Patchwork [1,of,4] dirstate: factor out code to discover normalized path

login
register
mail settings
Submitter Siddharth Agarwal
Date March 31, 2015, 4:52 p.m.
Message ID <1628a521be87f334e98a.1427820776@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8384/
State Accepted
Commit 24df9207520046b02ed5763c6aa5ae1915e88f65
Headers show

Comments

Siddharth Agarwal - March 31, 2015, 4:52 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1427682185 25200
#      Sun Mar 29 19:23:05 2015 -0700
# Node ID 1628a521be87f334e98a0575ebbb17153f1ed9b8
# Parent  888dcab69ca3fe817786a7078bb1f66afa203c8b
dirstate: factor out code to discover normalized path

In upcoming patches we're going to reuse this code. The storemap is currently
always the foldmap, but will vary in future patches.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -464,6 +464,32 @@ 
             self._droppath(f)
             del self._map[f]
 
+    def _discoverpath(self, path, normed, ignoremissing, exists, storemap):
+        if exists is None:
+            exists = os.path.lexists(os.path.join(self._root, path))
+        if not exists:
+            # Maybe a path component exists
+            if not ignoremissing and '/' in path:
+                d, f = path.rsplit('/', 1)
+                d = self._normalize(d, False, ignoremissing, None)
+                folded = d + "/" + f
+            else:
+                # No path components, preserve original case
+                folded = path
+        else:
+            # recursively normalize leading directory components
+            # against dirstate
+            if '/' in normed:
+                d, f = normed.rsplit('/', 1)
+                d = self._normalize(d, False, ignoremissing, True)
+                r = self._root + "/" + d
+                folded = d + "/" + util.fspath(f, r)
+            else:
+                folded = util.fspath(normed, self._root)
+            storemap[normed] = folded
+
+        return folded
+
     def _normalize(self, path, isknown, ignoremissing=False, exists=None):
         normed = util.normcase(path)
         folded = self._foldmap.get(normed, None)
@@ -471,29 +497,8 @@ 
             if isknown:
                 folded = path
             else:
-                if exists is None:
-                    exists = os.path.lexists(os.path.join(self._root, path))
-                if not exists:
-                    # Maybe a path component exists
-                    if not ignoremissing and '/' in path:
-                        d, f = path.rsplit('/', 1)
-                        d = self._normalize(d, isknown, ignoremissing, None)
-                        folded = d + "/" + f
-                    else:
-                        # No path components, preserve original case
-                        folded = path
-                else:
-                    # recursively normalize leading directory components
-                    # against dirstate
-                    if '/' in normed:
-                        d, f = normed.rsplit('/', 1)
-                        d = self._normalize(d, isknown, ignoremissing, True)
-                        r = self._root + "/" + d
-                        folded = d + "/" + util.fspath(f, r)
-                    else:
-                        folded = util.fspath(normed, self._root)
-                    self._foldmap[normed] = folded
-
+                folded = self._discoverpath(path, normed, ignoremissing, exists,
+                                            self._foldmap)
         return folded
 
     def normalize(self, path, isknown=False, ignoremissing=False):