Show More
@@ -0,0 +1,39 b'' | |||
|
1 | # store.py - repository store handling for Mercurial | |
|
2 | # | |
|
3 | # Copyright 2008 Matt Mackall <mpm@selenic.com> | |
|
4 | # | |
|
5 | # This software may be used and distributed according to the terms | |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
|
7 | ||
|
8 | def _buildencodefun(): | |
|
9 | e = '_' | |
|
10 | win_reserved = [ord(x) for x in '\\:*?"<>|'] | |
|
11 | cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ]) | |
|
12 | for x in (range(32) + range(126, 256) + win_reserved): | |
|
13 | cmap[chr(x)] = "~%02x" % x | |
|
14 | for x in range(ord("A"), ord("Z")+1) + [ord(e)]: | |
|
15 | cmap[chr(x)] = e + chr(x).lower() | |
|
16 | dmap = {} | |
|
17 | for k, v in cmap.iteritems(): | |
|
18 | dmap[v] = k | |
|
19 | def decode(s): | |
|
20 | i = 0 | |
|
21 | while i < len(s): | |
|
22 | for l in xrange(1, 4): | |
|
23 | try: | |
|
24 | yield dmap[s[i:i+l]] | |
|
25 | i += l | |
|
26 | break | |
|
27 | except KeyError: | |
|
28 | pass | |
|
29 | else: | |
|
30 | raise KeyError | |
|
31 | return (lambda s: "".join([cmap[c] for c in s]), | |
|
32 | lambda s: "".join(list(decode(s)))) | |
|
33 | ||
|
34 | encodefilename, decodefilename = _buildencodefun() | |
|
35 | ||
|
36 | def encodedopener(openerfn, fn): | |
|
37 | def o(path, *args, **kw): | |
|
38 | return openerfn(fn(path), *args, **kw) | |
|
39 | return o |
@@ -9,7 +9,7 b' from node import bin, hex, nullid, nullr' | |||
|
9 | 9 | from i18n import _ |
|
10 | 10 | import repo, changegroup |
|
11 | 11 | import changelog, dirstate, filelog, manifest, context, weakref |
|
12 | import lock, transaction, stat, errno, ui | |
|
12 | import lock, transaction, stat, errno, ui, store | |
|
13 | 13 | import os, revlog, time, util, extensions, hook, inspect |
|
14 | 14 | import match as match_ |
|
15 | 15 | |
@@ -62,8 +62,8 b' class localrepository(repo.repository):' | |||
|
62 | 62 | |
|
63 | 63 | # setup store |
|
64 | 64 | if "store" in requirements: |
|
65 |
self.encodefn = |
|
|
66 |
self.decodefn = |
|
|
65 | self.encodefn = store.encodefilename | |
|
66 | self.decodefn = store.decodefilename | |
|
67 | 67 | self.spath = os.path.join(self.path, "store") |
|
68 | 68 | else: |
|
69 | 69 | self.encodefn = lambda x: x |
@@ -83,7 +83,7 b' class localrepository(repo.repository):' | |||
|
83 | 83 | self.opener.createmode = mode |
|
84 | 84 | sopener = util.opener(self.spath) |
|
85 | 85 | sopener.createmode = mode |
|
86 |
self.sopener = |
|
|
86 | self.sopener = store.encodedopener(sopener, self.encodefn) | |
|
87 | 87 | |
|
88 | 88 | self.ui = ui.ui(parentui=parentui) |
|
89 | 89 | try: |
@@ -9,7 +9,7 b'' | |||
|
9 | 9 | |
|
10 | 10 | from i18n import _ |
|
11 | 11 | import changelog, httprangereader |
|
12 | import repo, localrepo, manifest, util | |
|
12 | import repo, localrepo, manifest, util, store | |
|
13 | 13 | import urllib, urllib2, errno |
|
14 | 14 | |
|
15 | 15 | class rangereader(httprangereader.httprangereader): |
@@ -55,14 +55,14 b' class statichttprepository(localrepo.loc' | |||
|
55 | 55 | |
|
56 | 56 | # setup store |
|
57 | 57 | if "store" in requirements: |
|
58 |
self.encodefn = |
|
|
59 |
self.decodefn = |
|
|
58 | self.encodefn = store.encodefilename | |
|
59 | self.decodefn = store.decodefilename | |
|
60 | 60 | self.spath = self.path + "/store" |
|
61 | 61 | else: |
|
62 | 62 | self.encodefn = lambda x: x |
|
63 | 63 | self.decodefn = lambda x: x |
|
64 | 64 | self.spath = self.path |
|
65 |
self.sopener = |
|
|
65 | self.sopener = store.encodedopener(opener(self.spath), self.encodefn) | |
|
66 | 66 | |
|
67 | 67 | self.manifest = manifest.manifest(self.sopener) |
|
68 | 68 | self.changelog = changelog.changelog(self.sopener) |
@@ -1345,39 +1345,6 b' def find_exe(name, default=None):' | |||
|
1345 | 1345 | return name |
|
1346 | 1346 | return find_in_path(name, os.environ.get('PATH', ''), default=default) |
|
1347 | 1347 | |
|
1348 | def _buildencodefun(): | |
|
1349 | e = '_' | |
|
1350 | win_reserved = [ord(x) for x in '\\:*?"<>|'] | |
|
1351 | cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ]) | |
|
1352 | for x in (range(32) + range(126, 256) + win_reserved): | |
|
1353 | cmap[chr(x)] = "~%02x" % x | |
|
1354 | for x in range(ord("A"), ord("Z")+1) + [ord(e)]: | |
|
1355 | cmap[chr(x)] = e + chr(x).lower() | |
|
1356 | dmap = {} | |
|
1357 | for k, v in cmap.iteritems(): | |
|
1358 | dmap[v] = k | |
|
1359 | def decode(s): | |
|
1360 | i = 0 | |
|
1361 | while i < len(s): | |
|
1362 | for l in xrange(1, 4): | |
|
1363 | try: | |
|
1364 | yield dmap[s[i:i+l]] | |
|
1365 | i += l | |
|
1366 | break | |
|
1367 | except KeyError: | |
|
1368 | pass | |
|
1369 | else: | |
|
1370 | raise KeyError | |
|
1371 | return (lambda s: "".join([cmap[c] for c in s]), | |
|
1372 | lambda s: "".join(list(decode(s)))) | |
|
1373 | ||
|
1374 | encodefilename, decodefilename = _buildencodefun() | |
|
1375 | ||
|
1376 | def encodedopener(openerfn, fn): | |
|
1377 | def o(path, *args, **kw): | |
|
1378 | return openerfn(fn(path), *args, **kw) | |
|
1379 | return o | |
|
1380 | ||
|
1381 | 1348 | def mktempcopy(name, emptyok=False, createmode=None): |
|
1382 | 1349 | """Create a temporary file with the same contents from name |
|
1383 | 1350 |
General Comments 0
You need to be logged in to leave comments.
Login now