store: keep an accumulated length for the shorted dirs in _hybridencode
authorAdrian Buehlmann <adrian@cadifra.com>
Sun, 16 Sep 2012 11:36:00 +0200
changeset 17588 3d789dd72316
parent 17587 5fb8cf6f4f58
child 17589 b11024849db6
store: keep an accumulated length for the shorted dirs in _hybridencode so we don't have to repeatedly do '/'.join(sdirs) inside the loop
mercurial/store.py
--- a/mercurial/store.py	Sun Sep 16 11:35:55 2012 +0200
+++ b/mercurial/store.py	Sun Sep 16 11:36:00 2012 +0200
@@ -204,15 +204,20 @@
         basename = parts[-1]
         _root, ext = os.path.splitext(basename)
         sdirs = []
+        sdirslen = 0
         for p in parts[:-1]:
             d = p[:_dirprefixlen]
             if d[-1] in '. ':
                 # Windows can't access dirs ending in period or space
                 d = d[:-1] + '_'
-            t = '/'.join(sdirs) + '/' + d
-            if len(t) > _maxshortdirslen:
-                break
+            if sdirslen == 0:
+                t = len(d)
+            else:
+                t = sdirslen + 1 + len(d)
+                if t > _maxshortdirslen:
+                    break
             sdirs.append(d)
+            sdirslen = t
         dirs = '/'.join(sdirs)
         if len(dirs) > 0:
             dirs += '/'