[PATCH 5 of 8] Fix for issue 750 (Revisions with case-only renames ...)

Paul Moore p.f.moore at gmail.com
Wed Apr 30 12:37:27 CDT 2008


# HG changeset patch
# User "Paul Moore <p.f.moore at gmail.com>"
# Date 1209573973 -3600
# Node ID 114727a7ad5604c8c31324ebb431b372eec73061
# Parent  c7ddd7a0bf7b980bf39ccd206cf19ca86f95f281
Fix for issue 750 (Revisions with case-only renames ...)

This patch ensures that case-only renames are merged correctly by sorting the
merge actions case insensitively on filename, and then making sure removes
sort before fetches (so that the remove of the old case does not remove the
newly-fetched new case).

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -258,11 +258,41 @@
 
     return action
 
+def actioncmp(a1, a2):
+    '''Compare actions on case-folding filesystems.
+
+    Filenames are compared first, in a case insensitive manner. Next, actions
+    are compared so that removes sort first (so that a remove and a get don't
+    get handled in the order get new/remove old when new and old are the same
+    apart from case). Finally, the remaining fields are compared.
+    '''
+    file1 = a1[0]
+    file2 = a2[0]
+    # We can get non-string values, such as None
+    try:
+        c = cmp(file1.lower(), file2.lower())
+    except AttributeError:
+        c = cmp(file1, file2)
+
+    if c != 0:
+        return c
+
+    # Always do removes first.
+    if a1[1] == 'r':
+        return -1
+    if a2[1] == 'r':
+        return 1
+
+    return cmp(a1[1:], a2[1:])
+
 def applyupdates(repo, action, wctx, mctx):
     "apply the merge action list to the working directory"
 
     updated, merged, removed, unresolved = 0, 0, 0, 0
-    action.sort()
+    if repo.dirstate.casefold():
+        action.sort(actioncmp)
+    else:
+        action.sort()
 
     ms = mergestate(repo)
     ms.reset(wctx.parents()[0].node())


More information about the Mercurial-devel mailing list