def diffstatgen(ctx): '''Generator function that provides the diffstat data.''' stats = patch.diffstatdata(util.iterlines(ctx.diff())) maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats) while True: yield stats, maxname, maxtotal, addtotal, removetotal, binary
def diffstatgen(ctx, basectx): '''Generator function that provides the diffstat data.''' stats = patch.diffstatdata(util.iterlines(ctx.diff(basectx))) maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats) while True: yield stats, maxname, maxtotal, addtotal, removetotal, binary
def _file_changes(hg_ui, local_repo_path, commit): "Return FileChange instances for a commit" repo = hg.repository(hg_ui, path=local_repo_path) node2 = repo.lookup(commit.hash) node1 = repo[node2].parents()[0].node() lines = util.iterlines(patch.diff(repo, node1, node2)) for f in patch.diffstatdata(lines): yield FileChange(f[0], commit.file_changes[f[0]], f[1], f[2], f[3])
def getShortStat(obj, node1, node2): ## SLOW FIXME repo = obj.repo ## if not node1 ## FIXME stats = diffstatdata(iterlines(diff( repo, str(node1), str(node2), ))) maxname, maxtotal, insertions, deletions, hasbinary = diffstatsum(stats) return len(stats), insertions, deletions
def getShortStat(obj, node1, node2):## SLOW FIXME repo = obj.repo ## if not node1 ## FIXME stats = diffstatdata( iterlines( diff( repo, str(node1), str(node2), ) ) ) maxname, maxtotal, insertions, deletions, hasbinary = diffstatsum(stats) return len(stats), insertions, deletions
def diffstat(ui, repo, **kwargs): '''Example usage: [hooks] commit.diffstat = python:/path/to/this/file.py:diffstat changegroup.diffstat = python:/path/to/this/file.py:diffstat ''' if kwargs.get('parent2'): return node = kwargs['node'] first = repo[node].parents()[0].node() if 'url' in kwargs: last = repo['tip'].node() else: last = node diff = patch.diff(repo, first, last) ui.write(patch.diffstat(util.iterlines(diff)))
def diffstat(ui, repo, **kwargs): '''Example usage: [hooks] commit.diffstat = python:/path/to/this/file.py:diffstat changegroup.diffstat = python:/path/to/this/file.py:diffstat ''' if kwargs.get('parent2'): return node = kwargs['node'] first = repo[node].p1().node() if 'url' in kwargs: last = repo['tip'].node() else: last = node diff = patch.diff(repo, first, last) ui.write(patch.diffstat(util.iterlines(diff)))
def diffcmd(orig, ui, repo, *args, **opts): if not opts.get('per_file_stat_json'): return orig(ui, repo, *args, **opts) ui.pushbuffer() res = orig(ui, repo, *args, **opts) buffer = ui.popbuffer() difflines = util.iterlines([buffer]) diffstat = patch.diffstatdata(difflines) output = {} for filename, adds, removes, isbinary in diffstat: # use special encoding that allows non-utf8 filenames filename = encoding.jsonescape(filename, paranoid=True) output[filename] = { 'adds': adds, 'removes': removes, 'isbinary': isbinary, } ui.write('%s\n' % (json.dumps(output, sort_keys=True))) return res
def _incoming(ui, repo, **kwargs): # Ensure that no fancying of output is enabled (e.g. coloring) os.environ['TERM'] = 'dumb' ui.setconfig('ui', 'interactive', 'False') ui.setconfig('ui', 'formatted', 'False') try: colormod = sys.modules['hgext.color'] except KeyError: pass else: colormod._styles.clear() blacklisted = ui.config('mail', 'diff-blacklist', '').split() displayer = cmdutil.changeset_printer(ui, repo, False, False, True) ctx = repo[kwargs['node']] displayer.show(ctx) log = displayer.hunk[ctx.rev()] user = os.environ.get('HGPUSHER', 'local') path = '/'.join(repo.root.split('/')[4:]) body = [] #body += ['%s pushed %s to %s:' % (user, str(ctx), path), ''] body += [CSET_URL % (path, ctx)] body += [line for line in log.splitlines()[:-2] if line != 'tag: tip'] body += ['summary:\n ' + fromlocal(ctx.description())] # ctx.files() gives us misleading info on merges, we use a diffstat instead body += ['', 'files:'] diffopts = patch.diffopts(repo.ui, {'git': True, 'showfunc': True}) parents = ctx.parents() node1 = parents and parents[0].node() or nullid node2 = ctx.node() diffchunks = list(patch.diff(repo, node1, node2, opts=diffopts)) diffstat = patch.diffstat(iterlines(diffchunks), width=60, git=True) for line in iterlines([''.join(diffstat)]): body.append(' ' + line) body += ['', ''] diffchunks = strip_bin_diffs(diffchunks) diffchunks = strip_blacklisted_files(diffchunks, blacklisted) body.append(''.join(chunk for chunk in diffchunks)) body.append('-- ') body.append('Repository URL: %s%s' % (BASE, path)) to = ui.config('mail', 'notify', None) if to is None: print 'no email address configured' return False from_ = ui.config('mail', 'sender', None) if from_ is None: from_ = to sender = '%s <%s>' % (user, from_) prefixes = [path] if len(parents) == 2: b1, b2, b = parents[0].branch(), parents[1].branch(), ctx.branch() if b in (b1, b2): bp = b2 if b == b1 else b1 # normal case prefixes.append('(merge %s -> %s)' % (bp, b)) else: # XXX really?? prefixes.append('(merge %s + %s -> %s)' % (b1, b2, b)) else: branch = ctx.branch() if branch != 'default': prefixes.append('(%s)' % branch) desc = ctx.description().splitlines()[0] if len(desc) > 80: desc = desc[:80] if ' ' in desc: desc = desc.rsplit(' ', 1)[0] if prefixes: prefixes = ' '.join(prefixes) + ': ' else: prefixes = '' subj = prefixes + desc host = ui.config('smtp', 'host', '') port = int(ui.config('smtp', 'port', 0)) smtp = smtplib.SMTP(host, port) username = ui.config('smtp', 'username', '') if username: smtp.login(username, ui.config('smtp', 'password', '')) send(smtp, subj, sender, to, '\n'.join(body) + '\n') smtp.close() ui.status('notified %s of incoming changeset %s\n' % (to, ctx)) return False
def showdiffstat(repo, ctx, templ, **args): """String. Return diffstat-style summary of changes.""" width = repo.ui.termwidth() return patch.diffstat(util.iterlines(ctx.diff(noprefix=False)), width=width)