[PATCH] localrepo: prevent executable-bit only changes from being lost on amend

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu May 19 18:52:18 EDT 2016



On 05/19/2016 11:39 PM, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich <mitrandir at fb.com>
> # Date 1463693722 25200
> #      Thu May 19 14:35:22 2016 -0700
> # Node ID ccd61c869f63297fbae2662314afcb7b3dce5224
> # Parent  f00f1de16454dfd31ee5e3fe301ab3225df76698
> localrepo: prevent executable-bit only changes from being lost on amend
>
> If you have just executable-bit change and amend it twice it will vanish:
>
>  * After the first amend the commit will have the proper executable bit set
>    in manifest but it won't have the the file on the list of files in
>    changelog.
>
>  * The second amend will read the wrong list of files from changelog and it
>    will copy the manifest entry from parent for this file.
>
>  * Voila! The change is lost.
>
> This change repairs the bug in localrepo causing this and adds a test for it.

Nice catch, any reason it should not go on stable?

>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1397,6 +1397,8 @@ class localrepository(object):
>              node = fctx.filenode()
>              if node in [fparent1, fparent2]:
>                  self.ui.debug('reusing %s filelog entry\n' % fname)
> +                if manifest1.flags(fname) != fctx.flags():
> +                    changelist.append(fname)
>                  return node
>  
>          flog = self.file(fname)
> 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
> @@ -1156,3 +1156,21 @@ directory)
>       rev    offset  length  delta linkrev nodeid       p1           p2
>         0         0      88     -1       3 34a4d536c0c0 000000000000 000000000000
>  
> +Test if amend preserves executable bit changes
> +  $ chmod +x newdirname/commonfile.py
> +  $ hg ci -m chmod
> +  $ hg ci --amend -m "chmod amended"
> +  $ hg ci --amend -m "chmod amended second time"
> +  $ hg log -p --git -r .
> +  changeset:   8:b1326f52dddf
> +  branch:      newdirname
> +  tag:         tip
> +  parent:      5:7fd235f7cb2f
> +  user:        test
> +  date:        Thu Jan 01 00:00:00 1970 +0000
> +  summary:     chmod amended second time
> +  
> +  diff --git a/newdirname/commonfile.py b/newdirname/commonfile.py
> +  old mode 100644
> +  new mode 100755
> +  
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list