# HG changeset patch # User Yuya Nishihara # Date 2010-04-06 15:45:20 # Node ID 5d35f7d93514566fbc53d93dbcdae71495ba61df # Parent a84f14228b1d4cd06ece89e0cc4d51dfc0c91bcf commands: refactor diff --stat and qdiff --stat `opts['unified'] = '0'` can be replaced by `diffopts.context = 0`. diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -477,25 +477,9 @@ class queue(object): 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 diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -701,6 +701,30 @@ def export(repo, revs, template='hg-%h.p 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.''' diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1172,23 +1172,9 @@ def diff(ui, repo, *pats, **opts): 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