[PATCH 1 of 2] cmdutil: rename a to A on Mac and Windows succeeds (issue1717)

Simon Heimberg simohe at besonet.ch
Wed Jul 22 13:22:36 UTC 2009


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1248259922 -7200
# Node ID ca876099803a9e71497d9deaee3c9fb7ff47ee81
# Parent  87df4249b626f412be634df807da1849cdab135b
cmdutil: rename a to A on Mac and Windows succeeds (issue1717)

diff -r 87df4249b626 -r ca876099803a mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Fre Jul 17 12:23:15 2009 +0200
+++ b/mercurial/cmdutil.py	Mit Jul 22 12:52:02 2009 +0200
@@ -388,10 +388,25 @@
                      repo.pathto(prevsrc, cwd)))
             return
 
+        def samepath(file1, file2):
+            if len(file1) <> len(file2):
+                return False
+            if hasattr(os.path, 'samefile'):
+                return os.path.samefile(file1, file2)
+            return os.path.normcase(file1) == os.path.normcase(file2)
+
         # check for overwrites
         exists = os.path.exists(target)
+        changecase = False
         if not after and exists or after and state in 'mn':
-            if not opts['force']:
+            if opts['force']:
+                pass
+            elif not after and samepath(src, target):
+                #case change on case insensitive filesystems
+                if not dryrun:
+                    os.rename(src, target)
+                changecase = True
+            else:
                 ui.warn(_('%s: not overwriting - file exists\n') %
                         reltarget)
                 return
@@ -399,7 +414,7 @@
         if after:
             if not exists:
                 return
-        elif not dryrun:
+        elif not dryrun and not changecase:
             try:
                 if exists:
                     os.unlink(target)
@@ -439,7 +454,7 @@
             elif not dryrun:
                 repo.copy(origsrc, abstarget)
 
-        if rename and not dryrun:
+        if rename and not dryrun and not changecase:
             repo.remove([abssrc], not after)
 
     # pat: ossep



More information about the Mercurial-devel mailing list