comparison mercurial/store.py @ 6988:907e4e9bd3c4

Fix for Issue1260
author Adrian Buehlmann <adrian@cadifra.com>
date Sun, 31 Aug 2008 00:22:20 +0200
parents 0642d9d7ec80
children 32e68ffccbc5
comparison
equal deleted inserted replaced
6987:d09e813b21e3 6988:907e4e9bd3c4
48 48
49 _data = 'data 00manifest.d 00manifest.i 00changelog.d 00changelog.i' 49 _data = 'data 00manifest.d 00manifest.i 00changelog.d 00changelog.i'
50 50
51 class basicstore: 51 class basicstore:
52 '''base class for local repository stores''' 52 '''base class for local repository stores'''
53 def __init__(self, path, opener): 53 def __init__(self, path, opener, pathjoiner):
54 self.pathjoiner = pathjoiner
54 self.path = path 55 self.path = path
55 self.createmode = _calcmode(path) 56 self.createmode = _calcmode(path)
56 self.opener = opener(self.path) 57 self.opener = opener(self.path)
57 self.opener.createmode = self.createmode 58 self.opener.createmode = self.createmode
58 59
59 def join(self, f): 60 def join(self, f):
60 return os.path.join(self.path, f) 61 return self.pathjoiner(self.path, f)
61 62
62 def _walk(self, relpath, recurse): 63 def _walk(self, relpath, recurse):
63 '''yields (unencoded, encoded, size)''' 64 '''yields (unencoded, encoded, size)'''
64 path = os.path.join(self.path, relpath) 65 path = self.pathjoiner(self.path, relpath)
65 striplen = len(self.path) + len(os.sep) 66 striplen = len(self.path) + len(os.sep)
66 prefix = path[striplen:] 67 prefix = path[striplen:]
67 l = [] 68 l = []
68 if os.path.isdir(path): 69 if os.path.isdir(path):
69 visit = [path] 70 visit = [path]
70 while visit: 71 while visit:
71 p = visit.pop() 72 p = visit.pop()
72 for f, kind, st in osutil.listdir(p, stat=True): 73 for f, kind, st in osutil.listdir(p, stat=True):
73 fp = os.path.join(p, f) 74 fp = self.pathjoiner(p, f)
74 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'): 75 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
75 n = util.pconvert(fp[striplen:]) 76 n = util.pconvert(fp[striplen:])
76 l.append((n, n, st.st_size)) 77 l.append((n, n, st.st_size))
77 elif kind == stat.S_IFDIR and recurse: 78 elif kind == stat.S_IFDIR and recurse:
78 visit.append(fp) 79 visit.append(fp)
94 95
95 def copylist(self): 96 def copylist(self):
96 return ['requires'] + _data.split() 97 return ['requires'] + _data.split()
97 98
98 class encodedstore(basicstore): 99 class encodedstore(basicstore):
99 def __init__(self, path, opener): 100 def __init__(self, path, opener, pathjoiner):
100 self.path = os.path.join(path, 'store') 101 self.pathjoiner = pathjoiner
102 self.path = self.pathjoiner(path, 'store')
101 self.createmode = _calcmode(self.path) 103 self.createmode = _calcmode(self.path)
102 op = opener(self.path) 104 op = opener(self.path)
103 op.createmode = self.createmode 105 op.createmode = self.createmode
104 self.opener = lambda f, *args, **kw: op(encodefilename(f), *args, **kw) 106 self.opener = lambda f, *args, **kw: op(encodefilename(f), *args, **kw)
105 107
110 except KeyError: 112 except KeyError:
111 a = None 113 a = None
112 yield a, b, size 114 yield a, b, size
113 115
114 def join(self, f): 116 def join(self, f):
115 return os.path.join(self.path, encodefilename(f)) 117 return self.pathjoiner(self.path, encodefilename(f))
116 118
117 def copylist(self): 119 def copylist(self):
118 return (['requires', '00changelog.i'] + 120 return (['requires', '00changelog.i'] +
119 ['store/' + f for f in _data.split()]) 121 [self.pathjoiner('store', f) for f in _data.split()])
120 122
121 def store(requirements, path, opener): 123 def store(requirements, path, opener, pathjoiner):
122 if 'store' in requirements: 124 if 'store' in requirements:
123 return encodedstore(path, opener) 125 return encodedstore(path, opener, pathjoiner)
124 return basicstore(path, opener) 126 return basicstore(path, opener, pathjoiner)