Mercurial > hg
changeset 11050:5d35f7d93514
commands: refactor diff --stat and qdiff --stat
`opts['unified'] = '0'` can be replaced by `diffopts.context = 0`.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 07 Apr 2010 00:45:20 +0900 |
parents | a84f14228b1d |
children | bf7e63fedca1 |
files | hgext/mq.py mercurial/cmdutil.py mercurial/commands.py |
diffstat | 3 files changed, 27 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/mq.py Wed Apr 07 00:10:54 2010 +0900 +++ b/hgext/mq.py Wed Apr 07 00:45:20 2010 +0900 @@ -477,25 +477,9 @@ def printdiff(self, repo, diffopts, node1, node2=None, files=None, fp=None, changes=None, opts={}): stat = opts.get('stat') - m = cmdutil.match(repo, files, opts) - if fp is None: - write = repo.ui.write - else: - def write(s, **kw): - fp.write(s) - if stat: - diffopts.context = 0 - width = self.ui.interactive() and util.termwidth() or 80 - chunks = patch.diff(repo, node1, node2, m, changes, diffopts) - for chunk, label in patch.diffstatui(util.iterlines(chunks), - width=width, - git=diffopts.git): - write(chunk, label=label) - else: - for chunk, label in patch.diffui(repo, node1, node2, m, changes, - diffopts): - write(chunk, label=label) + cmdutil.diffordiffstat(self.ui, repo, diffopts, node1, node2, m, + changes, stat, fp) def mergeone(self, repo, mergeq, head, patch, rev, diffopts): # first try just applying the patch
--- a/mercurial/cmdutil.py Wed Apr 07 00:10:54 2010 +0900 +++ b/mercurial/cmdutil.py Wed Apr 07 00:45:20 2010 +0900 @@ -701,6 +701,30 @@ for seqno, rev in enumerate(revs): single(rev, seqno + 1, fp) +def diffordiffstat(ui, repo, diffopts, node1, node2, match, + changes=None, stat=False, fp=None): + '''show diff or diffstat.''' + if fp is None: + write = ui.write + else: + def write(s, **kw): + fp.write(s) + + if stat: + diffopts.context = 0 + width = 80 + if not ui.plain(): + width = util.termwidth() + chunks = patch.diff(repo, node1, node2, match, changes, diffopts) + for chunk, label in patch.diffstatui(util.iterlines(chunks), + width=width, + git=diffopts.git): + write(chunk, label=label) + else: + for chunk, label in patch.diffui(repo, node1, node2, match, + changes, diffopts): + write(chunk, label=label) + class changeset_printer(object): '''show changeset information when templating not requested.'''
--- a/mercurial/commands.py Wed Apr 07 00:10:54 2010 +0900 +++ b/mercurial/commands.py Wed Apr 07 00:45:20 2010 +0900 @@ -1172,23 +1172,9 @@ if reverse: node1, node2 = node2, node1 - if stat: - opts['unified'] = '0' diffopts = patch.diffopts(ui, opts) - m = cmdutil.match(repo, pats, opts) - if stat: - it = patch.diff(repo, node1, node2, match=m, opts=diffopts) - width = 80 - if not ui.plain(): - width = util.termwidth() - for chunk, label in patch.diffstatui(util.iterlines(it), width=width, - git=diffopts.git): - ui.write(chunk, label=label) - else: - it = patch.diffui(repo, node1, node2, match=m, opts=diffopts) - for chunk, label in it: - ui.write(chunk, label=label) + cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat) def export(ui, repo, *changesets, **opts): """dump the header and diffs for one or more changesets