changeset 6839:01db3e101362

move filename encoding functions from util.py to new store.py
author Adrian Buehlmann <adrian@cadifra.com>
date Thu, 24 Jul 2008 16:32:51 +0200
parents 15ee8066bf5b
children 80e51429cb9a
files mercurial/localrepo.py mercurial/statichttprepo.py mercurial/store.py mercurial/util.py
diffstat 4 files changed, 47 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Thu Jul 24 22:46:45 2008 +0200
+++ b/mercurial/localrepo.py	Thu Jul 24 16:32:51 2008 +0200
@@ -9,7 +9,7 @@
 from i18n import _
 import repo, changegroup
 import changelog, dirstate, filelog, manifest, context, weakref
-import lock, transaction, stat, errno, ui
+import lock, transaction, stat, errno, ui, store
 import os, revlog, time, util, extensions, hook, inspect
 import match as match_
 
@@ -62,8 +62,8 @@
 
         # setup store
         if "store" in requirements:
-            self.encodefn = util.encodefilename
-            self.decodefn = util.decodefilename
+            self.encodefn = store.encodefilename
+            self.decodefn = store.decodefilename
             self.spath = os.path.join(self.path, "store")
         else:
             self.encodefn = lambda x: x
@@ -83,7 +83,7 @@
         self.opener.createmode = mode
         sopener = util.opener(self.spath)
         sopener.createmode = mode
-        self.sopener = util.encodedopener(sopener, self.encodefn)
+        self.sopener = store.encodedopener(sopener, self.encodefn)
 
         self.ui = ui.ui(parentui=parentui)
         try:
--- a/mercurial/statichttprepo.py	Thu Jul 24 22:46:45 2008 +0200
+++ b/mercurial/statichttprepo.py	Thu Jul 24 16:32:51 2008 +0200
@@ -9,7 +9,7 @@
 
 from i18n import _
 import changelog, httprangereader
-import repo, localrepo, manifest, util
+import repo, localrepo, manifest, util, store
 import urllib, urllib2, errno
 
 class rangereader(httprangereader.httprangereader):
@@ -55,14 +55,14 @@
 
         # setup store
         if "store" in requirements:
-            self.encodefn = util.encodefilename
-            self.decodefn = util.decodefilename
+            self.encodefn = store.encodefilename
+            self.decodefn = store.decodefilename
             self.spath = self.path + "/store"
         else:
             self.encodefn = lambda x: x
             self.decodefn = lambda x: x
             self.spath = self.path
-        self.sopener = util.encodedopener(opener(self.spath), self.encodefn)
+        self.sopener = store.encodedopener(opener(self.spath), self.encodefn)
 
         self.manifest = manifest.manifest(self.sopener)
         self.changelog = changelog.changelog(self.sopener)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/store.py	Thu Jul 24 16:32:51 2008 +0200
@@ -0,0 +1,39 @@
+# store.py - repository store handling for Mercurial
+#
+# Copyright 2008 Matt Mackall <mpm@selenic.com>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+def _buildencodefun():
+    e = '_'
+    win_reserved = [ord(x) for x in '\\:*?"<>|']
+    cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ])
+    for x in (range(32) + range(126, 256) + win_reserved):
+        cmap[chr(x)] = "~%02x" % x
+    for x in range(ord("A"), ord("Z")+1) + [ord(e)]:
+        cmap[chr(x)] = e + chr(x).lower()
+    dmap = {}
+    for k, v in cmap.iteritems():
+        dmap[v] = k
+    def decode(s):
+        i = 0
+        while i < len(s):
+            for l in xrange(1, 4):
+                try:
+                    yield dmap[s[i:i+l]]
+                    i += l
+                    break
+                except KeyError:
+                    pass
+            else:
+                raise KeyError
+    return (lambda s: "".join([cmap[c] for c in s]),
+            lambda s: "".join(list(decode(s))))
+
+encodefilename, decodefilename = _buildencodefun()
+
+def encodedopener(openerfn, fn):
+    def o(path, *args, **kw):
+        return openerfn(fn(path), *args, **kw)
+    return o
--- a/mercurial/util.py	Thu Jul 24 22:46:45 2008 +0200
+++ b/mercurial/util.py	Thu Jul 24 16:32:51 2008 +0200
@@ -1345,39 +1345,6 @@
         return name
     return find_in_path(name, os.environ.get('PATH', ''), default=default)
 
-def _buildencodefun():
-    e = '_'
-    win_reserved = [ord(x) for x in '\\:*?"<>|']
-    cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ])
-    for x in (range(32) + range(126, 256) + win_reserved):
-        cmap[chr(x)] = "~%02x" % x
-    for x in range(ord("A"), ord("Z")+1) + [ord(e)]:
-        cmap[chr(x)] = e + chr(x).lower()
-    dmap = {}
-    for k, v in cmap.iteritems():
-        dmap[v] = k
-    def decode(s):
-        i = 0
-        while i < len(s):
-            for l in xrange(1, 4):
-                try:
-                    yield dmap[s[i:i+l]]
-                    i += l
-                    break
-                except KeyError:
-                    pass
-            else:
-                raise KeyError
-    return (lambda s: "".join([cmap[c] for c in s]),
-            lambda s: "".join(list(decode(s))))
-
-encodefilename, decodefilename = _buildencodefun()
-
-def encodedopener(openerfn, fn):
-    def o(path, *args, **kw):
-        return openerfn(fn(path), *args, **kw)
-    return o
-
 def mktempcopy(name, emptyok=False, createmode=None):
     """Create a temporary file with the same contents from name