[PATCH] hg diff --branch <branch>
yozh at mx1.ru
yozh at mx1.ru
Wed Feb 11 18:55:29 CST 2009
# HG changeset patch
# User Stepan Koltsov <stepancheg at yandex-team.ru>
# Date 1234400049 -10800
# Node ID 72971b249e72ff50c5426d1811e0a73399ac4400
# Parent 998fc8f62539ee26601d526803d6da2476129411
hg diff --branch <branch>
generate diff from the parent of the branch tail to the branch head
diff -r 998fc8f62539 -r 72971b249e72 mercurial/commands.py
--- a/mercurial/commands.py Wed Jan 28 20:06:59 2009 -0600
+++ b/mercurial/commands.py Thu Feb 12 03:54:09 2009 +0300
@@ -1028,13 +1028,36 @@
revs = opts.get('rev')
change = opts.get('change')
+ branch = opts.get('branch')
- if revs and change:
- msg = _('cannot specify --rev and --change at the same time')
+ if bool(revs) + bool(change) + bool(branch) > 1:
+ msg = _('cannot specify --rev, --change or --branch at the same time')
raise util.Abort(msg)
elif change:
node2 = repo.lookup(change)
node1 = repo[node2].parents()[0].node()
+ elif branch:
+ heads = {}
+ tails = {} # parents of first changests within branches
+ for rev in xrange(0, len(repo)):
+ c = repo[rev]
+ if c.branch() == branch:
+ for p in c.parents():
+ if p.rev() in heads:
+ del heads[p.rev()]
+ heads[c.rev()] = c
+
+ for p in c.parents():
+ if p.branch() != branch:
+ tails[p.rev()] = p
+ def single(changesets, name):
+ if len(changets) == 0:
+ raise util.Abort(_(""))
+ if len(heads) != 1:
+ raise util.Abort(_("branch must have exactly one head"))
+ if len(tails) != 1:
+ raise util.Abort(_("branch must have exactly one parent of tail"))
+ node1, node2 = tails.itervalues().next().node(), heads.itervalues().next().node()
else:
node1, node2 = cmdutil.revpair(repo, revs)
@@ -3162,7 +3185,8 @@
"^diff":
(diff,
[('r', 'rev', [], _('revision')),
- ('c', 'change', '', _('change made by revision'))
+ ('c', 'change', '', _('change made by revision')),
+ ('', 'branch', '', _('diff from the tail to the head of the branch'))
] + diffopts + diffopts2 + walkopts,
_('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')),
"^export":
diff -r 998fc8f62539 -r 72971b249e72 tests/test-diff-branch
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-branch Thu Feb 12 03:54:09 2009 +0300
@@ -0,0 +1,49 @@
+#!/bin/sh -e
+
+ec() {
+ echo "$@"
+ "$@"
+}
+
+echo "### Simple case"
+echo
+
+ec hg init r
+ec cd r
+
+echo "the quick brown fox" > file.txt
+hg add file.txt
+hg commit -m "first commit" # 0
+
+echo "jumps over the lazy dog" >> file.txt
+hg commit -m "second commit" # 1
+
+hg up 0 # just before second commit
+hg branch "rabbit"
+echo "and the rabbit rabbit" >> file.txt
+hg commit -m "into the rabbit branch" # 2
+
+ec hg diff --branch rabbit
+
+echo
+echo "### Complicating: single parent of two tails, head is merge"
+echo
+
+hg branch "complex"
+echo "to be or not to be" > shakespeare.txt
+hg add shakespeare.txt
+hg commit -m 'shakespeare' # 3
+echo "that is the question" >> shakespeare.txt
+hg commit -m 'shakespeare^2' # 4
+
+hg up 2
+hg branch --force "complex"
+echo "in god we trust" > file.txt
+hg commit -m "another head" # 5
+
+hg merge 4
+hg commit -m "merge two heads of the same branch"
+
+ec hg diff --branch "complex"
+
+# vim: set ts=4 sw=4 et:
diff -r 998fc8f62539 -r 72971b249e72 tests/test-diff-branch.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-branch.out Thu Feb 12 03:54:09 2009 +0300
@@ -0,0 +1,37 @@
+### Simple case
+
+hg init r
+cd r
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+marked working directory as branch rabbit
+created new head
+hg diff --branch rabbit
+diff -r 019d07f21017 -r 4c6087bd3384 file.txt
+--- a/file.txt Thu Jan 01 00:00:00 1970 +0000
++++ b/file.txt Thu Jan 01 00:00:00 1970 +0000
+@@ -1,1 +1,2 @@
+ the quick brown fox
++and the rabbit rabbit
+
+### Complicating: single parent of two tails, head is merge
+
+marked working directory as branch complex
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+marked working directory as branch complex
+created new head
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+hg diff --branch complex
+diff -r 4c6087bd3384 -r 386f2ff150ae file.txt
+--- a/file.txt Thu Jan 01 00:00:00 1970 +0000
++++ b/file.txt Thu Jan 01 00:00:00 1970 +0000
+@@ -1,2 +1,1 @@
+-the quick brown fox
+-and the rabbit rabbit
++in god we trust
+diff -r 4c6087bd3384 -r 386f2ff150ae shakespeare.txt
+--- /dev/null Thu Jan 01 00:00:00 1970 +0000
++++ b/shakespeare.txt Thu Jan 01 00:00:00 1970 +0000
+@@ -0,0 +1,2 @@
++to be or not to be
++that is the question
diff -r 998fc8f62539 -r 72971b249e72 tests/test-help.out
--- a/tests/test-help.out Wed Jan 28 20:06:59 2009 -0600
+++ b/tests/test-help.out Thu Feb 12 03:54:09 2009 +0300
@@ -226,6 +226,7 @@
-r --rev revision
-c --change change made by revision
+ --branch diff from the tail to the head of the branch
-a --text treat all files as text
-g --git use git extended diff format
--nodates don't include dates in diff headers
More information about the Mercurial-devel
mailing list