Merge with crew.
authorThomas Arendsen Hein <thomas@intevation.de>
Thu, 16 Nov 2006 08:52:55 +0100
changeset 3672 e8730b5b8a32
parent 3671 86d3f966201d (current diff)
parent 3670 d2d8d23944a9 (diff)
child 3673 eb0b4a2d70a9
Merge with crew.
mercurial/commands.py
--- a/contrib/zsh_completion	Thu Nov 16 08:51:22 2006 +0100
+++ b/contrib/zsh_completion	Thu Nov 16 08:52:55 2006 +0100
@@ -377,7 +377,7 @@
 
 _hg_cmd_commit() {
   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]'
+  '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]' \
   '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
   '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_file -g \*.txt' \
   '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
--- a/mercurial/commands.py	Thu Nov 16 08:51:22 2006 +0100
+++ b/mercurial/commands.py	Thu Nov 16 08:52:55 2006 +0100
@@ -437,11 +437,17 @@
 
 def docopy(ui, repo, pats, opts, wlock):
     # called with the repo lock held
+    #
+    # hgsep => pathname that uses "/" to separate directories
+    # ossep => pathname that uses os.sep to separate directories
     cwd = repo.getcwd()
     errors = 0
     copied = []
     targets = {}
 
+    # abs: hgsep
+    # rel: ossep
+    # return: hgsep
     def okaytocopy(abs, rel, exact):
         reasons = {'?': _('is not managed'),
                    'a': _('has been marked for add'),
@@ -458,13 +464,18 @@
         else:
             return abs
 
+    # origsrc: hgsep
+    # abssrc: hgsep
+    # relsrc: ossep
+    # target: ossep
     def copy(origsrc, abssrc, relsrc, target, exact):
         abstarget = util.canonpath(repo.root, cwd, target)
         reltarget = util.pathto(cwd, abstarget)
         prevsrc = targets.get(abstarget)
         if prevsrc is not None:
             ui.warn(_('%s: not overwriting - %s collides with %s\n') %
-                    (reltarget, abssrc, prevsrc))
+                    (reltarget, util.localpath(abssrc),
+                     util.localpath(prevsrc)))
             return
         if (not opts['after'] and os.path.exists(reltarget) or
             opts['after'] and repo.dirstate.state(abstarget) not in '?r'):
@@ -507,26 +518,37 @@
             repo.copy(origsrc, abstarget, wlock)
         copied.append((abssrc, relsrc, exact))
 
+    # pat: ossep
+    # dest ossep
+    # srcs: list of (hgsep, hgsep, ossep, bool)
+    # return: function that takes hgsep and returns ossep
     def targetpathfn(pat, dest, srcs):
         if os.path.isdir(pat):
             abspfx = util.canonpath(repo.root, cwd, pat)
+            abspfx = util.localpath(abspfx)
             if destdirexists:
                 striplen = len(os.path.split(abspfx)[0])
             else:
                 striplen = len(abspfx)
             if striplen:
                 striplen += len(os.sep)
-            res = lambda p: os.path.join(dest, p[striplen:])
+            res = lambda p: os.path.join(dest, util.localpath(p)[striplen:])
         elif destdirexists:
-            res = lambda p: os.path.join(dest, os.path.basename(p))
+            res = lambda p: os.path.join(dest,
+                                         os.path.basename(util.localpath(p)))
         else:
             res = lambda p: dest
         return res
 
+    # pat: ossep
+    # dest ossep
+    # srcs: list of (hgsep, hgsep, ossep, bool)
+    # return: function that takes hgsep and returns ossep
     def targetpathafterfn(pat, dest, srcs):
         if util.patkind(pat, None)[0]:
             # a mercurial pattern
-            res = lambda p: os.path.join(dest, os.path.basename(p))
+            res = lambda p: os.path.join(dest,
+                                         os.path.basename(util.localpath(p)))
         else:
             abspfx = util.canonpath(repo.root, cwd, pat)
             if len(abspfx) < len(srcs[0][0]):
@@ -535,11 +557,12 @@
                 def evalpath(striplen):
                     score = 0
                     for s in srcs:
-                        t = os.path.join(dest, s[0][striplen:])
+                        t = os.path.join(dest, util.localpath(s[0])[striplen:])
                         if os.path.exists(t):
                             score += 1
                     return score
 
+                abspfx = util.localpath(abspfx)
                 striplen = len(abspfx)
                 if striplen:
                     striplen += len(os.sep)
@@ -550,11 +573,13 @@
                         striplen1 += len(os.sep)
                     if evalpath(striplen1) > score:
                         striplen = striplen1
-                res = lambda p: os.path.join(dest, p[striplen:])
+                res = lambda p: os.path.join(dest,
+                                             util.localpath(p)[striplen:])
             else:
                 # a file
                 if destdirexists:
-                    res = lambda p: os.path.join(dest, os.path.basename(p))
+                    res = lambda p: os.path.join(dest,
+                                        os.path.basename(util.localpath(p)))
                 else:
                     res = lambda p: dest
         return res
--- a/mercurial/dirstate.py	Thu Nov 16 08:51:22 2006 +0100
+++ b/mercurial/dirstate.py	Thu Nov 16 08:52:55 2006 +0100
@@ -32,7 +32,11 @@
     def getcwd(self):
         cwd = os.getcwd()
         if cwd == self.root: return ''
-        return cwd[len(self.root) + 1:]
+        # self.root ends with a path separator if self.root is '/' or 'C:\'
+        common_prefix_len = len(self.root)
+        if not self.root.endswith(os.sep):
+            common_prefix_len += 1
+        return cwd[common_prefix_len:]
 
     def hgignore(self):
         '''return the contents of .hgignore files as a list of patterns.
--- a/mercurial/localrepo.py	Thu Nov 16 08:51:22 2006 +0100
+++ b/mercurial/localrepo.py	Thu Nov 16 08:52:55 2006 +0100
@@ -324,16 +324,18 @@
         partial = {}
         try:
             f = self.opener("branches.cache")
-            last, lrev = f.readline().rstrip().split(" ", 1)
+            lines = f.read().split('\n')
+            f.close()
+            last, lrev = lines.pop(0).rstrip().split(" ", 1)
             last, lrev = bin(last), int(lrev)
             if (lrev < self.changelog.count() and
                 self.changelog.node(lrev) == last): # sanity check
-                for l in f:
+                for l in lines:
+                    if not l: continue
                     node, label = l.rstrip().split(" ", 1)
                     partial[label] = bin(node)
             else: # invalidate the cache
                 last, lrev = nullid, nullrev
-            f.close()
         except IOError:
             last, lrev = nullid, nullrev
         return partial, last, lrev
@@ -581,12 +583,13 @@
 
     def commit(self, files=None, text="", user=None, date=None,
                match=util.always, force=False, lock=None, wlock=None,
-               force_editor=False, p1=None, p2=None):
+               force_editor=False, p1=None, p2=None, extra={}):
 
         commit = []
         remove = []
         changed = []
         use_dirstate = (p1 is None) # not rawcommit
+        extra = extra.copy()
 
         if use_dirstate:
             if files:
@@ -693,7 +696,6 @@
         if not lines:
             return None
         text = '\n'.join(lines)
-        extra = {}
         if branchname:
             extra["branch"] = branchname
         n = self.changelog.add(mn, changed + remove, text, tr, p1, p2,
--- a/mercurial/util.py	Thu Nov 16 08:51:22 2006 +0100
+++ b/mercurial/util.py	Thu Nov 16 08:52:55 2006 +0100
@@ -207,9 +207,12 @@
 
 def pathto(n1, n2):
     '''return the relative path from one place to another.
-    this returns a path in the form used by the local filesystem, not hg.'''
+    n1 should use os.sep to separate directories
+    n2 should use "/" to separate directories
+    returns an os.sep-separated path.
+    '''
     if not n1: return localpath(n2)
-    a, b = n1.split('/'), n2.split('/')
+    a, b = n1.split(os.sep), n2.split('/')
     a.reverse()
     b.reverse()
     while a and b and a[-1] == b[-1]: