[PATCH] Sort removes first when applying updates (fixes issues 750 and 912)

Adrian Buehlmann adrian at cadifra.com
Tue Jul 1 16:02:42 CDT 2008


On 01.07.2008 19:10, Paul Moore wrote:
> # HG changeset patch
> # User Paul Moore <p.f.moore at gmail.com>
> # Date 1214931571 -3600
> # Node ID 78b3e254478e76d8f5058670f447ae1cbceab708
> # Parent  88a1bcc5c6a7b1729eb97d0509531c0f9f4a606e
> Sort removes first when applying updates (fixes issues 750 and 912)
> 
> This change ensures that removes happen first in applyupdates(). This avoids
> issues where we try to make a case-only rename of a file on a case insensitive
> system. Without this patch, the add of the new name happens before the remove
> of the old one - which results in the file not existing, as the two names are
> effectively the same.
> 
> With the patch, the old name gets removed then the new one gets added, which
> is always safe.
> 
> diff --git a/mercurial/merge.py b/mercurial/merge.py
> --- a/mercurial/merge.py
> +++ b/mercurial/merge.py
> @@ -258,6 +258,17 @@
>  
>      return action
>  
> +def actioncmp(a1, a2):
> +    m1 = a1[1]
> +    m2 = a2[1]
> +    if m1 == m2:
> +        return cmp(a1, a2)
> +    if m1 == 'r':
> +        return -1
> +    if m2 == 'r':
> +        return 1
> +    return cmp(a1, a2)
> +
>  def applyupdates(repo, action, wctx, mctx):
>      "apply the merge action list to the working directory"
>  
> @@ -265,7 +276,7 @@
>      ms = mergestate(repo)
>      ms.reset(wctx.parents()[0].node())
>      moves = []
> -    action.sort()
> +    action.sort(actioncmp)
>  
>      # prescan for merges
>      for a in action:

I can confirm that this patch fixes issu912 on Windows and thus hope it will be
pushed. (Just for reference: an earlier version of this patch was
http://selenic.com/pipermail/mercurial-devel/2008-April/006077.html)

I've applied this patch to e81d2bd66908 from main repo and ran the testsuite
on FreeBSD.

One output needs to be adjusted for this patch (see diff below), everything
else looks good.

diff --git a/tests/test-update-reverse.out b/tests/test-update-reverse.out
--- a/tests/test-update-reverse.out
+++ b/tests/test-update-reverse.out
@@ -46,9 +46,9 @@
  side2: remote deleted -> r
  side1: remote deleted -> r
  main: remote created -> g
-getting main
 removing side1
 removing side2
+getting main
 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
 Should only show a main
 a



More information about the Mercurial-devel mailing list