[PATCH 2 of 5] Add util.endswithsep() and use it instead of using os.sep directly

Shun-ichi Goto shunichi.goto at gmail.com
Sun Jan 6 06:26:13 CST 2008


# HG changeset patch
# User Shun-ichi GOTO <shunichi.goto at gmail.com>
# Date 1199621768 -32400
# Node ID 43ff7c5ed8446a721a7bad5655ddd59f8fc62e7b
# Parent  6b70720b93c7fd612cf286fbfb7501bcf3a8735b
Add util.endswithsep() and use it instead of using os.sep directly.

This is required for workaround of 0x5c issue.

diff -r 6b70720b93c7 -r 43ff7c5ed844 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sun Jan 06 21:15:34 2008 +0900
+++ b/mercurial/cmdutil.py	Sun Jan 06 21:16:08 2008 +0900
@@ -462,7 +462,7 @@ def copy(ui, repo, pats, opts, rename=Fa
         if len(pats) > 1 or util.patkind(pats[0], None)[0]:
             raise util.Abort(_('with multiple sources, destination must be an '
                                'existing directory'))
-        if dest.endswith(os.sep) or os.altsep and dest.endswith(os.altsep):
+        if util.endswithsep(dest):
             raise util.Abort(_('destination %s is not a directory') % dest)
 
     tfn = targetpathfn
diff -r 6b70720b93c7 -r 43ff7c5ed844 mercurial/dirstate.py
--- a/mercurial/dirstate.py	Sun Jan 06 21:15:34 2008 +0900
+++ b/mercurial/dirstate.py	Sun Jan 06 21:16:08 2008 +0900
@@ -74,7 +74,7 @@ class dirstate(object):
         if cwd == self._root: return ''
         # self._root ends with a path separator if self._root is '/' or 'C:\'
         rootsep = self._root
-        if not rootsep.endswith(os.sep):
+        if not util.endswithsep(rootsep):
             rootsep += os.sep
         if cwd.startswith(rootsep):
             return cwd[len(rootsep):]
@@ -410,7 +410,7 @@ class dirstate(object):
 
         # self._root may end with a path separator when self._root == '/'
         common_prefix_len = len(self._root)
-        if not self._root.endswith(os.sep):
+        if not util.endswithsep(self._root):
             common_prefix_len += 1
 
         normpath = util.normpath
diff -r 6b70720b93c7 -r 43ff7c5ed844 mercurial/util.py
--- a/mercurial/util.py	Sun Jan 06 21:15:34 2008 +0900
+++ b/mercurial/util.py	Sun Jan 06 21:16:08 2008 +0900
@@ -341,7 +341,7 @@ def canonpath(root, cwd, myname):
     """return the canonical path of myname, given cwd and root"""
     if root == os.sep:
         rootsep = os.sep
-    elif root.endswith(os.sep):
+    elif endswithsep(root):
         rootsep = root
     else:
         rootsep = root + os.sep
@@ -881,6 +881,10 @@ def needbinarypatch():
 def needbinarypatch():
     """return True if patches should be applied in binary mode by default."""
     return os.name == 'nt'
+
+def endswithsep(path):
+    '''Check path ends with os.sep or os.altsep.'''
+    return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep)
 
 # Platform specific variants
 if os.name == 'nt':


More information about the Mercurial-devel mailing list