[PATCH 05 of 10] store: unindent most of the contents of the for loop in _auxencode()

Adrian Buehlmann adrian at cadifra.com
Sat Sep 15 16:01:46 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1347738172 -7200
# Node ID b644287e79a8ee47711b36dbd0d9a852d8e99269
# Parent  7ed972a9e7a9e5ecf33ce1634a91926a1067da9a
store: unindent most of the contents of the for loop in _auxencode()

by refactoring

    for i, n in enumerate(res):
        if n:
            <main code block>

to

    for i, n in enumerate(res):
        if not n:
            continue
        <main code block>

(no functional change)

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -143,25 +143,26 @@
     '''
     res = path.split('/')
     for i, n in enumerate(res):
-        if n:
-            if dotencode and n[0] in '. ':
-                n = "~%02x" % ord(n[0]) + n[1:]
+        if not n:
+            continue
+        if dotencode and n[0] in '. ':
+            n = "~%02x" % ord(n[0]) + n[1:]
+            res[i] = n
+        else:
+            l = n.find('.')
+            if l == -1:
+                l = len(n)
+            if ((l == 3 and n[:3] in _winres3) or
+                (l == 4 and n[3] <= '9' and n[3] >= '1'
+                        and n[:3] in _winres4)):
+                # encode third letter ('aux' -> 'au~78')
+                ec = "~%02x" % ord(n[2])
+                n = n[0:2] + ec + n[3:]
                 res[i] = n
-            else:
-                l = n.find('.')
-                if l == -1:
-                    l = len(n)
-                if ((l == 3 and n[:3] in _winres3) or
-                    (l == 4 and n[3] <= '9' and n[3] >= '1'
-                            and n[:3] in _winres4)):
-                    # encode third letter ('aux' -> 'au~78')
-                    ec = "~%02x" % ord(n[2])
-                    n = n[0:2] + ec + n[3:]
-                    res[i] = n
-            if n[-1] in '. ':
-                # encode last period or space ('foo...' -> 'foo..~2e')
-                n = n[:-1] + "~%02x" % ord(n[-1])
-                res[i] = n
+        if n[-1] in '. ':
+            # encode last period or space ('foo...' -> 'foo..~2e')
+            n = n[:-1] + "~%02x" % ord(n[-1])
+            res[i] = n
     return '/'.join(res)
 
 _maxstorepathlen = 120


More information about the Mercurial-devel mailing list