[PATCH 2 of 2] store: add a fallback _pathencode Python function

Adrian Buehlmann adrian at cadifra.com
Wed Sep 19 07:15:44 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1348056023 -7200
# Node ID 6f0db549411eb13e6169410e46a075d97f4687d2
# Parent  28fbfcdd9c9384a4ea24c28c88636ed0633615ae
store: add a fallback _pathencode Python function

which does the equivalent of parsers.pathencode, so it can be used as a
default

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -254,20 +254,24 @@
         res = _hashencode(path, dotencode)
     return res
 
+def _pathencode(path):
+    ef = _encodefname(encodedir(path)).split('/')
+    res = '/'.join(_auxencode(ef, True))
+    if len(res) > _maxstorepathlen:
+        return None
+    return res
+
+_pathencode = getattr(parsers, 'pathencode', _pathencode)
+
+def _dothybridencode(f):
+    ef = _pathencode(f)
+    if ef is None:
+        return _hashencode(encodedir(f), True)
+    return ef
+
 def _plainhybridencode(f):
     return _hybridencode(f, False)
 
-_pathencode = getattr(parsers, 'pathencode', None)
-if _pathencode:
-    def _dothybridencode(f):
-        ef = _pathencode(f)
-        if ef is None:
-            return _hashencode(encodedir(f), True)
-        return ef
-else:
-    def _dothybridencode(f):
-        return _hybridencode(f, True)
-
 def _calcmode(path):
     try:
         # files in .hg/ will be created using this mode


More information about the Mercurial-devel mailing list