Skip to content

Commit

Permalink
git: update committer information when creating new commits
Browse files Browse the repository at this point in the history
Summary:
This matches the Git behavior. Update committer and date by default.

`test-git.t` is changed since some commits have committer written by Git with
`test <test@example.org>` and this diff rewrites the committer to `test <>`.

Reviewed By: sggutier

Differential Revision: D42200687

fbshipit-source-id: 0d40ad0868e89cbe0cf932782bfe4f74d42c9e65
  • Loading branch information
quark-zju authored and facebook-github-bot committed Dec 22, 2022
1 parent 47d08bf commit 7f88efd
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 11 deletions.
14 changes: 14 additions & 0 deletions eden/scm/edenscm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,3 +937,17 @@ def submodule_node_from_ctx_path(ctx, path) -> Optional[bytes]:
return None
fctx = ctx[path]
return submodule_node_from_fctx(fctx)


def update_extra_with_git_committer(ui, ctx, extra):
"""process Git committer on local commit creation
Update the `extra` in place to contain the Git committer and committer date information.
"""
committer = ui.config("git", "committer") or ui.username()
extra["committer"] = committer

date = ui.config("git", "committer-date") or "now"
unixtime, offset = util.parsedate(date)
committer_date = f"{unixtime} {offset}"
extra["committer_date"] = committer_date
2 changes: 2 additions & 0 deletions eden/scm/edenscm/localrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2798,6 +2798,8 @@ def handleremove(f):
self.ui.note(_("committing changelog\n"))
self.changelog.delayupdate(tr)
extra = ctx.extra().copy()
if isgit:
git.update_extra_with_git_committer(self.ui, ctx, extra)
n = self.changelog.add(
mn,
files,
Expand Down
4 changes: 4 additions & 0 deletions eden/scm/tests/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export GIT_COMMITTER_NAME="test"
export GIT_COMMITTER_EMAIL="test@example.org"
export GIT_COMMITTER_DATE="2007-01-01 00:00:10 +0000"
unset GIT_DIR

# preserve test compatibility
setconfig git.committer='test'
setconfig git.committer-date='0 0'
1 change: 1 addition & 0 deletions eden/scm/tests/test-ext-github-pr-submit.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#inprocess-hg-incompatible

$ enable github
$ . $TESTDIR/git.sh

build up a github repo

Expand Down
136 changes: 136 additions & 0 deletions eden/scm/tests/test-git-committer.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#require git no-windows
#debugruntest-compatible
#chg-compatible

Test that committer and author can be set separately. Committer is updated when
rewriting commits.

$ configure modern
$ enable rebase absorb
$ . $TESTDIR/git.sh

$ dump_commits() {
> local revs="${1}"
> sl log -r "${revs:-all()}" -T '{desc}:\n author: {author}\n committer: {get(extras,"committer")}\n committer date: {get(extras,"committer_date")}\n'
> }

Simple case: a single commit.

$ newrepo '' --git
$ drawdag << 'EOS'
> A1
> EOS

Explicitly set author and committer:

$ sl metaedit -r 'desc(A1)' -m A2 -u 'user2' --config git.committer='user3' --config git.committer-date='10 10'
$ dump_commits
A2:
author: user2 <>
committer: user3 <>
committer date: 10 0

If committer and date are not explicitly set, the current author ('test', set
by the test runner via HGUSER) and the current wall time are used:

$ sl metaedit -r 'desc(A2)' -m A3 --config git.committer= --config git.committer-date=
$ dump_commits
A3:
author: user2 <>
committer: test <>
committer date: [1-9][0-9]+ 0 (re)

A more complex case - a stack of 3 commits.

$ newrepo '' --git
$ drawdag << EOS
> C
> :
> A
> EOS

$ dump_commits
A:
author: test <>
committer: test <>
committer date: 0 0
B:
author: test <>
committer: test <>
committer date: 0 0
C:
author: test <>
committer: test <>
committer date: 0 0

Edit B (middle of the stack), and trigger an auto rebase (a rewrite of C):

$ sl metaedit -r $B -u 'user <user@example.com>' --config git.committer='committer <committer@example.com>' --config git.committer-date='2022-12-12 12:12 +0800'

Result:
- Committer and committer date are used for newly created commits (new B and new C)
- Author is changed per request for B.
- Other commits (A) remain unchanged.

$ dump_commits
A:
author: test <>
committer: test <>
committer date: 0 0
B:
author: user <user@example.com>
committer: committer <committer@example.com>
committer date: 1670818320 -28800
C:
author: test <>
committer: committer <committer@example.com>
committer date: 1670818320 -28800

Rebase uses the current committer, not from the existing commits.

$ newrepo '' --git
$ drawdag << 'EOS'
> C
> :
> A
> EOS
$ dump_commits $C
C:
author: test <>
committer: test <>
committer date: 0 0
$ sl rebase -qr $C -d $A --config git.committer=user5
$ dump_commits "successors($C)"
C:
author: test <>
committer: user5 <>
committer date: 0 0

Absorb updates committer too. In this test we edit commit B and C, leaving A unchanged.

$ newrepo '' --git
$ drawdag << 'EOS'
> C
> :
> A
> EOS

$ sl go -q $C
$ echo 1 >> B

$ sl absorb -qa --config git.committer=user6

(B and C should have the new committer)
$ dump_commits
A:
author: test <>
committer: test <>
committer date: 0 0
B:
author: test <>
committer: user6 <>
committer date: 0 0
C:
author: test <>
committer: user6 <>
committer date: 0 0
23 changes: 12 additions & 11 deletions eden/scm/tests/test-git.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ Test bookmarks:

$ hg bookmark -r. foo
$ hg bookmarks
foo 4899b7b71a9c
foo 57eda5013e06
master 3f5848713286

Test changes are readable via git:

$ export GIT_DIR="$TESTTMP/gitrepo/.git"
$ git log foo --pretty='format:%s %an %d'
alpha3 test (refs/visibleheads/4899b7b71a9c241a7c43171f525cc9d6fcabfd4f, foo)
alpha3 test (refs/visibleheads/57eda5013e068ac543a52ad073cec3d7750113b5, foo)
beta test (HEAD -> master)
alpha test (no-eol)
$ git fsck --strict
$ git show foo
commit 4899b7b71a9c241a7c43171f525cc9d6fcabfd4f
commit 57eda5013e068ac543a52ad073cec3d7750113b5
Author: test <>
Date: Sat Feb 3 14:56:01 2001 +0800

Expand Down Expand Up @@ -190,7 +190,7 @@ Test pull:
$ hg pull origin -B foo
pulling from file:/*/$TESTTMP/gitrepo/.git (glob)
From file:/*/$TESTTMP/gitrepo/ (glob)
* [new ref] 4899b7b71a9c241a7c43171f525cc9d6fcabfd4f -> origin/foo
* [new ref] 57eda5013e068ac543a52ad073cec3d7750113b5 -> origin/foo
$ hg log -r origin/foo -T '{desc}\n'
alpha3

Expand Down Expand Up @@ -250,24 +250,25 @@ Test clone with flags (--noupdate, --updaterev):

$ hg clone --git "$TESTTMP/gitrepo" cloned1 --config remotenames.selectivepulldefault=foo,master
From $TESTTMP/gitrepo
* [new ref] 4899b7b71a9c241a7c43171f525cc9d6fcabfd4f -> remote/foo
* [new ref] 57eda5013e068ac543a52ad073cec3d7750113b5 -> remote/foo
* [new ref] 3f5848713286c67b8a71a450e98c7fa66787bde2 -> remote/master
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg --cwd cloned1 log -r . -T '{node|short} {remotenames} {desc}\n'
4899b7b71a9c remote/foo alpha3
57eda5013e06 remote/foo alpha3

$ hg clone --updaterev foo --git "$TESTTMP/gitrepo" cloned2
From $TESTTMP/gitrepo
* [new ref] 3f5848713286c67b8a71a450e98c7fa66787bde2 -> remote/master
* [new ref] 4899b7b71a9c241a7c43171f525cc9d6fcabfd4f -> remote/foo
* [new ref] 57eda5013e068ac543a52ad073cec3d7750113b5 -> remote/foo
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg --cwd cloned2 log -r . -T '{node|short} {remotenames} {desc}\n'
4899b7b71a9c remote/foo alpha3
57eda5013e06 remote/foo alpha3

$ hg clone --updaterev 4899b7b71a9c241a7c43171f525cc9d6fcabfd4f --git "$TESTTMP/gitrepo" cloned3
$ NODE=$(git --git-dir ~/gitrepo/.git for-each-ref | grep visibleheads | sed 's# .*##')
$ hg clone --updaterev $NODE --git "$TESTTMP/gitrepo" cloned3
From $TESTTMP/gitrepo
* [new ref] 3f5848713286c67b8a71a450e98c7fa66787bde2 -> remote/master
* [new ref] 4899b7b71a9c241a7c43171f525cc9d6fcabfd4f -> refs/visibleheads/4899b7b71a9c241a7c43171f525cc9d6fcabfd4f
* [new ref] 57eda5013e068ac543a52ad073cec3d7750113b5 -> refs/visibleheads/57eda5013e068ac543a52ad073cec3d7750113b5
2 files updated, 0 files merged, 0 files removed, 0 files unresolved

Test clone using scp-like path:
Expand Down Expand Up @@ -334,7 +335,7 @@ Test push:
- --to with -r
$ hg push -r '.^' --to parent_change_beta
To $TESTTMP/gitrepo
* [new branch] 4899b7b71a9c241a7c43171f525cc9d6fcabfd4f -> parent_change_beta
* [new branch] 57eda5013e068ac543a52ad073cec3d7750113b5 -> parent_change_beta

$ hg log -r '.^+.' -T '{desc} {remotenames}\n'
alpha3 remote/foo remote/parent_change_beta
Expand Down

0 comments on commit 7f88efd

Please sign in to comment.