[PATCH 1 of 2] amend: add noise in extra to avoid creating obsolescence cycle (issue3664)

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Thu Oct 18 16:03:05 UTC 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1350575482 -7200
# Node ID 122ab0793ce25a8ada0895fca25d05dbde7326a3
# Parent  a1c4b21fc1b206f5cf386a8d9d5b5882aaa6807f
amend: add noise in extra to avoid creating obsolescence cycle (issue3664)

Obsolescence cycle are bad and should be avoided as much as possible. The
current amend implemented touch changeset meta data as few as possible. This
make is easy for amend to result in the same node than a precursors. We add some
deterministic noise in extra to avoid this. In practice, the hex of the amended
changeset is stored in 'amend-from' extra key.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1694,10 +1694,12 @@ def amend(ui, repo, commitfunc, old, ext
                 user = opts.get('user') or old.user()
                 date = opts.get('date') or old.date()
             if not message:
                 message = old.description()
 
+            extra['amend-from'] = old.hex()
+
             new = context.memctx(repo,
                                  parents=[base.node(), nullid],
                                  text=message,
                                  files=files,
                                  filectxfn=filectxfn,
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -18,36 +18,35 @@ Refuse to amend public csets:
   $ hg ci -Am 'base1'
 
 Nothing to amend:
 
   $ hg ci --amend
-  nothing changed
-  [1]
+  saved backup bundle to $TESTTMP/.hg/strip-backup/489edb5b847d-amend-backup.hg (glob)
 
   $ cat >> $HGRCPATH <<EOF
   > [hooks]
   > pretxncommit.foo = sh -c "echo \\"pretxncommit \$HG_NODE\\"; hg id -r \$HG_NODE"
   > EOF
 
 Amending changeset with changes in working dir:
 
   $ echo a >> a
   $ hg ci --amend -m 'amend base1'
-  pretxncommit 9cd25b479c51be2f4ed2c38e7abdf7ce67d8e0dc
-  9cd25b479c51 tip
-  saved backup bundle to $TESTTMP/.hg/strip-backup/489edb5b847d-amend-backup.hg (glob)
+  pretxncommit 375b7c6cee16eaccd8f3fc9de3959e21f54f28f3
+  375b7c6cee16 tip
+  saved backup bundle to $TESTTMP/.hg/strip-backup/70293cd2b10e-amend-backup.hg (glob)
   $ echo 'pretxncommit.foo = ' >> $HGRCPATH
   $ hg diff -c .
-  diff -r ad120869acf0 -r 9cd25b479c51 a
+  diff -r ad120869acf0 -r 375b7c6cee16 a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,1 +1,3 @@
    a
   +a
   +a
   $ hg log
-  changeset:   1:9cd25b479c51
+  changeset:   1:375b7c6cee16
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     amend base1
   
@@ -60,48 +59,48 @@ Amending changeset with changes in worki
 Add new file:
 
   $ echo b > b
   $ hg ci --amend -Am 'amend base1 new file'
   adding b
-  saved backup bundle to $TESTTMP/.hg/strip-backup/9cd25b479c51-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/375b7c6cee16-amend-backup.hg (glob)
 
 Remove file that was added in amended commit:
 
   $ hg rm b
   $ hg ci --amend -m 'amend base1 remove new file'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/e2bb3ecffd2f-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/ec38cdce6113-amend-backup.hg (glob)
 
   $ hg cat b
-  b: no such file in rev 664a9b2d60cd
+  b: no such file in rev 134e9d2ba669
   [1]
 
 No changes, just a different message:
 
   $ hg ci -v --amend -m 'no changes, new message'
-  amending changeset 664a9b2d60cd
-  copying changeset 664a9b2d60cd to ad120869acf0
+  amending changeset 134e9d2ba669
+  copying changeset 134e9d2ba669 to ad120869acf0
   a
-  stripping amended changeset 664a9b2d60cd
+  stripping amended changeset 134e9d2ba669
   1 changesets found
-  saved backup bundle to $TESTTMP/.hg/strip-backup/664a9b2d60cd-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/134e9d2ba669-amend-backup.hg (glob)
   1 changesets found
   adding branch
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  committed changeset 1:ea6e356ff2ad
+  committed changeset 1:c4e7ebf4e23d
   $ hg diff -c .
-  diff -r ad120869acf0 -r ea6e356ff2ad a
+  diff -r ad120869acf0 -r c4e7ebf4e23d a
   --- a/a	Thu Jan 01 00:00:00 1970 +0000
   +++ b/a	Thu Jan 01 00:00:00 1970 +0000
   @@ -1,1 +1,3 @@
    a
   +a
   +a
   $ hg log
-  changeset:   1:ea6e356ff2ad
+  changeset:   1:c4e7ebf4e23d
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     no changes, new message
   
@@ -117,16 +116,16 @@ Disable default date on commit so when -
   $ echo 'commit=' >> $HGRCPATH
 
 Test -u/-d:
 
   $ hg ci --amend -u foo -d '1 0'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/ea6e356ff2ad-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/c4e7ebf4e23d-amend-backup.hg (glob)
   $ echo a >> a
   $ hg ci --amend -u foo -d '1 0'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/377b91ce8b56-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/f713f6a6ab17-amend-backup.hg (glob)
   $ hg log -r .
-  changeset:   1:2c94e4a5756f
+  changeset:   1:5e9454fb7bef
   tag:         tip
   user:        foo
   date:        Thu Jan 01 00:00:01 1970 +0000
   summary:     no changes, new message
   
@@ -137,65 +136,65 @@ Open editor with old commit message if a
   > #!/bin/sh
   > cat $1
   > echo "another precious commit message" > "$1"
   > __EOF__
   $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
-  amending changeset 2c94e4a5756f
-  copying changeset 2c94e4a5756f to ad120869acf0
+  amending changeset 5e9454fb7bef
+  copying changeset 5e9454fb7bef to ad120869acf0
   no changes, new message
   
   
   HG: Enter commit message.  Lines beginning with 'HG:' are removed.
   HG: Leave message empty to abort commit.
   HG: --
   HG: user: foo
   HG: branch 'default'
   HG: changed a
   a
-  stripping amended changeset 2c94e4a5756f
+  stripping amended changeset 5e9454fb7bef
   1 changesets found
-  saved backup bundle to $TESTTMP/.hg/strip-backup/2c94e4a5756f-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/5e9454fb7bef-amend-backup.hg (glob)
   1 changesets found
   adding branch
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  committed changeset 1:ffb49186f961
+  committed changeset 1:18afb243865c
 
 Same, but with changes in working dir (different code path):
 
   $ echo a >> a
   $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
-  amending changeset ffb49186f961
+  amending changeset 18afb243865c
   a
-  copying changeset a4f8a65b7c6a to ad120869acf0
+  copying changeset a3ab8cb5aca7 to ad120869acf0
   another precious commit message
   
   
   HG: Enter commit message.  Lines beginning with 'HG:' are removed.
   HG: Leave message empty to abort commit.
   HG: --
   HG: user: foo
   HG: branch 'default'
   HG: changed a
   a
-  stripping intermediate changeset a4f8a65b7c6a
-  stripping amended changeset ffb49186f961
+  stripping intermediate changeset a3ab8cb5aca7
+  stripping amended changeset 18afb243865c
   2 changesets found
-  saved backup bundle to $TESTTMP/.hg/strip-backup/ffb49186f961-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/18afb243865c-amend-backup.hg (glob)
   1 changesets found
   adding branch
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  committed changeset 1:fb6cca43446f
+  committed changeset 1:32576d4c5ba0
 
   $ rm editor.sh
   $ hg log -r .
-  changeset:   1:fb6cca43446f
+  changeset:   1:32576d4c5ba0
   tag:         tip
   user:        foo
   date:        Thu Jan 01 00:00:01 1970 +0000
   summary:     another precious commit message
   
@@ -203,20 +202,20 @@ Same, but with changes in working dir (d
 Moving bookmarks, preserve active bookmark:
 
   $ hg book book1
   $ hg book book2
   $ hg ci --amend -m 'move bookmarks'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/fb6cca43446f-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/32576d4c5ba0-amend-backup.hg (glob)
   $ hg book
-     book1                     1:0cf1c7a51bcf
-   * book2                     1:0cf1c7a51bcf
+     book1                     1:4f7954c0988d
+   * book2                     1:4f7954c0988d
   $ echo a >> a
   $ hg ci --amend -m 'move bookmarks'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/0cf1c7a51bcf-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/4f7954c0988d-amend-backup.hg (glob)
   $ hg book
-     book1                     1:7344472bd951
-   * book2                     1:7344472bd951
+     book1                     1:8b74f9324cbf
+   * book2                     1:8b74f9324cbf
 
   $ echo '[defaults]' >> $HGRCPATH
   $ echo "commit=-d '0 0'" >> $HGRCPATH
 
 Moving branches:
@@ -228,13 +227,13 @@ Moving branches:
   $ hg ci -m 'branch foo'
   $ hg branch default -f
   marked working directory as branch default
   (branches are permanent and global, did you want a bookmark?)
   $ hg ci --amend -m 'back to default'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/1661ca36a2db-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/130b3ecce071-amend-backup.hg (glob)
   $ hg branches
-  default                        2:f24ee5961967
+  default                        2:9ac2de9c0b28
 
 Close branch:
 
   $ hg up -q 0
   $ echo b >> b
@@ -253,13 +252,13 @@ Same thing, different code path:
   $ echo b >> b
   $ hg ci -m 'reopen branch'
   reopening closed branch head 4
   $ echo b >> b
   $ hg ci --amend --close-branch
-  saved backup bundle to $TESTTMP/.hg/strip-backup/5e302dcc12b8-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/2cd74a061250-amend-backup.hg (glob)
   $ hg branches
-  default                        2:f24ee5961967
+  default                        2:9ac2de9c0b28
 
 Refuse to amend merges:
 
   $ hg up -q default
   $ hg merge foo
@@ -277,30 +276,30 @@ Follow copies/renames:
 
   $ hg mv b c
   $ hg ci -m 'b -> c'
   $ hg mv c d
   $ hg ci --amend -m 'b -> d'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/9c207120aa98-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/6d397cf8f8b4-amend-backup.hg (glob)
   $ hg st --rev '.^' --copies d
   A d
     b
   $ hg cp d e
   $ hg ci -m 'e = d'
   $ hg cp e f
   $ hg ci --amend -m 'f = d'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/fda2b3b27b22-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/1dff0fdfdd5c-amend-backup.hg (glob)
   $ hg st --rev '.^' --copies f
   A f
     d
 
   $ mv f f.orig
   $ hg rm -A f
   $ hg ci -m removef
   $ hg cp a f
   $ mv f.orig f
   $ hg ci --amend -m replacef
-  saved backup bundle to $TESTTMP/.hg/strip-backup/20a7413547f9-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/38996f6f2192-amend-backup.hg (glob)
   $ hg st --change . --copies
   $ hg log -r . --template "{file_copies}\n"
   
 
 Move added file (issue3410):
@@ -308,11 +307,11 @@ Move added file (issue3410):
   $ echo g >> g
   $ hg ci -Am g
   adding g
   $ hg mv g h
   $ hg ci --amend
-  saved backup bundle to $TESTTMP/.hg/strip-backup/5daa77a5d616-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/7a2783ffccd0-amend-backup.hg (glob)
   $ hg st --change . --copies h
   A h
   $ hg log -r . --template "{file_copies}\n"
   
 
@@ -328,15 +327,15 @@ Preserve extra dict (issue3430):
   marked working directory as branch a
   (branches are permanent and global, did you want a bookmark?)
   $ echo a >> a
   $ hg ci -ma
   $ hg ci --amend -m "a'"
-  saved backup bundle to $TESTTMP/.hg/strip-backup/167f8e3031df-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/ec57d9745b53-amend-backup.hg (glob)
   $ hg log -r . --template "{branch}\n"
   a
   $ hg ci --amend -m "a''"
-  saved backup bundle to $TESTTMP/.hg/strip-backup/ceac1a44c806-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/a871d6652029-amend-backup.hg (glob)
   $ hg log -r . --template "{branch}\n"
   a
 
 Also preserve other entries in the dict that are in the old commit,
 first graft something so there's an additional entry:
@@ -349,12 +348,13 @@ first graft something so there's an addi
   $ hg up 11
   5 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg graft 12
   grafting revision 12
   $ hg ci --amend -m 'graft amend'
-  saved backup bundle to $TESTTMP/.hg/strip-backup/18a5124daf7a-amend-backup.hg (glob)
+  saved backup bundle to $TESTTMP/.hg/strip-backup/9a61d80193bf-amend-backup.hg (glob)
   $ hg log -r . --debug | grep extra
+  extra:       amend-from=9a61d80193bfc77ffbd78c0b797bfa6911a1856f
   extra:       branch=a
   extra:       source=2647734878ef0236dda712fae9c1651cf694ea8a
 
 Preserve phase
 
@@ -389,30 +389,30 @@ Amend with no files changes
   13
   $ hg ci --amend -m 'babar'
   $ hg id -n
   14
   $ hg log -Gl 3 --style=compact
-  @  14[tip]:11   43df5a5434ad   1970-01-01 00:00 +0000   test
+  @  14[tip]:11   0eee7ea905ca   1970-01-01 00:00 +0000   test
   |    babar
   |
   | o  12:0   2647734878ef   1970-01-01 00:00 +0000   test
   | |    fork
   | |
-  o |  11   7e09f708a0e9   1970-01-01 00:00 +0000   test
+  o |  11   02c38da88c2f   1970-01-01 00:00 +0000   test
   | |    a''
   | |
   $ hg log -Gl 4 --hidden --style=compact
-  @  14[tip]:11   43df5a5434ad   1970-01-01 00:00 +0000   test
+  @  14[tip]:11   0eee7ea905ca   1970-01-01 00:00 +0000   test
   |    babar
   |
-  | x  13:11   175fafee6f44   1970-01-01 00:00 +0000   test
+  | x  13:11   3e7615e4fce4   1970-01-01 00:00 +0000   test
   |/     amend for phase
   |
   | o  12:0   2647734878ef   1970-01-01 00:00 +0000   test
   | |    fork
   | |
-  o |  11   7e09f708a0e9   1970-01-01 00:00 +0000   test
+  o |  11   02c38da88c2f   1970-01-01 00:00 +0000   test
   | |    a''
   | |
 
 Amend with files changes
 
@@ -420,25 +420,36 @@ Amend with files changes
 ride of)
 
   $ echo 'babar' >> a
   $ hg commit --amend
   $ hg log -Gl 6 --hidden --style=compact
-  @  16[tip]:11   31e0a4a1b04a   1970-01-01 00:00 +0000   test
+  @  16[tip]:11   bf9d312126f3   1970-01-01 00:00 +0000   test
   |    babar
   |
-  | x  15   053c696ada75   1970-01-01 00:00 +0000   test
-  | |    temporary amend commit for 43df5a5434ad
+  | x  15   a607aafa01c9   1970-01-01 00:00 +0000   test
+  | |    temporary amend commit for 0eee7ea905ca
   | |
-  | x  14:11   43df5a5434ad   1970-01-01 00:00 +0000   test
+  | x  14:11   0eee7ea905ca   1970-01-01 00:00 +0000   test
   |/     babar
   |
-  | x  13:11   175fafee6f44   1970-01-01 00:00 +0000   test
+  | x  13:11   3e7615e4fce4   1970-01-01 00:00 +0000   test
   |/     amend for phase
   |
   | o  12:0   2647734878ef   1970-01-01 00:00 +0000   test
   | |    fork
   | |
-  o |  11   7e09f708a0e9   1970-01-01 00:00 +0000   test
+  o |  11   02c38da88c2f   1970-01-01 00:00 +0000   test
   | |    a''
   | |
 
 
+Test that amend does not make it easy to create obsoletescence cycle
+---------------------------------------------------------------------
+
+
+  $ hg id -r 14
+  0eee7ea905ca (a)
+  $ hg revert -ar 14
+  reverting a
+  $ hg commit --amend
+  $ hg id
+  8ccab5c7e7fb (a) tip
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -507,13 +507,13 @@ amend
   $ hg -q commit -d '14 1' -m 'prepare amend'
 
   $ hg --debug commit --amend -d '15 1' -m 'amend without changes' | grep keywords
   overwriting a expanding keywords
   $ hg -q id
-  577e60613a88
+  50941c542db8
   $ head -1 a
-  expand $Id: a,v 577e60613a88 1970/01/01 00:00:15 test $
+  expand $Id: a,v 50941c542db8 1970/01/01 00:00:15 test $
 
   $ hg -q strip -n tip
 
 Test patch queue repo
 


More information about the Mercurial-devel mailing list