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

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Oct 18 12:37:17 CDT 2012


I forgot the V2 flag. It is now a no-op again when possible.

On 18 oct. 2012, at 19:34, Pierre-Yves David wrote:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at logilab.fr>
> # Date 1350581428 -7200
> # Node ID 455dbbdf1df8694254850cf9c96827f8b3ff2f61
> # 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
> @@ -1696,6 +1696,19 @@
>             if not message:
>                 message = old.description()
> 
> +            if ((not node)
> +                and message == old.description()
> +                and user == old.user()
> +                and date == old.date()
> +                and extra == old.extra()):
> +                # nothing changed. continuing here would create a new node
> +                # anyway because of the amend_source noise.
> +                #
> +                # This not what we expect from amend.
> +                return old.node()
> +
> +            extra['amend_source'] = old.hex()
> +
>             new = context.memctx(repo,
>                                  parents=[base.node(), nullid],
>                                  text=message,
> 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
> @@ -32,12 +32,12 @@
> 
>   $ echo a >> a
>   $ hg ci --amend -m 'amend base1'
> -  pretxncommit 9cd25b479c51be2f4ed2c38e7abdf7ce67d8e0dc
> -  9cd25b479c51 tip
> +  pretxncommit 43f1ba15f28a50abf0aae529cf8a16bfced7b149
> +  43f1ba15f28a tip
>   saved backup bundle to $TESTTMP/.hg/strip-backup/489edb5b847d-amend-backup.hg (glob)
>   $ echo 'pretxncommit.foo = ' >> $HGRCPATH
>   $ hg diff -c .
> -  diff -r ad120869acf0 -r 9cd25b479c51 a
> +  diff -r ad120869acf0 -r 43f1ba15f28a 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 @@
> @@ -45,7 +45,7 @@
>   +a
>   +a
>   $ hg log
> -  changeset:   1:9cd25b479c51
> +  changeset:   1:43f1ba15f28a
>   tag:         tip
>   user:        test
>   date:        Thu Jan 01 00:00:00 1970 +0000
> @@ -62,36 +62,36 @@
>   $ 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/43f1ba15f28a-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/b8e3cb2b3882-amend-backup.hg (glob)
> 
>   $ hg cat b
> -  b: no such file in rev 664a9b2d60cd
> +  b: no such file in rev 74609c7f506e
>   [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 74609c7f506e
> +  copying changeset 74609c7f506e to ad120869acf0
>   a
> -  stripping amended changeset 664a9b2d60cd
> +  stripping amended changeset 74609c7f506e
>   1 changesets found
> -  saved backup bundle to $TESTTMP/.hg/strip-backup/664a9b2d60cd-amend-backup.hg (glob)
> +  saved backup bundle to $TESTTMP/.hg/strip-backup/74609c7f506e-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:1cd866679df8
>   $ hg diff -c .
> -  diff -r ad120869acf0 -r ea6e356ff2ad a
> +  diff -r ad120869acf0 -r 1cd866679df8 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 @@
> @@ -99,7 +99,7 @@
>   +a
>   +a
>   $ hg log
> -  changeset:   1:ea6e356ff2ad
> +  changeset:   1:1cd866679df8
>   tag:         tip
>   user:        test
>   date:        Thu Jan 01 00:00:00 1970 +0000
> @@ -119,12 +119,12 @@
> 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/1cd866679df8-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/780e6f23e03d-amend-backup.hg (glob)
>   $ hg log -r .
> -  changeset:   1:2c94e4a5756f
> +  changeset:   1:5f357c7560ab
>   tag:         tip
>   user:        foo
>   date:        Thu Jan 01 00:00:01 1970 +0000
> @@ -139,8 +139,18 @@
>> 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 5f357c7560ab
> +  copying changeset 5f357c7560ab to ad120869acf0
> +  nothing changed
> +  [1]
> +
> +Same, but with changes in working dir (different code path):
> +
> +  $ echo a >> a
> +  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
> +  amending changeset 5f357c7560ab
> +  a
> +  copying changeset f02535e08f4d to ad120869acf0
>   no changes, new message
> 
> 
> @@ -151,49 +161,21 @@
>   HG: branch 'default'
>   HG: changed a
>   a
> -  stripping amended changeset 2c94e4a5756f
> -  1 changesets found
> -  saved backup bundle to $TESTTMP/.hg/strip-backup/2c94e4a5756f-amend-backup.hg (glob)
> +  stripping intermediate changeset f02535e08f4d
> +  stripping amended changeset 5f357c7560ab
> +  2 changesets found
> +  saved backup bundle to $TESTTMP/.hg/strip-backup/5f357c7560ab-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
> -
> -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
> -  a
> -  copying changeset a4f8a65b7c6a 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
> -  2 changesets found
> -  saved backup bundle to $TESTTMP/.hg/strip-backup/ffb49186f961-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:e0125bba593d
> 
>   $ rm editor.sh
>   $ hg log -r .
> -  changeset:   1:fb6cca43446f
> +  changeset:   1:e0125bba593d
>   tag:         tip
>   user:        foo
>   date:        Thu Jan 01 00:00:01 1970 +0000
> @@ -205,16 +187,16 @@
>   $ 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/e0125bba593d-amend-backup.hg (glob)
>   $ hg book
> -     book1                     1:0cf1c7a51bcf
> -   * book2                     1:0cf1c7a51bcf
> +     book1                     1:388d4e9962f4
> +   * book2                     1:388d4e9962f4
>   $ 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/388d4e9962f4-amend-backup.hg (glob)
>   $ hg book
> -     book1                     1:7344472bd951
> -   * book2                     1:7344472bd951
> +     book1                     1:3eadedadd2a5
> +   * book2                     1:3eadedadd2a5
> 
>   $ echo '[defaults]' >> $HGRCPATH
>   $ echo "commit=-d '0 0'" >> $HGRCPATH
> @@ -230,9 +212,9 @@
>   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/cb540325a83b-amend-backup.hg (glob)
>   $ hg branches
> -  default                        2:f24ee5961967
> +  default                        2:c0086a0bcc8c
> 
> Close branch:
> 
> @@ -255,9 +237,9 @@
>   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/027371728205-amend-backup.hg (glob)
>   $ hg branches
> -  default                        2:f24ee5961967
> +  default                        2:c0086a0bcc8c
> 
> Refuse to amend merges:
> 
> @@ -279,7 +261,7 @@
>   $ 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/6f0c0cb9e3db-amend-backup.hg (glob)
>   $ hg st --rev '.^' --copies d
>   A d
>     b
> @@ -287,7 +269,7 @@
>   $ 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/267f73b6edc3-amend-backup.hg (glob)
>   $ hg st --rev '.^' --copies f
>   A f
>     d
> @@ -298,7 +280,7 @@
>   $ 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/93cf733a9698-amend-backup.hg (glob)
>   $ hg st --change . --copies
>   $ hg log -r . --template "{file_copies}\n"
> 
> @@ -310,7 +292,7 @@
>   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/367111251f45-amend-backup.hg (glob)
>   $ hg st --change . --copies h
>   A h
>   $ hg log -r . --template "{file_copies}\n"
> @@ -330,11 +312,11 @@
>   $ 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/983169425fbb-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/902544419d9e-amend-backup.hg (glob)
>   $ hg log -r . --template "{branch}\n"
>   a
> 
> @@ -351,8 +333,9 @@
>   $ 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/890ce14987d2-amend-backup.hg (glob)
>   $ hg log -r . --debug | grep extra
> +  extra:       amend_source=890ce14987d22ca4c9e0ed6888701c640f5a1557
>   extra:       branch=a
>   extra:       source=2647734878ef0236dda712fae9c1651cf694ea8a
> 
> @@ -391,26 +374,26 @@
>   $ hg id -n
>   14
>   $ hg log -Gl 3 --style=compact
> -  @  14[tip]:11   43df5a5434ad   1970-01-01 00:00 +0000   test
> +  @  14[tip]:11   f85c3f3eac55   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   0a74115ec4cb   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   f85c3f3eac55   1970-01-01 00:00 +0000   test
>   |    babar
>   |
> -  | x  13:11   175fafee6f44   1970-01-01 00:00 +0000   test
> +  | x  13:11   d0d00603115a   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   0a74115ec4cb   1970-01-01 00:00 +0000   test
>   | |    a''
>   | |
> 
> @@ -422,23 +405,34 @@
>   $ 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   e782db26bdad   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   57a711f88bf5   1970-01-01 00:00 +0000   test
> +  | |    temporary amend commit for f85c3f3eac55
>   | |
> -  | x  14:11   43df5a5434ad   1970-01-01 00:00 +0000   test
> +  | x  14:11   f85c3f3eac55   1970-01-01 00:00 +0000   test
>   |/     babar
>   |
> -  | x  13:11   175fafee6f44   1970-01-01 00:00 +0000   test
> +  | x  13:11   d0d00603115a   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   0a74115ec4cb   1970-01-01 00:00 +0000   test
>   | |    a''
>   | |
> 
> 
> +Test that amend does not make it easy to create obsoletescence cycle
> +---------------------------------------------------------------------
> +
> +
> +  $ hg id -r 14
> +  f85c3f3eac55 (a)
> +  $ hg revert -ar 14
> +  reverting a
> +  $ hg commit --amend
> +  $ hg id
> +  bf4080b6674e (a) tip
> diff --git a/tests/test-keyword.t b/tests/test-keyword.t
> --- a/tests/test-keyword.t
> +++ b/tests/test-keyword.t
> @@ -509,9 +509,9 @@
>   $ hg --debug commit --amend -d '15 1' -m 'amend without changes' | grep keywords
>   overwriting a expanding keywords
>   $ hg -q id
> -  577e60613a88
> +  67d8c481a6be
>   $ head -1 a
> -  expand $Id: a,v 577e60613a88 1970/01/01 00:00:15 test $
> +  expand $Id: a,v 67d8c481a6be 1970/01/01 00:00:15 test $
> 
>   $ hg -q strip -n tip
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list