diff --git a/hgext/extdiff.py b/hgext/extdiff.py --- a/hgext/extdiff.py +++ b/hgext/extdiff.py @@ -147,7 +147,12 @@ def dodiff(ui, repo, cmdline, pats, opts matcher = scmutil.match(repo[node2], pats, opts) - if True: + if opts.get('patch'): + if subrepos: + raise util.Abort(_('--patch cannot be used with --subrepos')) + if node2 is None: + raise util.Abort(_('--patch requires two revisions')) + else: mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher, listsubrepos=subrepos)[:3]) if do3way: @@ -163,7 +168,7 @@ def dodiff(ui, repo, cmdline, pats, opts tmproot = tempfile.mkdtemp(prefix='extdiff.') try: - if True: + if not opts.get('patch'): # Always make a copy of node1a (and node1b, if applicable) dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a) dir1a = snapshot(ui, repo, dir1a_files, node1a, tmproot, @@ -217,6 +222,18 @@ def dodiff(ui, repo, cmdline, pats, opts dir1b = os.devnull dir2 = os.path.join(dir2root, dir2, common_file) label2 = common_file + rev2 + else: + # XXX: export doesn't support -I/-X like extdiff does + template = 'hg-%h.patch' + cmdutil.export(repo, [repo[node1a].rev(), repo[node2].rev()], + template=repo.vfs.reljoin(tmproot, template)) + label1a = cmdutil.makefilename(repo, template, node1a) + label2 = cmdutil.makefilename(repo, template, node2) + dir1a = repo.vfs.reljoin(tmproot, label1a) + dir2 = repo.vfs.reljoin(tmproot, label2) + dir1b = None + label1b = None + fns_and_mtime = [] # Function to quote file/dir names in the argument string. # When not operating in 3-way mode, an empty string is @@ -260,6 +277,7 @@ def dodiff(ui, repo, cmdline, pats, opts _('pass option to comparison program'), _('OPT')), ('r', 'rev', [], _('revision'), _('REV')), ('c', 'change', '', _('change made by revision'), _('REV')), + ('', 'patch', None, _('compare patches for two revisions')) ] + commands.walkopts + commands.subrepoopts, _('hg extdiff [OPT]... [FILE]...'), inferrepo=True) diff --git a/tests/test-extdiff.t b/tests/test-extdiff.t --- a/tests/test-extdiff.t +++ b/tests/test-extdiff.t @@ -46,6 +46,7 @@ Should diff cloned directories: -o --option OPT [+] pass option to comparison program -r --rev REV [+] revision -c --change REV change made by revision + --patch compare patches for two revisions -I --include PATTERN [+] include names matching the given patterns -X --exclude PATTERN [+] exclude names matching the given patterns -S --subrepos recurse into subrepositories diff --git a/tests/test-extension.t b/tests/test-extension.t --- a/tests/test-extension.t +++ b/tests/test-extension.t @@ -390,6 +390,7 @@ Extension module help vs command help: -o --option OPT [+] pass option to comparison program -r --rev REV [+] revision -c --change REV change made by revision + --patch compare patches for two revisions -I --include PATTERN [+] include names matching the given patterns -X --exclude PATTERN [+] exclude names matching the given patterns -S --subrepos recurse into subrepositories diff --git a/tests/test-graft.t b/tests/test-graft.t --- a/tests/test-graft.t +++ b/tests/test-graft.t @@ -332,6 +332,38 @@ Disallow grafting an already grafted cse skipping already grafted revision 7:ef0ef43d49e7 (was grafted from 2:5c095ad7e90f) [255] + $ hg extdiff --config extensions.extdiff= --patch -r 2 -r 13 + --- */hg-5c095ad7e90f.patch * +0000 (glob) + +++ */hg-7a4785234d87.patch * +0000 (glob) + @@ -1,18 +1,18 @@ + # HG changeset patch + -# User test + +# User foo + # Date 0 0 + # Thu Jan 01 00:00:00 1970 +0000 + -# Node ID 5c095ad7e90f871700f02dd1fa5012cb4498a2d4 + -# Parent 5d205f8b35b66bc36375c9534ffd3237730e8f04 + +# Node ID 7a4785234d87ec1aa420ed6b11afe40fa73e12a9 + +# Parent b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f + 2 + + -diff -r 5d205f8b35b6 -r 5c095ad7e90f a + +diff -r b592ea63bb0c -r 7a4785234d87 a + --- a/a Thu Jan 01 00:00:00 1970 +0000 + +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 + @@ -1,1 +0,0 @@ + --b + -diff -r 5d205f8b35b6 -r 5c095ad7e90f b + +-a + +diff -r b592ea63bb0c -r 7a4785234d87 b + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/b Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + -+b + ++a + [1] + + Disallow grafting already grafted csets with the same origin onto each other $ hg up -q 13 $ hg graft 2