issue1420: hg diff -c <rev>
Stepan Koltsov
yozh at mx1.ru
Wed Dec 17 09:01:43 CST 2008
OK, next version of patch to add --change flag to diff subcommand is ready.
http://www.selenic.com/mercurial/bts/issue1420
Added test for -c when merge, minor issue about list of values with -c
flag fixed.
( http://www.selenic.com/mercurial/bts/file786/change.diff )
===
diff -r 6aafd75fb924 mercurial/commands.py
--- a/mercurial/commands.py Tue Dec 02 13:06:18 2008 -0600
+++ b/mercurial/commands.py Wed Dec 17 14:42:52 2008 +0000
@@ -1007,7 +1007,15 @@ def diff(ui, repo, *pats, **opts):
Use the --git option to generate diffs in the git extended diff
format. Read the diffs help topic for more information.
"""
- node1, node2 = cmdutil.revpair(repo, opts.get('rev'))
+ revopts = opts.get('rev')
+ changeopt = opts.get('change')
+ if revopts and changeopt:
+ raise util.Abort(_('cannot specify --rev and --change at the
same time'))
+ elif changeopt:
+ node2 = repo.lookup(changeopt)
+ node1 = repo[node2].parents()[0].node()
+ else:
+ node1, node2 = cmdutil.revpair(repo, revopts)
m = cmdutil.match(repo, pats, opts)
it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
@@ -3158,7 +3166,8 @@ table = {
"debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')),
"^diff":
(diff,
- [('r', 'rev', [], _('revision'))
+ [('r', 'rev', [], _('revision')),
+ ('c', 'change', '', _('change made by revision'))
] + diffopts + diffopts2 + walkopts,
_('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')),
"^export":
diff -r 6aafd75fb924 tests/test-diff-change
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-change Wed Dec 17 14:42:52 2008 +0000
@@ -0,0 +1,61 @@
+#!/bin/sh -e
+
+# test of hg diff --change
+
+set -e
+
+ec() {
+ echo "invoking $@:"
+ "$@"
+}
+
+hg init a
+cd a
+
+echo "first" > file.txt
+hg add file.txt
+hg commit -m 'first commit' # 0
+
+echo "second" > file.txt
+hg commit -m 'second commit' # 1
+
+echo "third" > file.txt
+hg commit -m 'third commit' # 2
+
+ec hg diff --nodates --change 1
+
+echo
+
+#rev=$(hg log -r 1 --template '{node|short}')
+rev=e9b286083166
+ec hg diff --nodates --change "$rev"
+
+##
+# Testing diff -c when merge
+
+for i in 1 2 3 4 5 6 7 8 9 10; do
+ echo $i >> file.txt
+done
+hg commit -m "lots of text" # 3
+
+sed -i -e 's,^2$,x,' file.txt
+hg commit -m "changed 2 to x" # 4
+
+hg up -r 3 > /dev/null 2>&1 # updated, merged, removed, unresolved
+sed -i -e 's,^8$,y,' file.txt
+hg commit -m "change 8 to y" > /dev/null 2>&1 # 5 # created new head
+
+hg up -C -r 4 > /dev/null 2>&1 # updated, merged, removed, unresolved
+hg merge -r 5 > /dev/null 2>&1 # updated, merged, removed, unresolved
+hg commit -m "merging 8 to y" # 6
+
+echo
+ec hg diff --nodates --change 6 # must be similar to hg diff
--nodates --change 5
+
+#echo
+#hg log
+
+echo
+echo "EOF"
+
+# vim: set ts=4 sw=4 et:
diff -r 6aafd75fb924 tests/test-diff-change.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-change.out Wed Dec 17 14:42:52 2008 +0000
@@ -0,0 +1,30 @@
+invoking hg diff --nodates --change 1:
+diff -r 4bb65dda5db4 -r e9b286083166 file.txt
+--- a/file.txt
++++ b/file.txt
+@@ -1,1 +1,1 @@
+-first
++second
+
+invoking hg diff --nodates --change e9b286083166:
+diff -r 4bb65dda5db4 -r e9b286083166 file.txt
+--- a/file.txt
++++ b/file.txt
+@@ -1,1 +1,1 @@
+-first
++second
+
+invoking hg diff --nodates --change 6:
+diff -r e8a0797e73a6 -r aa9873050139 file.txt
+--- a/file.txt
++++ b/file.txt
+@@ -6,6 +6,6 @@
+ 5
+ 6
+ 7
+-8
++y
+ 9
+ 10
+
+EOF
diff -r 6aafd75fb924 tests/test-help.out
--- a/tests/test-help.out Tue Dec 02 13:06:18 2008 -0600
+++ b/tests/test-help.out Wed Dec 17 14:42:52 2008 +0000
@@ -221,6 +221,7 @@ options:
options:
-r --rev revision
+ -c --change change made by revision
-a --text treat all files as text
-g --git use git extended diff format
--nodates don't include dates in diff headers
===
S.
On Sat, Dec 13, 2008 at 04:19, Stepan Koltsov <yozh at mx1.ru> wrote:
> On Sat, Dec 13, 2008 at 00:21, Matt Mackall <mpm at selenic.com> wrote:
>> On Fri, 2008-12-12 at 03:42 +0300, Stepan Koltsov wrote:
>>> some time ago I've created second version of patch for --change flag
>>> for diff subcommand ( http://www.selenic.com/mercurial/bts/issue1420
>>> ).
>>>
>>> Could someone, please, either apply patch, close issue as "won't fix",
>>> or tell me what's wrong with current patch?
>>>
>>> ===
>>> diff -r 6aafd75fb924 mercurial/commands.py
>>> --- a/mercurial/commands.py Tue Dec 02 13:06:18 2008 -0600
>>> +++ b/mercurial/commands.py Tue Dec 09 14:53:05 2008 +0000
>>> @@ -1007,7 +1007,17 @@
>>> Use the --git option to generate diffs in the git extended diff
>>> format. Read the diffs help topic for more information.
>>> """
>>> - node1, node2 = cmdutil.revpair(repo, opts.get('rev'))
>>> + revopts = opts.get('rev')
>>> + changeopts = opts.get('change')
>>> + if revopts and changeopts:
>>> + raise util.Abort(_('cannot specify --rev and --change at the
>>> same time'))
>>> + elif len(changeopts) > 1:
>>> + raise util.Abort(_('change can be specified no more then once'))
>>> + elif changeopts:
>>> + node2 = repo.lookup(changeopts[0])
>>> + node1 = repo[node2].parents()[0].node()
>>> + else:
>>> + node1, node2 = cmdutil.revpair(repo, revopts)
>>>
>>> m = cmdutil.match(repo, pats, opts)
>>> it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
>>> @@ -3158,7 +3168,8 @@
>>> "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')),
>>> "^diff":
>>> (diff,
>>> - [('r', 'rev', [], _('revision'))
>>> + [('r', 'rev', [], _('revision')),
>>> + ('c', 'change', [], _('change made by revision'))
>>
>> The '[]' indicates this option takes a list of values, which it doesn't.
>
> I'll fix.
>
>> What happens when the changeset in question is a merge?
>
> Behavior is the same as hg log -p -r <rev>. It is compared with the
> first parent. I'll add test case for this.
>
> S.
More information about the Mercurial-devel
mailing list