RFC: committer field in extras for applied patches
Eric Eisner
ede at mit.edu
Fri Apr 1 13:19:01 CDT 2011
On Thu, Mar 31, 2011 at 20:33, <greg at gerg.ca> wrote:
> On 29 March 2011, Eric Eisner said:
> > The motivation for this feature is from hg's repo: being able to see who
> > reviewed and committed a patch that was not committed by crew/mpm. Other
> > projects that accept a lot of patches via patchbomb would also benefit.
> I'm
> > mostly focusing on the semantics of when to add the metadata, and
> ignoring
> > for now how one would view it.
>
> +1, if only for feature parity with git and bzr. ;-)
>
> No, seriously, I think this would be nice to have even if git and bzr
> did not already have it.
>
> > Idea 2: Every commit to the repo
> > This would be implemented at a lower level, maybe in repo.commit. Any
> time a
> > supplied user is different from ui.username(), add committer=username to
> > extras.
> > In addition to patch creation, the --user flag of commit/qrefresh will
> > create committer=ui.username(). This mostly seems pointless to me though.
> > This is pretty much the semantics of git for comparison.
>
> I like this choice. Once or twice at work I have had good reason to
> use "hg commit -u" to forge a changeset on someone else's behalf. It
> would be nice to have a formal record that I committed something but
> was not the author, and IMHO commit -u is morally equivalent to import
> or qimport.
>
> Greg
>
I implemented a very tiny patch to add the committer extra to everything,
including commit -u. It turns out that a lot of tests commit with a
non-default user for no particular reason, then depend on displaying a
particular cset hash. The number of external tests that may depend on commit
-u giving a particular hash may be a lot of inertia...
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -288,7 +288,7 @@ class ui(object):
'''
return 'HGPLAIN' in os.environ
- def username(self):
+ def username(self, reportnone=False):
"""Return default username to be used in commits.
Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
@@ -303,6 +303,8 @@ class ui(object):
user = os.path.expandvars(user)
if user is None:
user = os.environ.get("EMAIL")
+ if reportnone:
+ return user
if user is None and self.configbool("ui", "askusername"):
user = self.prompt(_("enter a commit username:"), default=None)
if user is None and not self.interactive():
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -983,6 +983,11 @@ class localrepository(repo.repository):
raise util.Abort(_("unresolved merge conflicts "
"(see hg help resolve)"))
+ # record the committer if the supplied user is different
+ committer = self.ui.username(reportnone=True)
+ if committer and user and user != committer:
+ extra['committer'] = committer
+
cctx = context.workingctx(self, text, user, date, extra,
changes)
if editor:
cctx._text = editor(self, cctx, subs)
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -7,7 +7,7 @@ init
commit
$ echo 'a' > a
- $ hg ci -A -m test -u nobody -d '1 0'
+ $ HGUSER=nobody hg ci -A -m test -d '1 0'
adding a
annotate -c
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -4,30 +4,30 @@
$ hg add a
$ echo line 1 > b
$ echo line 2 >> b
- $ hg commit -l b -d '1000000 0' -u 'User Name <user at hostname>'
+ $ HGUSER='User Name <user at hostname>' hg commit -l b -d '1000000 0'
$ hg add b
$ echo other 1 > c
$ echo other 2 >> c
$ echo >> c
$ echo other 3 >> c
- $ hg commit -l c -d '1100000 0' -u 'A. N. Other <other at place>'
+ $ HGUSER='A. N. Other <other at place>' hg commit -l c -d '1100000 0'
$ hg add c
- $ hg commit -m 'no person' -d '1200000 0' -u 'other at place'
+ $ HGUSER='other at place' hg commit -m 'no person' -d '1200000 0'
$ echo c >> c
- $ hg commit -m 'no user, no domain' -d '1300000 0' -u 'person'
+ $ HGUSER='person' hg commit -m 'no user, no domain' -d '1300000 0'
$ echo foo > .hg/branch
- $ hg commit -m 'new branch' -d '1400000 0' -u 'person'
+ $ HGUSER='person' hg commit -m 'new branch' -d '1400000 0'
$ hg co -q 3
$ echo other 4 >> d
$ hg add d
- $ hg commit -m 'new head' -d '1500000 0' -u 'person'
+ $ HGUSER='person' hg commit -m 'new head' -d '1500000 0'
$ hg merge -q foo
- $ hg commit -m 'merge' -d '1500001 0' -u 'person'
+ $ HGUSER='person' hg commit -m 'merge' -d '1500001 0'
Second branch starting at nullrev:
@@ -35,7 +35,7 @@ Second branch starting at nullrev:
0 files updated, 0 files merged, 4 files removed, 0 files unresolved
$ echo second > second
$ hg add second
- $ hg commit -m second -d '1000000 0' -u 'User Name <user at hostname>'
+ $ HGUSER='User Name <user at hostname>' hg commit -m second -d '1000000 0'
created new head
$ echo third > third
diff --git a/tests/test-committer.t b/tests/test-committer.t
--- a/tests/test-committer.t
+++ b/tests/test-committer.t
@@ -39,12 +39,15 @@
$ echo 1 > asdf
$ hg commit -u "foo at bar.com" -m commit-1
$ hg tip
- changeset: 3:957606a725e4
+ changeset: 3:98710bc49a86
tag: tip
user: foo at bar.com
date: Thu Jan 01 00:00:00 1970 +0000
summary: commit-1
+ $ hg tip --debug | grep committer
+ extra: committer=foobar <foo at bar.com>
+
$ echo 123 > asdf
$ echo "[ui]" > .hg/hgrc
$ echo "username = " >> .hg/hgrc
diff --git a/tests/test-diff-ignore-whitespace.t
b/tests/test-diff-ignore-whitespace.t
--- a/tests/test-diff-ignore-whitespace.t
+++ b/tests/test-diff-ignore-whitespace.t
@@ -7,7 +7,7 @@ Prepare tests:
$ hg init
$ printf 'hello world\ngoodbye world\n' >foo
- $ hg ci -Amfoo -ufoo
+ $ HGUSER=foo hg ci -Amfoo
adding foo
diff --git a/tests/test-encoding-align.t b/tests/test-encoding-align.t
--- a/tests/test-encoding-align.t
+++ b/tests/test-encoding-align.t
@@ -77,21 +77,21 @@ commit(1)
$ echo 'first line(1)' >> s; cp s $S
$ echo 'first line(2)' >> m; cp m $M
$ echo 'first line(3)' >> l; cp l $L
- $ hg commit -m 'first commit' -u $S
+ $ HGUSER=$S hg commit -m 'first commit'
commit(2)
$ echo 'second line(1)' >> s; cp s $S
$ echo 'second line(2)' >> m; cp m $M
$ echo 'second line(3)' >> l; cp l $L
- $ hg commit -m 'second commit' -u $M
+ $ HGUSER=$M hg commit -m 'second commit'
commit(3)
$ echo 'third line(1)' >> s; cp s $S
$ echo 'third line(2)' >> m; cp m $M
$ echo 'third line(3)' >> l; cp l $L
- $ hg commit -m 'third commit' -u $L
+ $ HGUSER=$L hg commit -m 'third commit'
check alignment of user names in annotate
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -103,7 +103,7 @@ import of plain diff with specific date
$ hg --cwd b import -mpatch -d '1 0' -u 'user at nowhere.net' ../tip.patch
applying ../tip.patch
$ hg -R b tip -pv
- changeset: 1:ca68f19f3a40
+ changeset: 1:40339aa5d63d
tag: tip
user: user at nowhere.net
date: Thu Jan 01 00:00:01 1970 +0000
@@ -112,13 +112,15 @@ import of plain diff with specific date
patch
- diff -r 80971e65b431 -r ca68f19f3a40 a
+ diff -r 80971e65b431 -r 40339aa5d63d a
--- a/a Thu Jan 01 00:00:00 1970 +0000
+++ b/a Thu Jan 01 00:00:01 1970 +0000
@@ -1,1 +1,2 @@
line 1
+line 2
+ $ hg -R b tip --debug | grep committer
+ extra: committer=test
$ rm -r b
@@ -203,9 +205,9 @@ import two patches in one stream
applying patch from stdin
applied 80971e65b431
$ hg --cwd a id
- 1d4bd90af0e4 tip
+ fc69af122cf8 tip
$ hg --cwd b id
- 1d4bd90af0e4 tip
+ fc69af122cf8 tip
$ rm -r b
@@ -362,7 +364,7 @@ patches: import patch1 patch2; rollback
$ hg --cwd b import ../patch1 ../patch2
applying ../patch1
applying ../patch2
- applied 1d4bd90af0e4
+ applied fc69af122cf8
$ hg --cwd b rollback
repository tip rolled back to revision 1 (undo commit)
working directory now based on revision 1
@@ -822,7 +824,7 @@ Issue1859: first line mistaken for email
# HG changeset patch
# User User B
# Date 0 0
- # Node ID eb56ab91903632294ac504838508cb370c0901d2
+ # Node ID 34f9b743fc297b687eeaba1985f902bc54651220
# Parent 0000000000000000000000000000000000000000
from: tricky!
@@ -878,7 +880,7 @@ Issue2102: hg export and hg import speak
> EOF
applying patch from stdin
$ hg sum
- parent: 1:d59915696727 tip
+ parent: 1:5357eee2cf2c tip
help management of empty pkg and lib directories in perforce
branch: default
commit: (clean)
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -131,7 +131,7 @@ Interrupted commit should not change sta
Commit with several checks
- $ hg --debug commit -mabsym -u 'User Name <user at example.com>'
+ $ HGUSER='User Name <user at example.com>' hg --debug commit -mabsym
a
b
overwriting a expanding keywords
@@ -277,7 +277,7 @@ Check whether expansion is filewise
commit file c
- $ hg commit -A -mcndiff -d '1 0' -u 'User Name <user at example.com>'
+ $ HGUSER='User Name <user at example.com>' hg commit -A -mcndiff -d '1 0'
adding c
force expansion
@@ -498,11 +498,13 @@ qgoto, implying qpush, should expand
$ hg qgoto mqtest.diff
applying mqtest.diff
now at: mqtest.diff
+ $ hg id --id
+ 25d7d4774bb3
$ cat c
- $Id: c,v 40a904bbbe4c 1970/01/01 00:00:01 user $
+ $Id: c,v 25d7d4774bb3 1970/01/01 00:00:01 user $
tests for different changenodes
$ hg cat c
- $Id: c,v 40a904bbbe4c 1970/01/01 00:00:01 user $
+ $Id: c,v 25d7d4774bb3 1970/01/01 00:00:01 user $
tests for different changenodes
Keywords should not be expanded in filelog
@@ -526,7 +528,7 @@ Copy and show added kwfiles
Commit and show expansion in original and copy
- $ hg --debug commit -ma2c -d '1 0' -u 'User Name <user at example.com>'
+ $ HGUSER='User Name <user at example.com>' hg --debug commit -ma2c -d '1 0'
c
c: copy a:0045e12f6c5791aac80ca6cbfd97709a88307292
overwriting c expanding keywords
@@ -691,7 +693,7 @@ Interrupted commit should not change sta
Commit with multiline message and custom expansion
- $ hg --debug commit -l log -d '2 0' -u 'User Name <user at example.com>'
+ $ HGUSER='User Name <user at example.com>' hg --debug commit -l log -d '2 0'
a
overwriting a expanding keywords
committed changeset 2:bb948857c743469b22bbf51f7ec8112279ca5d83
@@ -802,7 +804,7 @@ Imported patch should not be rejected
$ python -c \
> 'import re; s=re.sub("(Id.*)","\\1 rejecttest",open("a").read());
open("a","wb").write(s);'
- $ hg --debug commit -m'rejects?' -d '3 0' -u 'User Name <user at example.com
>'
+ $ HGUSER='User Name <user at example.com>' hg --debug commit -m'rejects?' -d
'3 0'
a
overwriting a expanding keywords
committed changeset 2:85e279d709ffc28c9fdd1b868570985fc3d87082
@@ -810,8 +812,10 @@ Imported patch should not be rejected
$ cd ../Test
$ hg import ../rejecttest.diff
applying ../rejecttest.diff
+ $ hg id --id
+ a753c4fede8f
$ cat a b
- expand $Id: a 4e0994474d25 Thu, 01 Jan 1970 00:00:03 +0000 user $
rejecttest
+ expand $Id: a a753c4fede8f Thu, 01 Jan 1970 00:00:03 +0000 user $
rejecttest
do not process $Id: rejecttest
xxx $
$Xinfo: User Name <user at example.com>: rejects? $
@@ -840,7 +844,7 @@ kwexpand x/a should abort
abort: outstanding uncommitted changes
[255]
$ cd x
- $ hg --debug commit -m xa -d '3 0' -u 'User Name <user at example.com>'
+ $ HGUSER='User Name <user at example.com>' hg --debug commit -m xa -d '3 0'
x/a
x/a: copy a:779c764182ce5d43e2b1eb66ce06d7b47bfe342e
overwriting x/a expanding keywords
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -574,10 +574,10 @@ log -r tip --stat
$ cd usertest
$ echo a > a
- $ hg ci -A -m "a" -u "User One <user1 at example.org>"
+ $ HGUSER="User One <user1 at example.org>" hg ci -A -m "a"
adding a
$ echo b > b
- $ hg ci -A -m "b" -u "User Two <user2 at example.org>"
+ $ HGUSER="User Two <user2 at example.org>" hg ci -A -m "b"
adding b
$ hg log -u "User One <user1 at example.org>"
diff --git a/tests/test-mq-qimport.t b/tests/test-mq-qimport.t
--- a/tests/test-mq-qimport.t
+++ b/tests/test-mq-qimport.t
@@ -62,7 +62,7 @@ import email
hg tip -v
$ hg tip -v
- changeset: 0:1a706973a7d8
+ changeset: 0:57b781107df5
tag: email
tag: qbase
@@ -76,6 +76,8 @@ hg tip -v
More text in commit message.
+ $ hg tip --debug | grep committer
+ extra: committer=test
$ hg qpop
popping email
patch queue now empty
diff --git a/tests/test-mq-qrefresh.t b/tests/test-mq-qrefresh.t
--- a/tests/test-mq-qrefresh.t
+++ b/tests/test-mq-qrefresh.t
@@ -336,6 +336,14 @@ Add 1/base with include filter - and thu
-base
+patched
+qrefresh as different user
+
+ $ HGUSER='Recent Refresher' hg qrefresh
+ $ hg tip | grep user
+ user: test
+ $ hg tip --debug | grep committer
+ extra: committer=Recent Refresher
+
$ cd ..
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -25,7 +25,7 @@
$ rm a
$ hg branch a-b-c-
marked working directory as branch a-b-c-
- $ hg ci -Aqm2 -u Bob
+ $ HGUSER=Bob hg ci -Aqm2
$ hg co 1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
diff --git a/tests/test-unrelated-pull.t b/tests/test-unrelated-pull.t
--- a/tests/test-unrelated-pull.t
+++ b/tests/test-unrelated-pull.t
@@ -3,7 +3,7 @@
$ hg init
$ echo 123 > a
$ hg add a
- $ hg commit -m "a" -u a
+ $ HGUSER=a hg commit -m "a"
$ cd ..
$ mkdir b
@@ -11,7 +11,7 @@
$ hg init
$ echo 321 > b
$ hg add b
- $ hg commit -m "b" -u b
+ $ HGUSER=b hg commit -m "b"
$ hg pull ../a
pulling from ../a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110401/29dedf7f/attachment.htm>
More information about the Mercurial-devel
mailing list