[PATCH] mq: fix patch names/paths mismatch under win32

Patrick Mezard pmezard at gmail.com
Sat Jan 13 17:01:23 CST 2007


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1168732707 -3600
# Node ID 133fe070c4946c78e873ac205c4bf3fea36af888
# Parent  112e9c5051980f5f27410d645ec19d692aed26af
mq: fix patch names/paths mismatch under win32.

Patch names are implicit relative unix paths. Under win32, paths can have
several equivalent representations because of case-insensitivity and path
separators tolerance. To avoid confusion and improve interoperability, patch
names are normalized to unix style when generated by mq, or checked to be
unix-style when passed to commands or read from the series file. Writing
Windows relative paths in the series file will now abort.

diff -r 112e9c505198 -r 133fe070c494 hgext/mq.py
--- a/hgext/mq.py	Tue Nov 21 21:05:28 2006 -0200
+++ b/hgext/mq.py	Sun Jan 14 00:58:27 2007 +0100
@@ -34,6 +34,10 @@ import os, sys, re, errno
 import os, sys, re, errno
 
 commands.norepo += " qclone qversion"
+
+# Patch names looks like unix-file names.
+# They must be joinable with queue directory and result in the patch path.
+normname = util.normpath
 
 class statusentry:
     def __init__(self, rev, name=None):
@@ -112,6 +116,9 @@ class queue:
                 comment = l[h:]
             patch = patch.strip()
             if patch:
+                if patch!=normname(patch):
+                    raise util.Abort(_('%s is not a valid patch name in %s') %
+                                     (patch, self.join(self.series_path)))
                 if patch in self.series:
                     raise util.Abort(_('%s appears more than once in %s') %
                                      (patch, self.join(self.series_path)))
@@ -1295,6 +1302,9 @@ class queue:
         if (len(files) > 1 or len(rev) > 1) and patchname:
             raise util.Abort(_('option "-n" not valid when importing multiple '
                                'patches'))
+        if patchname and patchname!=normname(patchname):
+            raise util.Abort(_('%s is not a valid patch name' % patchname))
+                               
         i = 0
         added = []
         if rev:
@@ -1335,7 +1345,7 @@ class queue:
                 lastparent = p1
 
                 if not patchname:
-                    patchname = '%d.diff' % r
+                    patchname = normname('%d.diff' % r)
                 checkseries(patchname)
                 checkfile(patchname)
                 self.full_series.insert(0, patchname)
@@ -1375,6 +1385,7 @@ class queue:
                 checkfile(patchname)
                 patchf = self.opener(patchname, "w")
                 patchf.write(text)
+            patchname = normname(patchname)
             checkseries(patchname)
             index = self.full_series_end() + i
             self.full_series[index:index] = [patchname]
@@ -1804,7 +1815,7 @@ def rename(ui, repo, patch, name=None, *
         patch = q.lookup('qtip')
     absdest = q.join(name)
     if os.path.isdir(absdest):
-        name = os.path.join(name, os.path.basename(patch))
+        name = normname(os.path.join(name, os.path.basename(patch)))
         absdest = q.join(name)
     if os.path.exists(absdest):
         raise util.Abort(_('%s already exists') % absdest)


More information about the Mercurial-devel mailing list