# HG changeset patch # User Martin Geisler # Date 2010-09-03 10:58:51 # Node ID d2c5b0927c2897dcd5384d1534dd6fbc4e0cc40a # Parent 441a74b8def144df7ab99370d139a47d846e5d4e diff: recurse into subrepositories with --subrepos/-S flag diff --git a/hgext/keyword.py b/hgext/keyword.py --- a/hgext/keyword.py +++ b/hgext/keyword.py @@ -511,14 +511,14 @@ def reposetup(ui, repo): self.lines = kwt.shrinklines(self.fname, self.lines) def kw_diff(orig, repo, node1=None, node2=None, match=None, changes=None, - opts=None): + opts=None, prefix=''): '''Monkeypatch patch.diff to avoid expansion except when comparing against working dir.''' if node2 is not None: kwt.match = util.never elif node1 is not None and node1 != repo['.'].node(): kwt.restrict = True - return orig(repo, node1, node2, match, changes, opts) + return orig(repo, node1, node2, match, changes, opts, prefix) def kwweb_skip(orig, web, req, tmpl): '''Wraps webcommands.x turning off keyword expansion.''' diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -5,7 +5,7 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -from node import hex, nullid, nullrev, short +from node import hex, bin, nullid, nullrev, short from i18n import _ import os, sys, errno, re, glob, tempfile import util, templater, patch, error, encoding, templatekw @@ -655,7 +655,8 @@ def export(repo, revs, template='hg-%h.p single(rev, seqno + 1, fp) def diffordiffstat(ui, repo, diffopts, node1, node2, match, - changes=None, stat=False, fp=None): + changes=None, stat=False, fp=None, prefix='', + listsubrepos=False): '''show diff or diffstat.''' if fp is None: write = ui.write @@ -668,16 +669,27 @@ def diffordiffstat(ui, repo, diffopts, n width = 80 if not ui.plain(): width = util.termwidth() - chunks = patch.diff(repo, node1, node2, match, changes, diffopts) + chunks = patch.diff(repo, node1, node2, match, changes, diffopts, + prefix=prefix) 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): + changes, diffopts, prefix=prefix): write(chunk, label=label) + if listsubrepos: + ctx1 = repo[node1] + for subpath in ctx1.substate: + sub = ctx1.sub(subpath) + if node2 is not None: + node2 = bin(repo[node2].substate[subpath][1]) + submatch = matchmod.narrowmatcher(subpath, match) + sub.diff(diffopts, node2, submatch, changes=changes, + stat=stat, fp=fp, prefix=prefix) + 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 @@ -1471,7 +1471,8 @@ def diff(ui, repo, *pats, **opts): diffopts = patch.diffopts(ui, opts) m = cmdutil.match(repo, pats, opts) - cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat) + cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, + listsubrepos=opts.get('subrepos')) def export(ui, repo, *changesets, **opts): """dump the header and diffs for one or more changesets @@ -4183,7 +4184,7 @@ table = { _('revision'), _('REV')), ('c', 'change', '', _('change made by revision'), _('REV')) - ] + diffopts + diffopts2 + walkopts, + ] + diffopts + diffopts2 + walkopts + subrepoopts, _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...')), "^export": (export, diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1404,7 +1404,7 @@ def diffopts(ui, opts=None, untrusted=Fa context=get('unified', getter=ui.config)) def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, - losedatafn=None): + losedatafn=None, prefix=''): '''yields diff of changes to files between two nodes, or node and working directory. @@ -1418,6 +1418,9 @@ def diff(repo, node1=None, node2=None, m called with the name of current file being diffed as 'fn'. If set to None, patches will always be upgraded to git format when necessary. + + prefix is a filename prefix that is prepended to all filenames on + display (used for subrepos). ''' if opts is None: @@ -1462,7 +1465,7 @@ def diff(repo, node1=None, node2=None, m copy = copies.copies(repo, ctx1, ctx2, repo[nullid])[0] difffn = lambda opts, losedata: trydiff(repo, revs, ctx1, ctx2, - modified, added, removed, copy, getfilectx, opts, losedata) + modified, added, removed, copy, getfilectx, opts, losedata, prefix) if opts.upgrade and not opts.git: try: def losedata(fn): @@ -1518,7 +1521,10 @@ def _addmodehdr(header, omode, nmode): header.append('new mode %s\n' % nmode) def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, - copy, getfilectx, opts, losedatafn): + copy, getfilectx, opts, losedatafn, prefix): + + def join(f): + return os.path.join(prefix, f) date1 = util.datestr(ctx1.date()) man1 = ctx1.manifest() @@ -1557,8 +1563,8 @@ def trydiff(repo, revs, ctx1, ctx2, modi gone.add(a) else: op = 'copy' - header.append('%s from %s\n' % (op, a)) - header.append('%s to %s\n' % (op, f)) + header.append('%s from %s\n' % (op, join(a))) + header.append('%s to %s\n' % (op, join(f))) to = getfilectx(a, ctx1).data() else: losedatafn(f) @@ -1600,7 +1606,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi elif binary or nflag != oflag: losedatafn(f) if opts.git: - header.insert(0, mdiff.diffline(revs, a, b, opts)) + header.insert(0, mdiff.diffline(revs, join(a), join(b), opts)) if dodiff: if dodiff == 'binary': @@ -1609,7 +1615,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi text = mdiff.unidiff(to, date1, # ctx2 date may be dynamic tn, util.datestr(ctx2.date()), - a, b, revs, opts=opts) + join(a), join(b), revs, opts=opts) if header and (text or len(header) > 1): yield ''.join(header) if text: diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -7,7 +7,7 @@ import errno, os, re, xml.dom.minidom, shutil, urlparse, posixpath from i18n import _ -import config, util, node, error +import config, util, node, error, cmdutil hg = None nullstate = ('', '', 'empty') @@ -249,6 +249,9 @@ class abstractsubrepo(object): def status(self, rev2, **opts): return [], [], [], [], [], [], [] + def diff(self, diffopts, node2, match, prefix, **opts): + pass + class hgsubrepo(abstractsubrepo): def __init__(self, ctx, path, state): self._path = path @@ -289,6 +292,17 @@ class hgsubrepo(abstractsubrepo): % (inst, relpath(self))) return [], [], [], [], [], [], [] + def diff(self, diffopts, node2, match, prefix, **opts): + try: + node1 = node.bin(self._state[1]) + cmdutil.diffordiffstat(self._repo.ui, self._repo, diffopts, + node1, node2, match, + prefix=os.path.join(prefix, self._path), + listsubrepos=True, **opts) + except error.RepoLookupError, inst: + self._repo.ui.warn(_("warning: %s in %s\n") + % (inst, relpath(self))) + def dirty(self): r = self._state[1] if r == '': diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t --- a/tests/test-debugcomplete.t +++ b/tests/test-debugcomplete.t @@ -180,7 +180,7 @@ Show all commands + options annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, include, exclude clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd commit: addremove, close-branch, include, exclude, message, logfile, date, user - diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude + diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos export: output, switch-parent, rev, text, git, nodates forget: include, exclude init: ssh, remotecmd diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -471,6 +471,7 @@ Test command without options --stat output diffstat-style summary of changes -I --include PATTERN [+] include names matching the given patterns -X --exclude PATTERN [+] exclude names matching the given patterns + -S --subrepos recurse into subrepositories [+] marked option can be specified multiple times diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t --- a/tests/test-subrepo-recursion.t +++ b/tests/test-subrepo-recursion.t @@ -2,6 +2,7 @@ Make status look into subrepositories by $ echo '[defaults]' >> $HGRCPATH $ echo 'status = -S' >> $HGRCPATH + $ echo 'diff = --nodates -S' >> $HGRCPATH Create test repository: @@ -54,6 +55,21 @@ Change working directory: $ hg status M foo/bar/z.txt M foo/y.txt + $ hg diff + diff -r d254738c5f5e foo/y.txt + --- a/foo/y.txt + +++ b/foo/y.txt + @@ -1,2 +1,3 @@ + y1 + y2 + +y3 + diff -r 9647f22de499 foo/bar/z.txt + --- a/foo/bar/z.txt + +++ b/foo/bar/z.txt + @@ -1,2 +1,3 @@ + z1 + z2 + +z3 Status call crossing repository boundaries: @@ -64,6 +80,21 @@ Status call crossing repository boundari $ hg status -I '**/?.txt' M foo/bar/z.txt M foo/y.txt + $ hg diff -I '**/?.txt' + diff -r d254738c5f5e foo/y.txt + --- a/foo/y.txt + +++ b/foo/y.txt + @@ -1,2 +1,3 @@ + y1 + y2 + +y3 + diff -r 9647f22de499 foo/bar/z.txt + --- a/foo/bar/z.txt + +++ b/foo/bar/z.txt + @@ -1,2 +1,3 @@ + z1 + z2 + +z3 Status from within a subdirectory: @@ -74,6 +105,21 @@ Status from within a subdirectory: M foo/bar/z.txt M foo/y.txt ? dir/a.txt + $ hg diff + diff -r d254738c5f5e foo/y.txt + --- a/foo/y.txt + +++ b/foo/y.txt + @@ -1,2 +1,3 @@ + y1 + y2 + +y3 + diff -r 9647f22de499 foo/bar/z.txt + --- a/foo/bar/z.txt + +++ b/foo/bar/z.txt + @@ -1,2 +1,3 @@ + z1 + z2 + +z3 Status with relative path: @@ -81,17 +127,66 @@ Status with relative path: M ../foo/bar/z.txt M ../foo/y.txt ? a.txt + $ hg diff .. + diff -r d254738c5f5e foo/y.txt + --- a/foo/y.txt + +++ b/foo/y.txt + @@ -1,2 +1,3 @@ + y1 + y2 + +y3 + diff -r 9647f22de499 foo/bar/z.txt + --- a/foo/bar/z.txt + +++ b/foo/bar/z.txt + @@ -1,2 +1,3 @@ + z1 + z2 + +z3 $ cd .. +Cleanup and final commit: + + $ rm -r dir + $ hg commit -m 2-3-2 + committing subrepository foo + committing subrepository foo/bar + +Log with the relationships between repo and its subrepo: + + $ hg log --template '{rev}:{node|short} {desc}\n' + 2:1326fa26d0c0 2-3-2 + 1:4b3c9ff4f66b 1-2-1 + 0:23376cbba0d8 0-0-0 + + $ hg -R foo log --template '{rev}:{node|short} {desc}\n' + 3:65903cebad86 2-3-2 + 2:d254738c5f5e 0-2-1 + 1:8629ce7dcc39 0-1-0 + 0:af048e97ade2 0-0-0 + + $ hg -R foo/bar log --template '{rev}:{node|short} {desc}\n' + 2:31ecbdafd357 2-3-2 + 1:9647f22de499 0-1-1 + 0:4904098473f9 0-0-0 + Status between revisions: - $ rm -r dir - $ hg commit -m 2-2-1 - committing subrepository foo - committing subrepository foo/bar $ hg status $ hg status --rev 0:1 M .hgsubstate M foo/.hgsubstate M foo/bar/z.txt M foo/y.txt + $ hg diff -I '**/?.txt' --rev 0:1 + diff -r af048e97ade2 -r d254738c5f5e foo/y.txt + --- a/foo/y.txt + +++ b/foo/y.txt + @@ -1,1 +1,2 @@ + y1 + +y2 + diff -r 4904098473f9 -r 9647f22de499 foo/bar/z.txt + --- a/foo/bar/z.txt + +++ b/foo/bar/z.txt + @@ -1,1 +1,2 @@ + z1 + +z2