##// END OF EJS Templates
introduce fncache repository layout...
Adrian Buehlmann -
r7229:7946503e default
parent child Browse files
Show More
@@ -1,2105 +1,2106 b''
1 # localrepo.py - read/write repository class for mercurial
1 # localrepo.py - read/write repository class for mercurial
2 #
2 #
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from node import bin, hex, nullid, nullrev, short
8 from node import bin, hex, nullid, nullrev, short
9 from i18n import _
9 from i18n import _
10 import repo, changegroup
10 import repo, changegroup
11 import changelog, dirstate, filelog, manifest, context, weakref
11 import changelog, dirstate, filelog, manifest, context, weakref
12 import lock, transaction, stat, errno, ui, store
12 import lock, transaction, stat, errno, ui, store
13 import os, revlog, time, util, extensions, hook, inspect
13 import os, revlog, time, util, extensions, hook, inspect
14 import match as match_
14 import match as match_
15 import merge as merge_
15 import merge as merge_
16
16
17 class localrepository(repo.repository):
17 class localrepository(repo.repository):
18 capabilities = util.set(('lookup', 'changegroupsubset'))
18 capabilities = util.set(('lookup', 'changegroupsubset'))
19 supported = ('revlogv1', 'store')
19 supported = ('revlogv1', 'store', 'fncache')
20
20
21 def __init__(self, parentui, path=None, create=0):
21 def __init__(self, parentui, path=None, create=0):
22 repo.repository.__init__(self)
22 repo.repository.__init__(self)
23 self.root = os.path.realpath(path)
23 self.root = os.path.realpath(path)
24 self.path = os.path.join(self.root, ".hg")
24 self.path = os.path.join(self.root, ".hg")
25 self.origroot = path
25 self.origroot = path
26 self.opener = util.opener(self.path)
26 self.opener = util.opener(self.path)
27 self.wopener = util.opener(self.root)
27 self.wopener = util.opener(self.root)
28
28
29 if not os.path.isdir(self.path):
29 if not os.path.isdir(self.path):
30 if create:
30 if create:
31 if not os.path.exists(path):
31 if not os.path.exists(path):
32 os.mkdir(path)
32 os.mkdir(path)
33 os.mkdir(self.path)
33 os.mkdir(self.path)
34 requirements = ["revlogv1"]
34 requirements = ["revlogv1"]
35 if parentui.configbool('format', 'usestore', True):
35 if parentui.configbool('format', 'usestore', True):
36 os.mkdir(os.path.join(self.path, "store"))
36 os.mkdir(os.path.join(self.path, "store"))
37 requirements.append("store")
37 requirements.append("store")
38 requirements.append("fncache")
38 # create an invalid changelog
39 # create an invalid changelog
39 self.opener("00changelog.i", "a").write(
40 self.opener("00changelog.i", "a").write(
40 '\0\0\0\2' # represents revlogv2
41 '\0\0\0\2' # represents revlogv2
41 ' dummy changelog to prevent using the old repo layout'
42 ' dummy changelog to prevent using the old repo layout'
42 )
43 )
43 reqfile = self.opener("requires", "w")
44 reqfile = self.opener("requires", "w")
44 for r in requirements:
45 for r in requirements:
45 reqfile.write("%s\n" % r)
46 reqfile.write("%s\n" % r)
46 reqfile.close()
47 reqfile.close()
47 else:
48 else:
48 raise repo.RepoError(_("repository %s not found") % path)
49 raise repo.RepoError(_("repository %s not found") % path)
49 elif create:
50 elif create:
50 raise repo.RepoError(_("repository %s already exists") % path)
51 raise repo.RepoError(_("repository %s already exists") % path)
51 else:
52 else:
52 # find requirements
53 # find requirements
53 requirements = []
54 requirements = []
54 try:
55 try:
55 requirements = self.opener("requires").read().splitlines()
56 requirements = self.opener("requires").read().splitlines()
56 for r in requirements:
57 for r in requirements:
57 if r not in self.supported:
58 if r not in self.supported:
58 raise repo.RepoError(_("requirement '%s' not supported") % r)
59 raise repo.RepoError(_("requirement '%s' not supported") % r)
59 except IOError, inst:
60 except IOError, inst:
60 if inst.errno != errno.ENOENT:
61 if inst.errno != errno.ENOENT:
61 raise
62 raise
62
63
63 self.store = store.store(requirements, self.path, util.opener)
64 self.store = store.store(requirements, self.path, util.opener)
64 self.spath = self.store.path
65 self.spath = self.store.path
65 self.sopener = self.store.opener
66 self.sopener = self.store.opener
66 self.sjoin = self.store.join
67 self.sjoin = self.store.join
67 self.opener.createmode = self.store.createmode
68 self.opener.createmode = self.store.createmode
68
69
69 self.ui = ui.ui(parentui=parentui)
70 self.ui = ui.ui(parentui=parentui)
70 try:
71 try:
71 self.ui.readconfig(self.join("hgrc"), self.root)
72 self.ui.readconfig(self.join("hgrc"), self.root)
72 extensions.loadall(self.ui)
73 extensions.loadall(self.ui)
73 except IOError:
74 except IOError:
74 pass
75 pass
75
76
76 self.tagscache = None
77 self.tagscache = None
77 self._tagstypecache = None
78 self._tagstypecache = None
78 self.branchcache = None
79 self.branchcache = None
79 self._ubranchcache = None # UTF-8 version of branchcache
80 self._ubranchcache = None # UTF-8 version of branchcache
80 self._branchcachetip = None
81 self._branchcachetip = None
81 self.nodetagscache = None
82 self.nodetagscache = None
82 self.filterpats = {}
83 self.filterpats = {}
83 self._datafilters = {}
84 self._datafilters = {}
84 self._transref = self._lockref = self._wlockref = None
85 self._transref = self._lockref = self._wlockref = None
85
86
86 def __getattr__(self, name):
87 def __getattr__(self, name):
87 if name == 'changelog':
88 if name == 'changelog':
88 self.changelog = changelog.changelog(self.sopener)
89 self.changelog = changelog.changelog(self.sopener)
89 self.sopener.defversion = self.changelog.version
90 self.sopener.defversion = self.changelog.version
90 return self.changelog
91 return self.changelog
91 if name == 'manifest':
92 if name == 'manifest':
92 self.changelog
93 self.changelog
93 self.manifest = manifest.manifest(self.sopener)
94 self.manifest = manifest.manifest(self.sopener)
94 return self.manifest
95 return self.manifest
95 if name == 'dirstate':
96 if name == 'dirstate':
96 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
97 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
97 return self.dirstate
98 return self.dirstate
98 else:
99 else:
99 raise AttributeError(name)
100 raise AttributeError(name)
100
101
101 def __getitem__(self, changeid):
102 def __getitem__(self, changeid):
102 if changeid == None:
103 if changeid == None:
103 return context.workingctx(self)
104 return context.workingctx(self)
104 return context.changectx(self, changeid)
105 return context.changectx(self, changeid)
105
106
106 def __nonzero__(self):
107 def __nonzero__(self):
107 return True
108 return True
108
109
109 def __len__(self):
110 def __len__(self):
110 return len(self.changelog)
111 return len(self.changelog)
111
112
112 def __iter__(self):
113 def __iter__(self):
113 for i in xrange(len(self)):
114 for i in xrange(len(self)):
114 yield i
115 yield i
115
116
116 def url(self):
117 def url(self):
117 return 'file:' + self.root
118 return 'file:' + self.root
118
119
119 def hook(self, name, throw=False, **args):
120 def hook(self, name, throw=False, **args):
120 return hook.hook(self.ui, self, name, throw, **args)
121 return hook.hook(self.ui, self, name, throw, **args)
121
122
122 tag_disallowed = ':\r\n'
123 tag_disallowed = ':\r\n'
123
124
124 def _tag(self, names, node, message, local, user, date, parent=None,
125 def _tag(self, names, node, message, local, user, date, parent=None,
125 extra={}):
126 extra={}):
126 use_dirstate = parent is None
127 use_dirstate = parent is None
127
128
128 if isinstance(names, str):
129 if isinstance(names, str):
129 allchars = names
130 allchars = names
130 names = (names,)
131 names = (names,)
131 else:
132 else:
132 allchars = ''.join(names)
133 allchars = ''.join(names)
133 for c in self.tag_disallowed:
134 for c in self.tag_disallowed:
134 if c in allchars:
135 if c in allchars:
135 raise util.Abort(_('%r cannot be used in a tag name') % c)
136 raise util.Abort(_('%r cannot be used in a tag name') % c)
136
137
137 for name in names:
138 for name in names:
138 self.hook('pretag', throw=True, node=hex(node), tag=name,
139 self.hook('pretag', throw=True, node=hex(node), tag=name,
139 local=local)
140 local=local)
140
141
141 def writetags(fp, names, munge, prevtags):
142 def writetags(fp, names, munge, prevtags):
142 fp.seek(0, 2)
143 fp.seek(0, 2)
143 if prevtags and prevtags[-1] != '\n':
144 if prevtags and prevtags[-1] != '\n':
144 fp.write('\n')
145 fp.write('\n')
145 for name in names:
146 for name in names:
146 m = munge and munge(name) or name
147 m = munge and munge(name) or name
147 if self._tagstypecache and name in self._tagstypecache:
148 if self._tagstypecache and name in self._tagstypecache:
148 old = self.tagscache.get(name, nullid)
149 old = self.tagscache.get(name, nullid)
149 fp.write('%s %s\n' % (hex(old), m))
150 fp.write('%s %s\n' % (hex(old), m))
150 fp.write('%s %s\n' % (hex(node), m))
151 fp.write('%s %s\n' % (hex(node), m))
151 fp.close()
152 fp.close()
152
153
153 prevtags = ''
154 prevtags = ''
154 if local:
155 if local:
155 try:
156 try:
156 fp = self.opener('localtags', 'r+')
157 fp = self.opener('localtags', 'r+')
157 except IOError, err:
158 except IOError, err:
158 fp = self.opener('localtags', 'a')
159 fp = self.opener('localtags', 'a')
159 else:
160 else:
160 prevtags = fp.read()
161 prevtags = fp.read()
161
162
162 # local tags are stored in the current charset
163 # local tags are stored in the current charset
163 writetags(fp, names, None, prevtags)
164 writetags(fp, names, None, prevtags)
164 for name in names:
165 for name in names:
165 self.hook('tag', node=hex(node), tag=name, local=local)
166 self.hook('tag', node=hex(node), tag=name, local=local)
166 return
167 return
167
168
168 if use_dirstate:
169 if use_dirstate:
169 try:
170 try:
170 fp = self.wfile('.hgtags', 'rb+')
171 fp = self.wfile('.hgtags', 'rb+')
171 except IOError, err:
172 except IOError, err:
172 fp = self.wfile('.hgtags', 'ab')
173 fp = self.wfile('.hgtags', 'ab')
173 else:
174 else:
174 prevtags = fp.read()
175 prevtags = fp.read()
175 else:
176 else:
176 try:
177 try:
177 prevtags = self.filectx('.hgtags', parent).data()
178 prevtags = self.filectx('.hgtags', parent).data()
178 except revlog.LookupError:
179 except revlog.LookupError:
179 pass
180 pass
180 fp = self.wfile('.hgtags', 'wb')
181 fp = self.wfile('.hgtags', 'wb')
181 if prevtags:
182 if prevtags:
182 fp.write(prevtags)
183 fp.write(prevtags)
183
184
184 # committed tags are stored in UTF-8
185 # committed tags are stored in UTF-8
185 writetags(fp, names, util.fromlocal, prevtags)
186 writetags(fp, names, util.fromlocal, prevtags)
186
187
187 if use_dirstate and '.hgtags' not in self.dirstate:
188 if use_dirstate and '.hgtags' not in self.dirstate:
188 self.add(['.hgtags'])
189 self.add(['.hgtags'])
189
190
190 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent,
191 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent,
191 extra=extra)
192 extra=extra)
192
193
193 for name in names:
194 for name in names:
194 self.hook('tag', node=hex(node), tag=name, local=local)
195 self.hook('tag', node=hex(node), tag=name, local=local)
195
196
196 return tagnode
197 return tagnode
197
198
198 def tag(self, names, node, message, local, user, date):
199 def tag(self, names, node, message, local, user, date):
199 '''tag a revision with one or more symbolic names.
200 '''tag a revision with one or more symbolic names.
200
201
201 names is a list of strings or, when adding a single tag, names may be a
202 names is a list of strings or, when adding a single tag, names may be a
202 string.
203 string.
203
204
204 if local is True, the tags are stored in a per-repository file.
205 if local is True, the tags are stored in a per-repository file.
205 otherwise, they are stored in the .hgtags file, and a new
206 otherwise, they are stored in the .hgtags file, and a new
206 changeset is committed with the change.
207 changeset is committed with the change.
207
208
208 keyword arguments:
209 keyword arguments:
209
210
210 local: whether to store tags in non-version-controlled file
211 local: whether to store tags in non-version-controlled file
211 (default False)
212 (default False)
212
213
213 message: commit message to use if committing
214 message: commit message to use if committing
214
215
215 user: name of user to use if committing
216 user: name of user to use if committing
216
217
217 date: date tuple to use if committing'''
218 date: date tuple to use if committing'''
218
219
219 for x in self.status()[:5]:
220 for x in self.status()[:5]:
220 if '.hgtags' in x:
221 if '.hgtags' in x:
221 raise util.Abort(_('working copy of .hgtags is changed '
222 raise util.Abort(_('working copy of .hgtags is changed '
222 '(please commit .hgtags manually)'))
223 '(please commit .hgtags manually)'))
223
224
224 self._tag(names, node, message, local, user, date)
225 self._tag(names, node, message, local, user, date)
225
226
226 def tags(self):
227 def tags(self):
227 '''return a mapping of tag to node'''
228 '''return a mapping of tag to node'''
228 if self.tagscache:
229 if self.tagscache:
229 return self.tagscache
230 return self.tagscache
230
231
231 globaltags = {}
232 globaltags = {}
232 tagtypes = {}
233 tagtypes = {}
233
234
234 def readtags(lines, fn, tagtype):
235 def readtags(lines, fn, tagtype):
235 filetags = {}
236 filetags = {}
236 count = 0
237 count = 0
237
238
238 def warn(msg):
239 def warn(msg):
239 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg))
240 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg))
240
241
241 for l in lines:
242 for l in lines:
242 count += 1
243 count += 1
243 if not l:
244 if not l:
244 continue
245 continue
245 s = l.split(" ", 1)
246 s = l.split(" ", 1)
246 if len(s) != 2:
247 if len(s) != 2:
247 warn(_("cannot parse entry"))
248 warn(_("cannot parse entry"))
248 continue
249 continue
249 node, key = s
250 node, key = s
250 key = util.tolocal(key.strip()) # stored in UTF-8
251 key = util.tolocal(key.strip()) # stored in UTF-8
251 try:
252 try:
252 bin_n = bin(node)
253 bin_n = bin(node)
253 except TypeError:
254 except TypeError:
254 warn(_("node '%s' is not well formed") % node)
255 warn(_("node '%s' is not well formed") % node)
255 continue
256 continue
256 if bin_n not in self.changelog.nodemap:
257 if bin_n not in self.changelog.nodemap:
257 warn(_("tag '%s' refers to unknown node") % key)
258 warn(_("tag '%s' refers to unknown node") % key)
258 continue
259 continue
259
260
260 h = []
261 h = []
261 if key in filetags:
262 if key in filetags:
262 n, h = filetags[key]
263 n, h = filetags[key]
263 h.append(n)
264 h.append(n)
264 filetags[key] = (bin_n, h)
265 filetags[key] = (bin_n, h)
265
266
266 for k, nh in filetags.items():
267 for k, nh in filetags.items():
267 if k not in globaltags:
268 if k not in globaltags:
268 globaltags[k] = nh
269 globaltags[k] = nh
269 tagtypes[k] = tagtype
270 tagtypes[k] = tagtype
270 continue
271 continue
271
272
272 # we prefer the global tag if:
273 # we prefer the global tag if:
273 # it supercedes us OR
274 # it supercedes us OR
274 # mutual supercedes and it has a higher rank
275 # mutual supercedes and it has a higher rank
275 # otherwise we win because we're tip-most
276 # otherwise we win because we're tip-most
276 an, ah = nh
277 an, ah = nh
277 bn, bh = globaltags[k]
278 bn, bh = globaltags[k]
278 if (bn != an and an in bh and
279 if (bn != an and an in bh and
279 (bn not in ah or len(bh) > len(ah))):
280 (bn not in ah or len(bh) > len(ah))):
280 an = bn
281 an = bn
281 ah.extend([n for n in bh if n not in ah])
282 ah.extend([n for n in bh if n not in ah])
282 globaltags[k] = an, ah
283 globaltags[k] = an, ah
283 tagtypes[k] = tagtype
284 tagtypes[k] = tagtype
284
285
285 # read the tags file from each head, ending with the tip
286 # read the tags file from each head, ending with the tip
286 f = None
287 f = None
287 for rev, node, fnode in self._hgtagsnodes():
288 for rev, node, fnode in self._hgtagsnodes():
288 f = (f and f.filectx(fnode) or
289 f = (f and f.filectx(fnode) or
289 self.filectx('.hgtags', fileid=fnode))
290 self.filectx('.hgtags', fileid=fnode))
290 readtags(f.data().splitlines(), f, "global")
291 readtags(f.data().splitlines(), f, "global")
291
292
292 try:
293 try:
293 data = util.fromlocal(self.opener("localtags").read())
294 data = util.fromlocal(self.opener("localtags").read())
294 # localtags are stored in the local character set
295 # localtags are stored in the local character set
295 # while the internal tag table is stored in UTF-8
296 # while the internal tag table is stored in UTF-8
296 readtags(data.splitlines(), "localtags", "local")
297 readtags(data.splitlines(), "localtags", "local")
297 except IOError:
298 except IOError:
298 pass
299 pass
299
300
300 self.tagscache = {}
301 self.tagscache = {}
301 self._tagstypecache = {}
302 self._tagstypecache = {}
302 for k,nh in globaltags.items():
303 for k,nh in globaltags.items():
303 n = nh[0]
304 n = nh[0]
304 if n != nullid:
305 if n != nullid:
305 self.tagscache[k] = n
306 self.tagscache[k] = n
306 self._tagstypecache[k] = tagtypes[k]
307 self._tagstypecache[k] = tagtypes[k]
307 self.tagscache['tip'] = self.changelog.tip()
308 self.tagscache['tip'] = self.changelog.tip()
308 return self.tagscache
309 return self.tagscache
309
310
310 def tagtype(self, tagname):
311 def tagtype(self, tagname):
311 '''
312 '''
312 return the type of the given tag. result can be:
313 return the type of the given tag. result can be:
313
314
314 'local' : a local tag
315 'local' : a local tag
315 'global' : a global tag
316 'global' : a global tag
316 None : tag does not exist
317 None : tag does not exist
317 '''
318 '''
318
319
319 self.tags()
320 self.tags()
320
321
321 return self._tagstypecache.get(tagname)
322 return self._tagstypecache.get(tagname)
322
323
323 def _hgtagsnodes(self):
324 def _hgtagsnodes(self):
324 heads = self.heads()
325 heads = self.heads()
325 heads.reverse()
326 heads.reverse()
326 last = {}
327 last = {}
327 ret = []
328 ret = []
328 for node in heads:
329 for node in heads:
329 c = self[node]
330 c = self[node]
330 rev = c.rev()
331 rev = c.rev()
331 try:
332 try:
332 fnode = c.filenode('.hgtags')
333 fnode = c.filenode('.hgtags')
333 except revlog.LookupError:
334 except revlog.LookupError:
334 continue
335 continue
335 ret.append((rev, node, fnode))
336 ret.append((rev, node, fnode))
336 if fnode in last:
337 if fnode in last:
337 ret[last[fnode]] = None
338 ret[last[fnode]] = None
338 last[fnode] = len(ret) - 1
339 last[fnode] = len(ret) - 1
339 return [item for item in ret if item]
340 return [item for item in ret if item]
340
341
341 def tagslist(self):
342 def tagslist(self):
342 '''return a list of tags ordered by revision'''
343 '''return a list of tags ordered by revision'''
343 l = []
344 l = []
344 for t, n in self.tags().items():
345 for t, n in self.tags().items():
345 try:
346 try:
346 r = self.changelog.rev(n)
347 r = self.changelog.rev(n)
347 except:
348 except:
348 r = -2 # sort to the beginning of the list if unknown
349 r = -2 # sort to the beginning of the list if unknown
349 l.append((r, t, n))
350 l.append((r, t, n))
350 return [(t, n) for r, t, n in util.sort(l)]
351 return [(t, n) for r, t, n in util.sort(l)]
351
352
352 def nodetags(self, node):
353 def nodetags(self, node):
353 '''return the tags associated with a node'''
354 '''return the tags associated with a node'''
354 if not self.nodetagscache:
355 if not self.nodetagscache:
355 self.nodetagscache = {}
356 self.nodetagscache = {}
356 for t, n in self.tags().items():
357 for t, n in self.tags().items():
357 self.nodetagscache.setdefault(n, []).append(t)
358 self.nodetagscache.setdefault(n, []).append(t)
358 return self.nodetagscache.get(node, [])
359 return self.nodetagscache.get(node, [])
359
360
360 def _branchtags(self, partial, lrev):
361 def _branchtags(self, partial, lrev):
361 tiprev = len(self) - 1
362 tiprev = len(self) - 1
362 if lrev != tiprev:
363 if lrev != tiprev:
363 self._updatebranchcache(partial, lrev+1, tiprev+1)
364 self._updatebranchcache(partial, lrev+1, tiprev+1)
364 self._writebranchcache(partial, self.changelog.tip(), tiprev)
365 self._writebranchcache(partial, self.changelog.tip(), tiprev)
365
366
366 return partial
367 return partial
367
368
368 def branchtags(self):
369 def branchtags(self):
369 tip = self.changelog.tip()
370 tip = self.changelog.tip()
370 if self.branchcache is not None and self._branchcachetip == tip:
371 if self.branchcache is not None and self._branchcachetip == tip:
371 return self.branchcache
372 return self.branchcache
372
373
373 oldtip = self._branchcachetip
374 oldtip = self._branchcachetip
374 self._branchcachetip = tip
375 self._branchcachetip = tip
375 if self.branchcache is None:
376 if self.branchcache is None:
376 self.branchcache = {} # avoid recursion in changectx
377 self.branchcache = {} # avoid recursion in changectx
377 else:
378 else:
378 self.branchcache.clear() # keep using the same dict
379 self.branchcache.clear() # keep using the same dict
379 if oldtip is None or oldtip not in self.changelog.nodemap:
380 if oldtip is None or oldtip not in self.changelog.nodemap:
380 partial, last, lrev = self._readbranchcache()
381 partial, last, lrev = self._readbranchcache()
381 else:
382 else:
382 lrev = self.changelog.rev(oldtip)
383 lrev = self.changelog.rev(oldtip)
383 partial = self._ubranchcache
384 partial = self._ubranchcache
384
385
385 self._branchtags(partial, lrev)
386 self._branchtags(partial, lrev)
386
387
387 # the branch cache is stored on disk as UTF-8, but in the local
388 # the branch cache is stored on disk as UTF-8, but in the local
388 # charset internally
389 # charset internally
389 for k, v in partial.items():
390 for k, v in partial.items():
390 self.branchcache[util.tolocal(k)] = v
391 self.branchcache[util.tolocal(k)] = v
391 self._ubranchcache = partial
392 self._ubranchcache = partial
392 return self.branchcache
393 return self.branchcache
393
394
394 def _readbranchcache(self):
395 def _readbranchcache(self):
395 partial = {}
396 partial = {}
396 try:
397 try:
397 f = self.opener("branch.cache")
398 f = self.opener("branch.cache")
398 lines = f.read().split('\n')
399 lines = f.read().split('\n')
399 f.close()
400 f.close()
400 except (IOError, OSError):
401 except (IOError, OSError):
401 return {}, nullid, nullrev
402 return {}, nullid, nullrev
402
403
403 try:
404 try:
404 last, lrev = lines.pop(0).split(" ", 1)
405 last, lrev = lines.pop(0).split(" ", 1)
405 last, lrev = bin(last), int(lrev)
406 last, lrev = bin(last), int(lrev)
406 if lrev >= len(self) or self[lrev].node() != last:
407 if lrev >= len(self) or self[lrev].node() != last:
407 # invalidate the cache
408 # invalidate the cache
408 raise ValueError('invalidating branch cache (tip differs)')
409 raise ValueError('invalidating branch cache (tip differs)')
409 for l in lines:
410 for l in lines:
410 if not l: continue
411 if not l: continue
411 node, label = l.split(" ", 1)
412 node, label = l.split(" ", 1)
412 partial[label.strip()] = bin(node)
413 partial[label.strip()] = bin(node)
413 except (KeyboardInterrupt, util.SignalInterrupt):
414 except (KeyboardInterrupt, util.SignalInterrupt):
414 raise
415 raise
415 except Exception, inst:
416 except Exception, inst:
416 if self.ui.debugflag:
417 if self.ui.debugflag:
417 self.ui.warn(str(inst), '\n')
418 self.ui.warn(str(inst), '\n')
418 partial, last, lrev = {}, nullid, nullrev
419 partial, last, lrev = {}, nullid, nullrev
419 return partial, last, lrev
420 return partial, last, lrev
420
421
421 def _writebranchcache(self, branches, tip, tiprev):
422 def _writebranchcache(self, branches, tip, tiprev):
422 try:
423 try:
423 f = self.opener("branch.cache", "w", atomictemp=True)
424 f = self.opener("branch.cache", "w", atomictemp=True)
424 f.write("%s %s\n" % (hex(tip), tiprev))
425 f.write("%s %s\n" % (hex(tip), tiprev))
425 for label, node in branches.iteritems():
426 for label, node in branches.iteritems():
426 f.write("%s %s\n" % (hex(node), label))
427 f.write("%s %s\n" % (hex(node), label))
427 f.rename()
428 f.rename()
428 except (IOError, OSError):
429 except (IOError, OSError):
429 pass
430 pass
430
431
431 def _updatebranchcache(self, partial, start, end):
432 def _updatebranchcache(self, partial, start, end):
432 for r in xrange(start, end):
433 for r in xrange(start, end):
433 c = self[r]
434 c = self[r]
434 b = c.branch()
435 b = c.branch()
435 partial[b] = c.node()
436 partial[b] = c.node()
436
437
437 def lookup(self, key):
438 def lookup(self, key):
438 if key == '.':
439 if key == '.':
439 return self.dirstate.parents()[0]
440 return self.dirstate.parents()[0]
440 elif key == 'null':
441 elif key == 'null':
441 return nullid
442 return nullid
442 n = self.changelog._match(key)
443 n = self.changelog._match(key)
443 if n:
444 if n:
444 return n
445 return n
445 if key in self.tags():
446 if key in self.tags():
446 return self.tags()[key]
447 return self.tags()[key]
447 if key in self.branchtags():
448 if key in self.branchtags():
448 return self.branchtags()[key]
449 return self.branchtags()[key]
449 n = self.changelog._partialmatch(key)
450 n = self.changelog._partialmatch(key)
450 if n:
451 if n:
451 return n
452 return n
452 try:
453 try:
453 if len(key) == 20:
454 if len(key) == 20:
454 key = hex(key)
455 key = hex(key)
455 except:
456 except:
456 pass
457 pass
457 raise repo.RepoError(_("unknown revision '%s'") % key)
458 raise repo.RepoError(_("unknown revision '%s'") % key)
458
459
459 def local(self):
460 def local(self):
460 return True
461 return True
461
462
462 def join(self, f):
463 def join(self, f):
463 return os.path.join(self.path, f)
464 return os.path.join(self.path, f)
464
465
465 def wjoin(self, f):
466 def wjoin(self, f):
466 return os.path.join(self.root, f)
467 return os.path.join(self.root, f)
467
468
468 def rjoin(self, f):
469 def rjoin(self, f):
469 return os.path.join(self.root, util.pconvert(f))
470 return os.path.join(self.root, util.pconvert(f))
470
471
471 def file(self, f):
472 def file(self, f):
472 if f[0] == '/':
473 if f[0] == '/':
473 f = f[1:]
474 f = f[1:]
474 return filelog.filelog(self.sopener, f)
475 return filelog.filelog(self.sopener, f)
475
476
476 def changectx(self, changeid):
477 def changectx(self, changeid):
477 return self[changeid]
478 return self[changeid]
478
479
479 def parents(self, changeid=None):
480 def parents(self, changeid=None):
480 '''get list of changectxs for parents of changeid'''
481 '''get list of changectxs for parents of changeid'''
481 return self[changeid].parents()
482 return self[changeid].parents()
482
483
483 def filectx(self, path, changeid=None, fileid=None):
484 def filectx(self, path, changeid=None, fileid=None):
484 """changeid can be a changeset revision, node, or tag.
485 """changeid can be a changeset revision, node, or tag.
485 fileid can be a file revision or node."""
486 fileid can be a file revision or node."""
486 return context.filectx(self, path, changeid, fileid)
487 return context.filectx(self, path, changeid, fileid)
487
488
488 def getcwd(self):
489 def getcwd(self):
489 return self.dirstate.getcwd()
490 return self.dirstate.getcwd()
490
491
491 def pathto(self, f, cwd=None):
492 def pathto(self, f, cwd=None):
492 return self.dirstate.pathto(f, cwd)
493 return self.dirstate.pathto(f, cwd)
493
494
494 def wfile(self, f, mode='r'):
495 def wfile(self, f, mode='r'):
495 return self.wopener(f, mode)
496 return self.wopener(f, mode)
496
497
497 def _link(self, f):
498 def _link(self, f):
498 return os.path.islink(self.wjoin(f))
499 return os.path.islink(self.wjoin(f))
499
500
500 def _filter(self, filter, filename, data):
501 def _filter(self, filter, filename, data):
501 if filter not in self.filterpats:
502 if filter not in self.filterpats:
502 l = []
503 l = []
503 for pat, cmd in self.ui.configitems(filter):
504 for pat, cmd in self.ui.configitems(filter):
504 if cmd == '!':
505 if cmd == '!':
505 continue
506 continue
506 mf = util.matcher(self.root, "", [pat], [], [])[1]
507 mf = util.matcher(self.root, "", [pat], [], [])[1]
507 fn = None
508 fn = None
508 params = cmd
509 params = cmd
509 for name, filterfn in self._datafilters.iteritems():
510 for name, filterfn in self._datafilters.iteritems():
510 if cmd.startswith(name):
511 if cmd.startswith(name):
511 fn = filterfn
512 fn = filterfn
512 params = cmd[len(name):].lstrip()
513 params = cmd[len(name):].lstrip()
513 break
514 break
514 if not fn:
515 if not fn:
515 fn = lambda s, c, **kwargs: util.filter(s, c)
516 fn = lambda s, c, **kwargs: util.filter(s, c)
516 # Wrap old filters not supporting keyword arguments
517 # Wrap old filters not supporting keyword arguments
517 if not inspect.getargspec(fn)[2]:
518 if not inspect.getargspec(fn)[2]:
518 oldfn = fn
519 oldfn = fn
519 fn = lambda s, c, **kwargs: oldfn(s, c)
520 fn = lambda s, c, **kwargs: oldfn(s, c)
520 l.append((mf, fn, params))
521 l.append((mf, fn, params))
521 self.filterpats[filter] = l
522 self.filterpats[filter] = l
522
523
523 for mf, fn, cmd in self.filterpats[filter]:
524 for mf, fn, cmd in self.filterpats[filter]:
524 if mf(filename):
525 if mf(filename):
525 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
526 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
526 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
527 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
527 break
528 break
528
529
529 return data
530 return data
530
531
531 def adddatafilter(self, name, filter):
532 def adddatafilter(self, name, filter):
532 self._datafilters[name] = filter
533 self._datafilters[name] = filter
533
534
534 def wread(self, filename):
535 def wread(self, filename):
535 if self._link(filename):
536 if self._link(filename):
536 data = os.readlink(self.wjoin(filename))
537 data = os.readlink(self.wjoin(filename))
537 else:
538 else:
538 data = self.wopener(filename, 'r').read()
539 data = self.wopener(filename, 'r').read()
539 return self._filter("encode", filename, data)
540 return self._filter("encode", filename, data)
540
541
541 def wwrite(self, filename, data, flags):
542 def wwrite(self, filename, data, flags):
542 data = self._filter("decode", filename, data)
543 data = self._filter("decode", filename, data)
543 try:
544 try:
544 os.unlink(self.wjoin(filename))
545 os.unlink(self.wjoin(filename))
545 except OSError:
546 except OSError:
546 pass
547 pass
547 if 'l' in flags:
548 if 'l' in flags:
548 self.wopener.symlink(data, filename)
549 self.wopener.symlink(data, filename)
549 else:
550 else:
550 self.wopener(filename, 'w').write(data)
551 self.wopener(filename, 'w').write(data)
551 if 'x' in flags:
552 if 'x' in flags:
552 util.set_flags(self.wjoin(filename), False, True)
553 util.set_flags(self.wjoin(filename), False, True)
553
554
554 def wwritedata(self, filename, data):
555 def wwritedata(self, filename, data):
555 return self._filter("decode", filename, data)
556 return self._filter("decode", filename, data)
556
557
557 def transaction(self):
558 def transaction(self):
558 if self._transref and self._transref():
559 if self._transref and self._transref():
559 return self._transref().nest()
560 return self._transref().nest()
560
561
561 # abort here if the journal already exists
562 # abort here if the journal already exists
562 if os.path.exists(self.sjoin("journal")):
563 if os.path.exists(self.sjoin("journal")):
563 raise repo.RepoError(_("journal already exists - run hg recover"))
564 raise repo.RepoError(_("journal already exists - run hg recover"))
564
565
565 # save dirstate for rollback
566 # save dirstate for rollback
566 try:
567 try:
567 ds = self.opener("dirstate").read()
568 ds = self.opener("dirstate").read()
568 except IOError:
569 except IOError:
569 ds = ""
570 ds = ""
570 self.opener("journal.dirstate", "w").write(ds)
571 self.opener("journal.dirstate", "w").write(ds)
571 self.opener("journal.branch", "w").write(self.dirstate.branch())
572 self.opener("journal.branch", "w").write(self.dirstate.branch())
572
573
573 renames = [(self.sjoin("journal"), self.sjoin("undo")),
574 renames = [(self.sjoin("journal"), self.sjoin("undo")),
574 (self.join("journal.dirstate"), self.join("undo.dirstate")),
575 (self.join("journal.dirstate"), self.join("undo.dirstate")),
575 (self.join("journal.branch"), self.join("undo.branch"))]
576 (self.join("journal.branch"), self.join("undo.branch"))]
576 tr = transaction.transaction(self.ui.warn, self.sopener,
577 tr = transaction.transaction(self.ui.warn, self.sopener,
577 self.sjoin("journal"),
578 self.sjoin("journal"),
578 aftertrans(renames),
579 aftertrans(renames),
579 self.store.createmode)
580 self.store.createmode)
580 self._transref = weakref.ref(tr)
581 self._transref = weakref.ref(tr)
581 return tr
582 return tr
582
583
583 def recover(self):
584 def recover(self):
584 l = self.lock()
585 l = self.lock()
585 try:
586 try:
586 if os.path.exists(self.sjoin("journal")):
587 if os.path.exists(self.sjoin("journal")):
587 self.ui.status(_("rolling back interrupted transaction\n"))
588 self.ui.status(_("rolling back interrupted transaction\n"))
588 transaction.rollback(self.sopener, self.sjoin("journal"))
589 transaction.rollback(self.sopener, self.sjoin("journal"))
589 self.invalidate()
590 self.invalidate()
590 return True
591 return True
591 else:
592 else:
592 self.ui.warn(_("no interrupted transaction available\n"))
593 self.ui.warn(_("no interrupted transaction available\n"))
593 return False
594 return False
594 finally:
595 finally:
595 del l
596 del l
596
597
597 def rollback(self):
598 def rollback(self):
598 wlock = lock = None
599 wlock = lock = None
599 try:
600 try:
600 wlock = self.wlock()
601 wlock = self.wlock()
601 lock = self.lock()
602 lock = self.lock()
602 if os.path.exists(self.sjoin("undo")):
603 if os.path.exists(self.sjoin("undo")):
603 self.ui.status(_("rolling back last transaction\n"))
604 self.ui.status(_("rolling back last transaction\n"))
604 transaction.rollback(self.sopener, self.sjoin("undo"))
605 transaction.rollback(self.sopener, self.sjoin("undo"))
605 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
606 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
606 try:
607 try:
607 branch = self.opener("undo.branch").read()
608 branch = self.opener("undo.branch").read()
608 self.dirstate.setbranch(branch)
609 self.dirstate.setbranch(branch)
609 except IOError:
610 except IOError:
610 self.ui.warn(_("Named branch could not be reset, "
611 self.ui.warn(_("Named branch could not be reset, "
611 "current branch still is: %s\n")
612 "current branch still is: %s\n")
612 % util.tolocal(self.dirstate.branch()))
613 % util.tolocal(self.dirstate.branch()))
613 self.invalidate()
614 self.invalidate()
614 self.dirstate.invalidate()
615 self.dirstate.invalidate()
615 else:
616 else:
616 self.ui.warn(_("no rollback information available\n"))
617 self.ui.warn(_("no rollback information available\n"))
617 finally:
618 finally:
618 del lock, wlock
619 del lock, wlock
619
620
620 def invalidate(self):
621 def invalidate(self):
621 for a in "changelog manifest".split():
622 for a in "changelog manifest".split():
622 if a in self.__dict__:
623 if a in self.__dict__:
623 delattr(self, a)
624 delattr(self, a)
624 self.tagscache = None
625 self.tagscache = None
625 self._tagstypecache = None
626 self._tagstypecache = None
626 self.nodetagscache = None
627 self.nodetagscache = None
627 self.branchcache = None
628 self.branchcache = None
628 self._ubranchcache = None
629 self._ubranchcache = None
629 self._branchcachetip = None
630 self._branchcachetip = None
630
631
631 def _lock(self, lockname, wait, releasefn, acquirefn, desc):
632 def _lock(self, lockname, wait, releasefn, acquirefn, desc):
632 try:
633 try:
633 l = lock.lock(lockname, 0, releasefn, desc=desc)
634 l = lock.lock(lockname, 0, releasefn, desc=desc)
634 except lock.LockHeld, inst:
635 except lock.LockHeld, inst:
635 if not wait:
636 if not wait:
636 raise
637 raise
637 self.ui.warn(_("waiting for lock on %s held by %r\n") %
638 self.ui.warn(_("waiting for lock on %s held by %r\n") %
638 (desc, inst.locker))
639 (desc, inst.locker))
639 # default to 600 seconds timeout
640 # default to 600 seconds timeout
640 l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")),
641 l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")),
641 releasefn, desc=desc)
642 releasefn, desc=desc)
642 if acquirefn:
643 if acquirefn:
643 acquirefn()
644 acquirefn()
644 return l
645 return l
645
646
646 def lock(self, wait=True):
647 def lock(self, wait=True):
647 if self._lockref and self._lockref():
648 if self._lockref and self._lockref():
648 return self._lockref()
649 return self._lockref()
649
650
650 l = self._lock(self.sjoin("lock"), wait, None, self.invalidate,
651 l = self._lock(self.sjoin("lock"), wait, None, self.invalidate,
651 _('repository %s') % self.origroot)
652 _('repository %s') % self.origroot)
652 self._lockref = weakref.ref(l)
653 self._lockref = weakref.ref(l)
653 return l
654 return l
654
655
655 def wlock(self, wait=True):
656 def wlock(self, wait=True):
656 if self._wlockref and self._wlockref():
657 if self._wlockref and self._wlockref():
657 return self._wlockref()
658 return self._wlockref()
658
659
659 l = self._lock(self.join("wlock"), wait, self.dirstate.write,
660 l = self._lock(self.join("wlock"), wait, self.dirstate.write,
660 self.dirstate.invalidate, _('working directory of %s') %
661 self.dirstate.invalidate, _('working directory of %s') %
661 self.origroot)
662 self.origroot)
662 self._wlockref = weakref.ref(l)
663 self._wlockref = weakref.ref(l)
663 return l
664 return l
664
665
665 def filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
666 def filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
666 """
667 """
667 commit an individual file as part of a larger transaction
668 commit an individual file as part of a larger transaction
668 """
669 """
669
670
670 fn = fctx.path()
671 fn = fctx.path()
671 t = fctx.data()
672 t = fctx.data()
672 fl = self.file(fn)
673 fl = self.file(fn)
673 fp1 = manifest1.get(fn, nullid)
674 fp1 = manifest1.get(fn, nullid)
674 fp2 = manifest2.get(fn, nullid)
675 fp2 = manifest2.get(fn, nullid)
675
676
676 meta = {}
677 meta = {}
677 cp = fctx.renamed()
678 cp = fctx.renamed()
678 if cp and cp[0] != fn:
679 if cp and cp[0] != fn:
679 # Mark the new revision of this file as a copy of another
680 # Mark the new revision of this file as a copy of another
680 # file. This copy data will effectively act as a parent
681 # file. This copy data will effectively act as a parent
681 # of this new revision. If this is a merge, the first
682 # of this new revision. If this is a merge, the first
682 # parent will be the nullid (meaning "look up the copy data")
683 # parent will be the nullid (meaning "look up the copy data")
683 # and the second one will be the other parent. For example:
684 # and the second one will be the other parent. For example:
684 #
685 #
685 # 0 --- 1 --- 3 rev1 changes file foo
686 # 0 --- 1 --- 3 rev1 changes file foo
686 # \ / rev2 renames foo to bar and changes it
687 # \ / rev2 renames foo to bar and changes it
687 # \- 2 -/ rev3 should have bar with all changes and
688 # \- 2 -/ rev3 should have bar with all changes and
688 # should record that bar descends from
689 # should record that bar descends from
689 # bar in rev2 and foo in rev1
690 # bar in rev2 and foo in rev1
690 #
691 #
691 # this allows this merge to succeed:
692 # this allows this merge to succeed:
692 #
693 #
693 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
694 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
694 # \ / merging rev3 and rev4 should use bar@rev2
695 # \ / merging rev3 and rev4 should use bar@rev2
695 # \- 2 --- 4 as the merge base
696 # \- 2 --- 4 as the merge base
696 #
697 #
697
698
698 cf = cp[0]
699 cf = cp[0]
699 cr = manifest1.get(cf)
700 cr = manifest1.get(cf)
700 nfp = fp2
701 nfp = fp2
701
702
702 if manifest2: # branch merge
703 if manifest2: # branch merge
703 if fp2 == nullid: # copied on remote side
704 if fp2 == nullid: # copied on remote side
704 if fp1 != nullid or cf in manifest2:
705 if fp1 != nullid or cf in manifest2:
705 cr = manifest2[cf]
706 cr = manifest2[cf]
706 nfp = fp1
707 nfp = fp1
707
708
708 # find source in nearest ancestor if we've lost track
709 # find source in nearest ancestor if we've lost track
709 if not cr:
710 if not cr:
710 self.ui.debug(_(" %s: searching for copy revision for %s\n") %
711 self.ui.debug(_(" %s: searching for copy revision for %s\n") %
711 (fn, cf))
712 (fn, cf))
712 for a in self['.'].ancestors():
713 for a in self['.'].ancestors():
713 if cf in a:
714 if cf in a:
714 cr = a[cf].filenode()
715 cr = a[cf].filenode()
715 break
716 break
716
717
717 self.ui.debug(_(" %s: copy %s:%s\n") % (fn, cf, hex(cr)))
718 self.ui.debug(_(" %s: copy %s:%s\n") % (fn, cf, hex(cr)))
718 meta["copy"] = cf
719 meta["copy"] = cf
719 meta["copyrev"] = hex(cr)
720 meta["copyrev"] = hex(cr)
720 fp1, fp2 = nullid, nfp
721 fp1, fp2 = nullid, nfp
721 elif fp2 != nullid:
722 elif fp2 != nullid:
722 # is one parent an ancestor of the other?
723 # is one parent an ancestor of the other?
723 fpa = fl.ancestor(fp1, fp2)
724 fpa = fl.ancestor(fp1, fp2)
724 if fpa == fp1:
725 if fpa == fp1:
725 fp1, fp2 = fp2, nullid
726 fp1, fp2 = fp2, nullid
726 elif fpa == fp2:
727 elif fpa == fp2:
727 fp2 = nullid
728 fp2 = nullid
728
729
729 # is the file unmodified from the parent? report existing entry
730 # is the file unmodified from the parent? report existing entry
730 if fp2 == nullid and not fl.cmp(fp1, t) and not meta:
731 if fp2 == nullid and not fl.cmp(fp1, t) and not meta:
731 return fp1
732 return fp1
732
733
733 changelist.append(fn)
734 changelist.append(fn)
734 return fl.add(t, meta, tr, linkrev, fp1, fp2)
735 return fl.add(t, meta, tr, linkrev, fp1, fp2)
735
736
736 def rawcommit(self, files, text, user, date, p1=None, p2=None, extra={}):
737 def rawcommit(self, files, text, user, date, p1=None, p2=None, extra={}):
737 if p1 is None:
738 if p1 is None:
738 p1, p2 = self.dirstate.parents()
739 p1, p2 = self.dirstate.parents()
739 return self.commit(files=files, text=text, user=user, date=date,
740 return self.commit(files=files, text=text, user=user, date=date,
740 p1=p1, p2=p2, extra=extra, empty_ok=True)
741 p1=p1, p2=p2, extra=extra, empty_ok=True)
741
742
742 def commit(self, files=None, text="", user=None, date=None,
743 def commit(self, files=None, text="", user=None, date=None,
743 match=None, force=False, force_editor=False,
744 match=None, force=False, force_editor=False,
744 p1=None, p2=None, extra={}, empty_ok=False):
745 p1=None, p2=None, extra={}, empty_ok=False):
745 wlock = lock = None
746 wlock = lock = None
746 if files:
747 if files:
747 files = util.unique(files)
748 files = util.unique(files)
748 try:
749 try:
749 wlock = self.wlock()
750 wlock = self.wlock()
750 lock = self.lock()
751 lock = self.lock()
751 use_dirstate = (p1 is None) # not rawcommit
752 use_dirstate = (p1 is None) # not rawcommit
752
753
753 if use_dirstate:
754 if use_dirstate:
754 p1, p2 = self.dirstate.parents()
755 p1, p2 = self.dirstate.parents()
755 update_dirstate = True
756 update_dirstate = True
756
757
757 if (not force and p2 != nullid and
758 if (not force and p2 != nullid and
758 (match and (match.files() or match.anypats()))):
759 (match and (match.files() or match.anypats()))):
759 raise util.Abort(_('cannot partially commit a merge '
760 raise util.Abort(_('cannot partially commit a merge '
760 '(do not specify files or patterns)'))
761 '(do not specify files or patterns)'))
761
762
762 if files:
763 if files:
763 modified, removed = [], []
764 modified, removed = [], []
764 for f in files:
765 for f in files:
765 s = self.dirstate[f]
766 s = self.dirstate[f]
766 if s in 'nma':
767 if s in 'nma':
767 modified.append(f)
768 modified.append(f)
768 elif s == 'r':
769 elif s == 'r':
769 removed.append(f)
770 removed.append(f)
770 else:
771 else:
771 self.ui.warn(_("%s not tracked!\n") % f)
772 self.ui.warn(_("%s not tracked!\n") % f)
772 changes = [modified, [], removed, [], []]
773 changes = [modified, [], removed, [], []]
773 else:
774 else:
774 changes = self.status(match=match)
775 changes = self.status(match=match)
775 else:
776 else:
776 p1, p2 = p1, p2 or nullid
777 p1, p2 = p1, p2 or nullid
777 update_dirstate = (self.dirstate.parents()[0] == p1)
778 update_dirstate = (self.dirstate.parents()[0] == p1)
778 changes = [files, [], [], [], []]
779 changes = [files, [], [], [], []]
779
780
780 ms = merge_.mergestate(self)
781 ms = merge_.mergestate(self)
781 for f in changes[0]:
782 for f in changes[0]:
782 if f in ms and ms[f] == 'u':
783 if f in ms and ms[f] == 'u':
783 raise util.Abort(_("unresolved merge conflicts "
784 raise util.Abort(_("unresolved merge conflicts "
784 "(see hg resolve)"))
785 "(see hg resolve)"))
785 wctx = context.workingctx(self, (p1, p2), text, user, date,
786 wctx = context.workingctx(self, (p1, p2), text, user, date,
786 extra, changes)
787 extra, changes)
787 return self._commitctx(wctx, force, force_editor, empty_ok,
788 return self._commitctx(wctx, force, force_editor, empty_ok,
788 use_dirstate, update_dirstate)
789 use_dirstate, update_dirstate)
789 finally:
790 finally:
790 del lock, wlock
791 del lock, wlock
791
792
792 def commitctx(self, ctx):
793 def commitctx(self, ctx):
793 """Add a new revision to current repository.
794 """Add a new revision to current repository.
794
795
795 Revision information is passed in the context.memctx argument.
796 Revision information is passed in the context.memctx argument.
796 commitctx() does not touch the working directory.
797 commitctx() does not touch the working directory.
797 """
798 """
798 wlock = lock = None
799 wlock = lock = None
799 try:
800 try:
800 wlock = self.wlock()
801 wlock = self.wlock()
801 lock = self.lock()
802 lock = self.lock()
802 return self._commitctx(ctx, force=True, force_editor=False,
803 return self._commitctx(ctx, force=True, force_editor=False,
803 empty_ok=True, use_dirstate=False,
804 empty_ok=True, use_dirstate=False,
804 update_dirstate=False)
805 update_dirstate=False)
805 finally:
806 finally:
806 del lock, wlock
807 del lock, wlock
807
808
808 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
809 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
809 use_dirstate=True, update_dirstate=True):
810 use_dirstate=True, update_dirstate=True):
810 tr = None
811 tr = None
811 valid = 0 # don't save the dirstate if this isn't set
812 valid = 0 # don't save the dirstate if this isn't set
812 try:
813 try:
813 commit = util.sort(wctx.modified() + wctx.added())
814 commit = util.sort(wctx.modified() + wctx.added())
814 remove = wctx.removed()
815 remove = wctx.removed()
815 extra = wctx.extra().copy()
816 extra = wctx.extra().copy()
816 branchname = extra['branch']
817 branchname = extra['branch']
817 user = wctx.user()
818 user = wctx.user()
818 text = wctx.description()
819 text = wctx.description()
819
820
820 p1, p2 = [p.node() for p in wctx.parents()]
821 p1, p2 = [p.node() for p in wctx.parents()]
821 c1 = self.changelog.read(p1)
822 c1 = self.changelog.read(p1)
822 c2 = self.changelog.read(p2)
823 c2 = self.changelog.read(p2)
823 m1 = self.manifest.read(c1[0]).copy()
824 m1 = self.manifest.read(c1[0]).copy()
824 m2 = self.manifest.read(c2[0])
825 m2 = self.manifest.read(c2[0])
825
826
826 if use_dirstate:
827 if use_dirstate:
827 oldname = c1[5].get("branch") # stored in UTF-8
828 oldname = c1[5].get("branch") # stored in UTF-8
828 if (not commit and not remove and not force and p2 == nullid
829 if (not commit and not remove and not force and p2 == nullid
829 and branchname == oldname):
830 and branchname == oldname):
830 self.ui.status(_("nothing changed\n"))
831 self.ui.status(_("nothing changed\n"))
831 return None
832 return None
832
833
833 xp1 = hex(p1)
834 xp1 = hex(p1)
834 if p2 == nullid: xp2 = ''
835 if p2 == nullid: xp2 = ''
835 else: xp2 = hex(p2)
836 else: xp2 = hex(p2)
836
837
837 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
838 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
838
839
839 tr = self.transaction()
840 tr = self.transaction()
840 trp = weakref.proxy(tr)
841 trp = weakref.proxy(tr)
841
842
842 # check in files
843 # check in files
843 new = {}
844 new = {}
844 changed = []
845 changed = []
845 linkrev = len(self)
846 linkrev = len(self)
846 for f in commit:
847 for f in commit:
847 self.ui.note(f + "\n")
848 self.ui.note(f + "\n")
848 try:
849 try:
849 fctx = wctx.filectx(f)
850 fctx = wctx.filectx(f)
850 newflags = fctx.flags()
851 newflags = fctx.flags()
851 new[f] = self.filecommit(fctx, m1, m2, linkrev, trp, changed)
852 new[f] = self.filecommit(fctx, m1, m2, linkrev, trp, changed)
852 if ((not changed or changed[-1] != f) and
853 if ((not changed or changed[-1] != f) and
853 m2.get(f) != new[f]):
854 m2.get(f) != new[f]):
854 # mention the file in the changelog if some
855 # mention the file in the changelog if some
855 # flag changed, even if there was no content
856 # flag changed, even if there was no content
856 # change.
857 # change.
857 if m1.flags(f) != newflags:
858 if m1.flags(f) != newflags:
858 changed.append(f)
859 changed.append(f)
859 m1.set(f, newflags)
860 m1.set(f, newflags)
860 if use_dirstate:
861 if use_dirstate:
861 self.dirstate.normal(f)
862 self.dirstate.normal(f)
862
863
863 except (OSError, IOError):
864 except (OSError, IOError):
864 if use_dirstate:
865 if use_dirstate:
865 self.ui.warn(_("trouble committing %s!\n") % f)
866 self.ui.warn(_("trouble committing %s!\n") % f)
866 raise
867 raise
867 else:
868 else:
868 remove.append(f)
869 remove.append(f)
869
870
870 updated, added = [], []
871 updated, added = [], []
871 for f in util.sort(changed):
872 for f in util.sort(changed):
872 if f in m1 or f in m2:
873 if f in m1 or f in m2:
873 updated.append(f)
874 updated.append(f)
874 else:
875 else:
875 added.append(f)
876 added.append(f)
876
877
877 # update manifest
878 # update manifest
878 m1.update(new)
879 m1.update(new)
879 removed = []
880 removed = []
880
881
881 for f in util.sort(remove):
882 for f in util.sort(remove):
882 if f in m1:
883 if f in m1:
883 del m1[f]
884 del m1[f]
884 removed.append(f)
885 removed.append(f)
885 elif f in m2:
886 elif f in m2:
886 removed.append(f)
887 removed.append(f)
887 mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0],
888 mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0],
888 (new, removed))
889 (new, removed))
889
890
890 # add changeset
891 # add changeset
891 if (not empty_ok and not text) or force_editor:
892 if (not empty_ok and not text) or force_editor:
892 edittext = []
893 edittext = []
893 if text:
894 if text:
894 edittext.append(text)
895 edittext.append(text)
895 edittext.append("")
896 edittext.append("")
896 edittext.append("") # Empty line between message and comments.
897 edittext.append("") # Empty line between message and comments.
897 edittext.append(_("HG: Enter commit message."
898 edittext.append(_("HG: Enter commit message."
898 " Lines beginning with 'HG:' are removed."))
899 " Lines beginning with 'HG:' are removed."))
899 edittext.append("HG: --")
900 edittext.append("HG: --")
900 edittext.append("HG: user: %s" % user)
901 edittext.append("HG: user: %s" % user)
901 if p2 != nullid:
902 if p2 != nullid:
902 edittext.append("HG: branch merge")
903 edittext.append("HG: branch merge")
903 if branchname:
904 if branchname:
904 edittext.append("HG: branch '%s'" % util.tolocal(branchname))
905 edittext.append("HG: branch '%s'" % util.tolocal(branchname))
905 edittext.extend(["HG: added %s" % f for f in added])
906 edittext.extend(["HG: added %s" % f for f in added])
906 edittext.extend(["HG: changed %s" % f for f in updated])
907 edittext.extend(["HG: changed %s" % f for f in updated])
907 edittext.extend(["HG: removed %s" % f for f in removed])
908 edittext.extend(["HG: removed %s" % f for f in removed])
908 if not added and not updated and not removed:
909 if not added and not updated and not removed:
909 edittext.append("HG: no files changed")
910 edittext.append("HG: no files changed")
910 edittext.append("")
911 edittext.append("")
911 # run editor in the repository root
912 # run editor in the repository root
912 olddir = os.getcwd()
913 olddir = os.getcwd()
913 os.chdir(self.root)
914 os.chdir(self.root)
914 text = self.ui.edit("\n".join(edittext), user)
915 text = self.ui.edit("\n".join(edittext), user)
915 os.chdir(olddir)
916 os.chdir(olddir)
916
917
917 lines = [line.rstrip() for line in text.rstrip().splitlines()]
918 lines = [line.rstrip() for line in text.rstrip().splitlines()]
918 while lines and not lines[0]:
919 while lines and not lines[0]:
919 del lines[0]
920 del lines[0]
920 if not lines and use_dirstate:
921 if not lines and use_dirstate:
921 raise util.Abort(_("empty commit message"))
922 raise util.Abort(_("empty commit message"))
922 text = '\n'.join(lines)
923 text = '\n'.join(lines)
923
924
924 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
925 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
925 user, wctx.date(), extra)
926 user, wctx.date(), extra)
926 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
927 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
927 parent2=xp2)
928 parent2=xp2)
928 tr.close()
929 tr.close()
929
930
930 if self.branchcache:
931 if self.branchcache:
931 self.branchtags()
932 self.branchtags()
932
933
933 if use_dirstate or update_dirstate:
934 if use_dirstate or update_dirstate:
934 self.dirstate.setparents(n)
935 self.dirstate.setparents(n)
935 if use_dirstate:
936 if use_dirstate:
936 for f in removed:
937 for f in removed:
937 self.dirstate.forget(f)
938 self.dirstate.forget(f)
938 valid = 1 # our dirstate updates are complete
939 valid = 1 # our dirstate updates are complete
939
940
940 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
941 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
941 return n
942 return n
942 finally:
943 finally:
943 if not valid: # don't save our updated dirstate
944 if not valid: # don't save our updated dirstate
944 self.dirstate.invalidate()
945 self.dirstate.invalidate()
945 del tr
946 del tr
946
947
947 def walk(self, match, node=None):
948 def walk(self, match, node=None):
948 '''
949 '''
949 walk recursively through the directory tree or a given
950 walk recursively through the directory tree or a given
950 changeset, finding all files matched by the match
951 changeset, finding all files matched by the match
951 function
952 function
952 '''
953 '''
953 return self[node].walk(match)
954 return self[node].walk(match)
954
955
955 def status(self, node1='.', node2=None, match=None,
956 def status(self, node1='.', node2=None, match=None,
956 ignored=False, clean=False, unknown=False):
957 ignored=False, clean=False, unknown=False):
957 """return status of files between two nodes or node and working directory
958 """return status of files between two nodes or node and working directory
958
959
959 If node1 is None, use the first dirstate parent instead.
960 If node1 is None, use the first dirstate parent instead.
960 If node2 is None, compare node1 with working directory.
961 If node2 is None, compare node1 with working directory.
961 """
962 """
962
963
963 def mfmatches(ctx):
964 def mfmatches(ctx):
964 mf = ctx.manifest().copy()
965 mf = ctx.manifest().copy()
965 for fn in mf.keys():
966 for fn in mf.keys():
966 if not match(fn):
967 if not match(fn):
967 del mf[fn]
968 del mf[fn]
968 return mf
969 return mf
969
970
970 if isinstance(node1, context.changectx):
971 if isinstance(node1, context.changectx):
971 ctx1 = node1
972 ctx1 = node1
972 else:
973 else:
973 ctx1 = self[node1]
974 ctx1 = self[node1]
974 if isinstance(node2, context.changectx):
975 if isinstance(node2, context.changectx):
975 ctx2 = node2
976 ctx2 = node2
976 else:
977 else:
977 ctx2 = self[node2]
978 ctx2 = self[node2]
978
979
979 working = ctx2 == self[None]
980 working = ctx2 == self[None]
980 parentworking = working and ctx1 == self['.']
981 parentworking = working and ctx1 == self['.']
981 match = match or match_.always(self.root, self.getcwd())
982 match = match or match_.always(self.root, self.getcwd())
982 listignored, listclean, listunknown = ignored, clean, unknown
983 listignored, listclean, listunknown = ignored, clean, unknown
983
984
984 # load earliest manifest first for caching reasons
985 # load earliest manifest first for caching reasons
985 if not working and ctx2.rev() < ctx1.rev():
986 if not working and ctx2.rev() < ctx1.rev():
986 ctx2.manifest()
987 ctx2.manifest()
987
988
988 if not parentworking:
989 if not parentworking:
989 def bad(f, msg):
990 def bad(f, msg):
990 if f not in ctx1:
991 if f not in ctx1:
991 self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg))
992 self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg))
992 return False
993 return False
993 match.bad = bad
994 match.bad = bad
994
995
995 if working: # we need to scan the working dir
996 if working: # we need to scan the working dir
996 s = self.dirstate.status(match, listignored, listclean, listunknown)
997 s = self.dirstate.status(match, listignored, listclean, listunknown)
997 cmp, modified, added, removed, deleted, unknown, ignored, clean = s
998 cmp, modified, added, removed, deleted, unknown, ignored, clean = s
998
999
999 # check for any possibly clean files
1000 # check for any possibly clean files
1000 if parentworking and cmp:
1001 if parentworking and cmp:
1001 fixup = []
1002 fixup = []
1002 # do a full compare of any files that might have changed
1003 # do a full compare of any files that might have changed
1003 for f in cmp:
1004 for f in cmp:
1004 if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
1005 if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
1005 or ctx1[f].cmp(ctx2[f].data())):
1006 or ctx1[f].cmp(ctx2[f].data())):
1006 modified.append(f)
1007 modified.append(f)
1007 else:
1008 else:
1008 fixup.append(f)
1009 fixup.append(f)
1009
1010
1010 if listclean:
1011 if listclean:
1011 clean += fixup
1012 clean += fixup
1012
1013
1013 # update dirstate for files that are actually clean
1014 # update dirstate for files that are actually clean
1014 if fixup:
1015 if fixup:
1015 wlock = None
1016 wlock = None
1016 try:
1017 try:
1017 try:
1018 try:
1018 wlock = self.wlock(False)
1019 wlock = self.wlock(False)
1019 for f in fixup:
1020 for f in fixup:
1020 self.dirstate.normal(f)
1021 self.dirstate.normal(f)
1021 except lock.LockException:
1022 except lock.LockException:
1022 pass
1023 pass
1023 finally:
1024 finally:
1024 del wlock
1025 del wlock
1025
1026
1026 if not parentworking:
1027 if not parentworking:
1027 mf1 = mfmatches(ctx1)
1028 mf1 = mfmatches(ctx1)
1028 if working:
1029 if working:
1029 # we are comparing working dir against non-parent
1030 # we are comparing working dir against non-parent
1030 # generate a pseudo-manifest for the working dir
1031 # generate a pseudo-manifest for the working dir
1031 mf2 = mfmatches(self['.'])
1032 mf2 = mfmatches(self['.'])
1032 for f in cmp + modified + added:
1033 for f in cmp + modified + added:
1033 mf2[f] = None
1034 mf2[f] = None
1034 mf2.set(f, ctx2.flags(f))
1035 mf2.set(f, ctx2.flags(f))
1035 for f in removed:
1036 for f in removed:
1036 if f in mf2:
1037 if f in mf2:
1037 del mf2[f]
1038 del mf2[f]
1038 else:
1039 else:
1039 # we are comparing two revisions
1040 # we are comparing two revisions
1040 deleted, unknown, ignored = [], [], []
1041 deleted, unknown, ignored = [], [], []
1041 mf2 = mfmatches(ctx2)
1042 mf2 = mfmatches(ctx2)
1042
1043
1043 modified, added, clean = [], [], []
1044 modified, added, clean = [], [], []
1044 for fn in mf2:
1045 for fn in mf2:
1045 if fn in mf1:
1046 if fn in mf1:
1046 if (mf1.flags(fn) != mf2.flags(fn) or
1047 if (mf1.flags(fn) != mf2.flags(fn) or
1047 (mf1[fn] != mf2[fn] and
1048 (mf1[fn] != mf2[fn] and
1048 (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))):
1049 (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))):
1049 modified.append(fn)
1050 modified.append(fn)
1050 elif listclean:
1051 elif listclean:
1051 clean.append(fn)
1052 clean.append(fn)
1052 del mf1[fn]
1053 del mf1[fn]
1053 else:
1054 else:
1054 added.append(fn)
1055 added.append(fn)
1055 removed = mf1.keys()
1056 removed = mf1.keys()
1056
1057
1057 r = modified, added, removed, deleted, unknown, ignored, clean
1058 r = modified, added, removed, deleted, unknown, ignored, clean
1058 [l.sort() for l in r]
1059 [l.sort() for l in r]
1059 return r
1060 return r
1060
1061
1061 def add(self, list):
1062 def add(self, list):
1062 wlock = self.wlock()
1063 wlock = self.wlock()
1063 try:
1064 try:
1064 rejected = []
1065 rejected = []
1065 for f in list:
1066 for f in list:
1066 p = self.wjoin(f)
1067 p = self.wjoin(f)
1067 try:
1068 try:
1068 st = os.lstat(p)
1069 st = os.lstat(p)
1069 except:
1070 except:
1070 self.ui.warn(_("%s does not exist!\n") % f)
1071 self.ui.warn(_("%s does not exist!\n") % f)
1071 rejected.append(f)
1072 rejected.append(f)
1072 continue
1073 continue
1073 if st.st_size > 10000000:
1074 if st.st_size > 10000000:
1074 self.ui.warn(_("%s: files over 10MB may cause memory and"
1075 self.ui.warn(_("%s: files over 10MB may cause memory and"
1075 " performance problems\n"
1076 " performance problems\n"
1076 "(use 'hg revert %s' to unadd the file)\n")
1077 "(use 'hg revert %s' to unadd the file)\n")
1077 % (f, f))
1078 % (f, f))
1078 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1079 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1079 self.ui.warn(_("%s not added: only files and symlinks "
1080 self.ui.warn(_("%s not added: only files and symlinks "
1080 "supported currently\n") % f)
1081 "supported currently\n") % f)
1081 rejected.append(p)
1082 rejected.append(p)
1082 elif self.dirstate[f] in 'amn':
1083 elif self.dirstate[f] in 'amn':
1083 self.ui.warn(_("%s already tracked!\n") % f)
1084 self.ui.warn(_("%s already tracked!\n") % f)
1084 elif self.dirstate[f] == 'r':
1085 elif self.dirstate[f] == 'r':
1085 self.dirstate.normallookup(f)
1086 self.dirstate.normallookup(f)
1086 else:
1087 else:
1087 self.dirstate.add(f)
1088 self.dirstate.add(f)
1088 return rejected
1089 return rejected
1089 finally:
1090 finally:
1090 del wlock
1091 del wlock
1091
1092
1092 def forget(self, list):
1093 def forget(self, list):
1093 wlock = self.wlock()
1094 wlock = self.wlock()
1094 try:
1095 try:
1095 for f in list:
1096 for f in list:
1096 if self.dirstate[f] != 'a':
1097 if self.dirstate[f] != 'a':
1097 self.ui.warn(_("%s not added!\n") % f)
1098 self.ui.warn(_("%s not added!\n") % f)
1098 else:
1099 else:
1099 self.dirstate.forget(f)
1100 self.dirstate.forget(f)
1100 finally:
1101 finally:
1101 del wlock
1102 del wlock
1102
1103
1103 def remove(self, list, unlink=False):
1104 def remove(self, list, unlink=False):
1104 wlock = None
1105 wlock = None
1105 try:
1106 try:
1106 if unlink:
1107 if unlink:
1107 for f in list:
1108 for f in list:
1108 try:
1109 try:
1109 util.unlink(self.wjoin(f))
1110 util.unlink(self.wjoin(f))
1110 except OSError, inst:
1111 except OSError, inst:
1111 if inst.errno != errno.ENOENT:
1112 if inst.errno != errno.ENOENT:
1112 raise
1113 raise
1113 wlock = self.wlock()
1114 wlock = self.wlock()
1114 for f in list:
1115 for f in list:
1115 if unlink and os.path.exists(self.wjoin(f)):
1116 if unlink and os.path.exists(self.wjoin(f)):
1116 self.ui.warn(_("%s still exists!\n") % f)
1117 self.ui.warn(_("%s still exists!\n") % f)
1117 elif self.dirstate[f] == 'a':
1118 elif self.dirstate[f] == 'a':
1118 self.dirstate.forget(f)
1119 self.dirstate.forget(f)
1119 elif f not in self.dirstate:
1120 elif f not in self.dirstate:
1120 self.ui.warn(_("%s not tracked!\n") % f)
1121 self.ui.warn(_("%s not tracked!\n") % f)
1121 else:
1122 else:
1122 self.dirstate.remove(f)
1123 self.dirstate.remove(f)
1123 finally:
1124 finally:
1124 del wlock
1125 del wlock
1125
1126
1126 def undelete(self, list):
1127 def undelete(self, list):
1127 wlock = None
1128 wlock = None
1128 try:
1129 try:
1129 manifests = [self.manifest.read(self.changelog.read(p)[0])
1130 manifests = [self.manifest.read(self.changelog.read(p)[0])
1130 for p in self.dirstate.parents() if p != nullid]
1131 for p in self.dirstate.parents() if p != nullid]
1131 wlock = self.wlock()
1132 wlock = self.wlock()
1132 for f in list:
1133 for f in list:
1133 if self.dirstate[f] != 'r':
1134 if self.dirstate[f] != 'r':
1134 self.ui.warn(_("%s not removed!\n") % f)
1135 self.ui.warn(_("%s not removed!\n") % f)
1135 else:
1136 else:
1136 m = f in manifests[0] and manifests[0] or manifests[1]
1137 m = f in manifests[0] and manifests[0] or manifests[1]
1137 t = self.file(f).read(m[f])
1138 t = self.file(f).read(m[f])
1138 self.wwrite(f, t, m.flags(f))
1139 self.wwrite(f, t, m.flags(f))
1139 self.dirstate.normal(f)
1140 self.dirstate.normal(f)
1140 finally:
1141 finally:
1141 del wlock
1142 del wlock
1142
1143
1143 def copy(self, source, dest):
1144 def copy(self, source, dest):
1144 wlock = None
1145 wlock = None
1145 try:
1146 try:
1146 p = self.wjoin(dest)
1147 p = self.wjoin(dest)
1147 if not (os.path.exists(p) or os.path.islink(p)):
1148 if not (os.path.exists(p) or os.path.islink(p)):
1148 self.ui.warn(_("%s does not exist!\n") % dest)
1149 self.ui.warn(_("%s does not exist!\n") % dest)
1149 elif not (os.path.isfile(p) or os.path.islink(p)):
1150 elif not (os.path.isfile(p) or os.path.islink(p)):
1150 self.ui.warn(_("copy failed: %s is not a file or a "
1151 self.ui.warn(_("copy failed: %s is not a file or a "
1151 "symbolic link\n") % dest)
1152 "symbolic link\n") % dest)
1152 else:
1153 else:
1153 wlock = self.wlock()
1154 wlock = self.wlock()
1154 if self.dirstate[dest] in '?r':
1155 if self.dirstate[dest] in '?r':
1155 self.dirstate.add(dest)
1156 self.dirstate.add(dest)
1156 self.dirstate.copy(source, dest)
1157 self.dirstate.copy(source, dest)
1157 finally:
1158 finally:
1158 del wlock
1159 del wlock
1159
1160
1160 def heads(self, start=None):
1161 def heads(self, start=None):
1161 heads = self.changelog.heads(start)
1162 heads = self.changelog.heads(start)
1162 # sort the output in rev descending order
1163 # sort the output in rev descending order
1163 heads = [(-self.changelog.rev(h), h) for h in heads]
1164 heads = [(-self.changelog.rev(h), h) for h in heads]
1164 return [n for (r, n) in util.sort(heads)]
1165 return [n for (r, n) in util.sort(heads)]
1165
1166
1166 def branchheads(self, branch=None, start=None):
1167 def branchheads(self, branch=None, start=None):
1167 if branch is None:
1168 if branch is None:
1168 branch = self[None].branch()
1169 branch = self[None].branch()
1169 branches = self.branchtags()
1170 branches = self.branchtags()
1170 if branch not in branches:
1171 if branch not in branches:
1171 return []
1172 return []
1172 # The basic algorithm is this:
1173 # The basic algorithm is this:
1173 #
1174 #
1174 # Start from the branch tip since there are no later revisions that can
1175 # Start from the branch tip since there are no later revisions that can
1175 # possibly be in this branch, and the tip is a guaranteed head.
1176 # possibly be in this branch, and the tip is a guaranteed head.
1176 #
1177 #
1177 # Remember the tip's parents as the first ancestors, since these by
1178 # Remember the tip's parents as the first ancestors, since these by
1178 # definition are not heads.
1179 # definition are not heads.
1179 #
1180 #
1180 # Step backwards from the brach tip through all the revisions. We are
1181 # Step backwards from the brach tip through all the revisions. We are
1181 # guaranteed by the rules of Mercurial that we will now be visiting the
1182 # guaranteed by the rules of Mercurial that we will now be visiting the
1182 # nodes in reverse topological order (children before parents).
1183 # nodes in reverse topological order (children before parents).
1183 #
1184 #
1184 # If a revision is one of the ancestors of a head then we can toss it
1185 # If a revision is one of the ancestors of a head then we can toss it
1185 # out of the ancestors set (we've already found it and won't be
1186 # out of the ancestors set (we've already found it and won't be
1186 # visiting it again) and put its parents in the ancestors set.
1187 # visiting it again) and put its parents in the ancestors set.
1187 #
1188 #
1188 # Otherwise, if a revision is in the branch it's another head, since it
1189 # Otherwise, if a revision is in the branch it's another head, since it
1189 # wasn't in the ancestor list of an existing head. So add it to the
1190 # wasn't in the ancestor list of an existing head. So add it to the
1190 # head list, and add its parents to the ancestor list.
1191 # head list, and add its parents to the ancestor list.
1191 #
1192 #
1192 # If it is not in the branch ignore it.
1193 # If it is not in the branch ignore it.
1193 #
1194 #
1194 # Once we have a list of heads, use nodesbetween to filter out all the
1195 # Once we have a list of heads, use nodesbetween to filter out all the
1195 # heads that cannot be reached from startrev. There may be a more
1196 # heads that cannot be reached from startrev. There may be a more
1196 # efficient way to do this as part of the previous algorithm.
1197 # efficient way to do this as part of the previous algorithm.
1197
1198
1198 set = util.set
1199 set = util.set
1199 heads = [self.changelog.rev(branches[branch])]
1200 heads = [self.changelog.rev(branches[branch])]
1200 # Don't care if ancestors contains nullrev or not.
1201 # Don't care if ancestors contains nullrev or not.
1201 ancestors = set(self.changelog.parentrevs(heads[0]))
1202 ancestors = set(self.changelog.parentrevs(heads[0]))
1202 for rev in xrange(heads[0] - 1, nullrev, -1):
1203 for rev in xrange(heads[0] - 1, nullrev, -1):
1203 if rev in ancestors:
1204 if rev in ancestors:
1204 ancestors.update(self.changelog.parentrevs(rev))
1205 ancestors.update(self.changelog.parentrevs(rev))
1205 ancestors.remove(rev)
1206 ancestors.remove(rev)
1206 elif self[rev].branch() == branch:
1207 elif self[rev].branch() == branch:
1207 heads.append(rev)
1208 heads.append(rev)
1208 ancestors.update(self.changelog.parentrevs(rev))
1209 ancestors.update(self.changelog.parentrevs(rev))
1209 heads = [self.changelog.node(rev) for rev in heads]
1210 heads = [self.changelog.node(rev) for rev in heads]
1210 if start is not None:
1211 if start is not None:
1211 heads = self.changelog.nodesbetween([start], heads)[2]
1212 heads = self.changelog.nodesbetween([start], heads)[2]
1212 return heads
1213 return heads
1213
1214
1214 def branches(self, nodes):
1215 def branches(self, nodes):
1215 if not nodes:
1216 if not nodes:
1216 nodes = [self.changelog.tip()]
1217 nodes = [self.changelog.tip()]
1217 b = []
1218 b = []
1218 for n in nodes:
1219 for n in nodes:
1219 t = n
1220 t = n
1220 while 1:
1221 while 1:
1221 p = self.changelog.parents(n)
1222 p = self.changelog.parents(n)
1222 if p[1] != nullid or p[0] == nullid:
1223 if p[1] != nullid or p[0] == nullid:
1223 b.append((t, n, p[0], p[1]))
1224 b.append((t, n, p[0], p[1]))
1224 break
1225 break
1225 n = p[0]
1226 n = p[0]
1226 return b
1227 return b
1227
1228
1228 def between(self, pairs):
1229 def between(self, pairs):
1229 r = []
1230 r = []
1230
1231
1231 for top, bottom in pairs:
1232 for top, bottom in pairs:
1232 n, l, i = top, [], 0
1233 n, l, i = top, [], 0
1233 f = 1
1234 f = 1
1234
1235
1235 while n != bottom:
1236 while n != bottom:
1236 p = self.changelog.parents(n)[0]
1237 p = self.changelog.parents(n)[0]
1237 if i == f:
1238 if i == f:
1238 l.append(n)
1239 l.append(n)
1239 f = f * 2
1240 f = f * 2
1240 n = p
1241 n = p
1241 i += 1
1242 i += 1
1242
1243
1243 r.append(l)
1244 r.append(l)
1244
1245
1245 return r
1246 return r
1246
1247
1247 def findincoming(self, remote, base=None, heads=None, force=False):
1248 def findincoming(self, remote, base=None, heads=None, force=False):
1248 """Return list of roots of the subsets of missing nodes from remote
1249 """Return list of roots of the subsets of missing nodes from remote
1249
1250
1250 If base dict is specified, assume that these nodes and their parents
1251 If base dict is specified, assume that these nodes and their parents
1251 exist on the remote side and that no child of a node of base exists
1252 exist on the remote side and that no child of a node of base exists
1252 in both remote and self.
1253 in both remote and self.
1253 Furthermore base will be updated to include the nodes that exists
1254 Furthermore base will be updated to include the nodes that exists
1254 in self and remote but no children exists in self and remote.
1255 in self and remote but no children exists in self and remote.
1255 If a list of heads is specified, return only nodes which are heads
1256 If a list of heads is specified, return only nodes which are heads
1256 or ancestors of these heads.
1257 or ancestors of these heads.
1257
1258
1258 All the ancestors of base are in self and in remote.
1259 All the ancestors of base are in self and in remote.
1259 All the descendants of the list returned are missing in self.
1260 All the descendants of the list returned are missing in self.
1260 (and so we know that the rest of the nodes are missing in remote, see
1261 (and so we know that the rest of the nodes are missing in remote, see
1261 outgoing)
1262 outgoing)
1262 """
1263 """
1263 m = self.changelog.nodemap
1264 m = self.changelog.nodemap
1264 search = []
1265 search = []
1265 fetch = {}
1266 fetch = {}
1266 seen = {}
1267 seen = {}
1267 seenbranch = {}
1268 seenbranch = {}
1268 if base == None:
1269 if base == None:
1269 base = {}
1270 base = {}
1270
1271
1271 if not heads:
1272 if not heads:
1272 heads = remote.heads()
1273 heads = remote.heads()
1273
1274
1274 if self.changelog.tip() == nullid:
1275 if self.changelog.tip() == nullid:
1275 base[nullid] = 1
1276 base[nullid] = 1
1276 if heads != [nullid]:
1277 if heads != [nullid]:
1277 return [nullid]
1278 return [nullid]
1278 return []
1279 return []
1279
1280
1280 # assume we're closer to the tip than the root
1281 # assume we're closer to the tip than the root
1281 # and start by examining the heads
1282 # and start by examining the heads
1282 self.ui.status(_("searching for changes\n"))
1283 self.ui.status(_("searching for changes\n"))
1283
1284
1284 unknown = []
1285 unknown = []
1285 for h in heads:
1286 for h in heads:
1286 if h not in m:
1287 if h not in m:
1287 unknown.append(h)
1288 unknown.append(h)
1288 else:
1289 else:
1289 base[h] = 1
1290 base[h] = 1
1290
1291
1291 if not unknown:
1292 if not unknown:
1292 return []
1293 return []
1293
1294
1294 req = dict.fromkeys(unknown)
1295 req = dict.fromkeys(unknown)
1295 reqcnt = 0
1296 reqcnt = 0
1296
1297
1297 # search through remote branches
1298 # search through remote branches
1298 # a 'branch' here is a linear segment of history, with four parts:
1299 # a 'branch' here is a linear segment of history, with four parts:
1299 # head, root, first parent, second parent
1300 # head, root, first parent, second parent
1300 # (a branch always has two parents (or none) by definition)
1301 # (a branch always has two parents (or none) by definition)
1301 unknown = remote.branches(unknown)
1302 unknown = remote.branches(unknown)
1302 while unknown:
1303 while unknown:
1303 r = []
1304 r = []
1304 while unknown:
1305 while unknown:
1305 n = unknown.pop(0)
1306 n = unknown.pop(0)
1306 if n[0] in seen:
1307 if n[0] in seen:
1307 continue
1308 continue
1308
1309
1309 self.ui.debug(_("examining %s:%s\n")
1310 self.ui.debug(_("examining %s:%s\n")
1310 % (short(n[0]), short(n[1])))
1311 % (short(n[0]), short(n[1])))
1311 if n[0] == nullid: # found the end of the branch
1312 if n[0] == nullid: # found the end of the branch
1312 pass
1313 pass
1313 elif n in seenbranch:
1314 elif n in seenbranch:
1314 self.ui.debug(_("branch already found\n"))
1315 self.ui.debug(_("branch already found\n"))
1315 continue
1316 continue
1316 elif n[1] and n[1] in m: # do we know the base?
1317 elif n[1] and n[1] in m: # do we know the base?
1317 self.ui.debug(_("found incomplete branch %s:%s\n")
1318 self.ui.debug(_("found incomplete branch %s:%s\n")
1318 % (short(n[0]), short(n[1])))
1319 % (short(n[0]), short(n[1])))
1319 search.append(n) # schedule branch range for scanning
1320 search.append(n) # schedule branch range for scanning
1320 seenbranch[n] = 1
1321 seenbranch[n] = 1
1321 else:
1322 else:
1322 if n[1] not in seen and n[1] not in fetch:
1323 if n[1] not in seen and n[1] not in fetch:
1323 if n[2] in m and n[3] in m:
1324 if n[2] in m and n[3] in m:
1324 self.ui.debug(_("found new changeset %s\n") %
1325 self.ui.debug(_("found new changeset %s\n") %
1325 short(n[1]))
1326 short(n[1]))
1326 fetch[n[1]] = 1 # earliest unknown
1327 fetch[n[1]] = 1 # earliest unknown
1327 for p in n[2:4]:
1328 for p in n[2:4]:
1328 if p in m:
1329 if p in m:
1329 base[p] = 1 # latest known
1330 base[p] = 1 # latest known
1330
1331
1331 for p in n[2:4]:
1332 for p in n[2:4]:
1332 if p not in req and p not in m:
1333 if p not in req and p not in m:
1333 r.append(p)
1334 r.append(p)
1334 req[p] = 1
1335 req[p] = 1
1335 seen[n[0]] = 1
1336 seen[n[0]] = 1
1336
1337
1337 if r:
1338 if r:
1338 reqcnt += 1
1339 reqcnt += 1
1339 self.ui.debug(_("request %d: %s\n") %
1340 self.ui.debug(_("request %d: %s\n") %
1340 (reqcnt, " ".join(map(short, r))))
1341 (reqcnt, " ".join(map(short, r))))
1341 for p in xrange(0, len(r), 10):
1342 for p in xrange(0, len(r), 10):
1342 for b in remote.branches(r[p:p+10]):
1343 for b in remote.branches(r[p:p+10]):
1343 self.ui.debug(_("received %s:%s\n") %
1344 self.ui.debug(_("received %s:%s\n") %
1344 (short(b[0]), short(b[1])))
1345 (short(b[0]), short(b[1])))
1345 unknown.append(b)
1346 unknown.append(b)
1346
1347
1347 # do binary search on the branches we found
1348 # do binary search on the branches we found
1348 search = [(t, b) for (t, b, p1, p2) in search]
1349 search = [(t, b) for (t, b, p1, p2) in search]
1349 while search:
1350 while search:
1350 newsearch = []
1351 newsearch = []
1351 reqcnt += 1
1352 reqcnt += 1
1352 for n, l in zip(search, remote.between(search)):
1353 for n, l in zip(search, remote.between(search)):
1353 l.append(n[1])
1354 l.append(n[1])
1354 p = n[0]
1355 p = n[0]
1355 f = 1
1356 f = 1
1356 for i in l:
1357 for i in l:
1357 self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i)))
1358 self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i)))
1358 if i in m:
1359 if i in m:
1359 if f <= 2:
1360 if f <= 2:
1360 self.ui.debug(_("found new branch changeset %s\n") %
1361 self.ui.debug(_("found new branch changeset %s\n") %
1361 short(p))
1362 short(p))
1362 fetch[p] = 1
1363 fetch[p] = 1
1363 base[i] = 1
1364 base[i] = 1
1364 else:
1365 else:
1365 self.ui.debug(_("narrowed branch search to %s:%s\n")
1366 self.ui.debug(_("narrowed branch search to %s:%s\n")
1366 % (short(p), short(i)))
1367 % (short(p), short(i)))
1367 newsearch.append((p, i))
1368 newsearch.append((p, i))
1368 break
1369 break
1369 p, f = i, f * 2
1370 p, f = i, f * 2
1370 search = newsearch
1371 search = newsearch
1371
1372
1372 # sanity check our fetch list
1373 # sanity check our fetch list
1373 for f in fetch.keys():
1374 for f in fetch.keys():
1374 if f in m:
1375 if f in m:
1375 raise repo.RepoError(_("already have changeset ") + short(f[:4]))
1376 raise repo.RepoError(_("already have changeset ") + short(f[:4]))
1376
1377
1377 if base.keys() == [nullid]:
1378 if base.keys() == [nullid]:
1378 if force:
1379 if force:
1379 self.ui.warn(_("warning: repository is unrelated\n"))
1380 self.ui.warn(_("warning: repository is unrelated\n"))
1380 else:
1381 else:
1381 raise util.Abort(_("repository is unrelated"))
1382 raise util.Abort(_("repository is unrelated"))
1382
1383
1383 self.ui.debug(_("found new changesets starting at ") +
1384 self.ui.debug(_("found new changesets starting at ") +
1384 " ".join([short(f) for f in fetch]) + "\n")
1385 " ".join([short(f) for f in fetch]) + "\n")
1385
1386
1386 self.ui.debug(_("%d total queries\n") % reqcnt)
1387 self.ui.debug(_("%d total queries\n") % reqcnt)
1387
1388
1388 return fetch.keys()
1389 return fetch.keys()
1389
1390
1390 def findoutgoing(self, remote, base=None, heads=None, force=False):
1391 def findoutgoing(self, remote, base=None, heads=None, force=False):
1391 """Return list of nodes that are roots of subsets not in remote
1392 """Return list of nodes that are roots of subsets not in remote
1392
1393
1393 If base dict is specified, assume that these nodes and their parents
1394 If base dict is specified, assume that these nodes and their parents
1394 exist on the remote side.
1395 exist on the remote side.
1395 If a list of heads is specified, return only nodes which are heads
1396 If a list of heads is specified, return only nodes which are heads
1396 or ancestors of these heads, and return a second element which
1397 or ancestors of these heads, and return a second element which
1397 contains all remote heads which get new children.
1398 contains all remote heads which get new children.
1398 """
1399 """
1399 if base == None:
1400 if base == None:
1400 base = {}
1401 base = {}
1401 self.findincoming(remote, base, heads, force=force)
1402 self.findincoming(remote, base, heads, force=force)
1402
1403
1403 self.ui.debug(_("common changesets up to ")
1404 self.ui.debug(_("common changesets up to ")
1404 + " ".join(map(short, base.keys())) + "\n")
1405 + " ".join(map(short, base.keys())) + "\n")
1405
1406
1406 remain = dict.fromkeys(self.changelog.nodemap)
1407 remain = dict.fromkeys(self.changelog.nodemap)
1407
1408
1408 # prune everything remote has from the tree
1409 # prune everything remote has from the tree
1409 del remain[nullid]
1410 del remain[nullid]
1410 remove = base.keys()
1411 remove = base.keys()
1411 while remove:
1412 while remove:
1412 n = remove.pop(0)
1413 n = remove.pop(0)
1413 if n in remain:
1414 if n in remain:
1414 del remain[n]
1415 del remain[n]
1415 for p in self.changelog.parents(n):
1416 for p in self.changelog.parents(n):
1416 remove.append(p)
1417 remove.append(p)
1417
1418
1418 # find every node whose parents have been pruned
1419 # find every node whose parents have been pruned
1419 subset = []
1420 subset = []
1420 # find every remote head that will get new children
1421 # find every remote head that will get new children
1421 updated_heads = {}
1422 updated_heads = {}
1422 for n in remain:
1423 for n in remain:
1423 p1, p2 = self.changelog.parents(n)
1424 p1, p2 = self.changelog.parents(n)
1424 if p1 not in remain and p2 not in remain:
1425 if p1 not in remain and p2 not in remain:
1425 subset.append(n)
1426 subset.append(n)
1426 if heads:
1427 if heads:
1427 if p1 in heads:
1428 if p1 in heads:
1428 updated_heads[p1] = True
1429 updated_heads[p1] = True
1429 if p2 in heads:
1430 if p2 in heads:
1430 updated_heads[p2] = True
1431 updated_heads[p2] = True
1431
1432
1432 # this is the set of all roots we have to push
1433 # this is the set of all roots we have to push
1433 if heads:
1434 if heads:
1434 return subset, updated_heads.keys()
1435 return subset, updated_heads.keys()
1435 else:
1436 else:
1436 return subset
1437 return subset
1437
1438
1438 def pull(self, remote, heads=None, force=False):
1439 def pull(self, remote, heads=None, force=False):
1439 lock = self.lock()
1440 lock = self.lock()
1440 try:
1441 try:
1441 fetch = self.findincoming(remote, heads=heads, force=force)
1442 fetch = self.findincoming(remote, heads=heads, force=force)
1442 if fetch == [nullid]:
1443 if fetch == [nullid]:
1443 self.ui.status(_("requesting all changes\n"))
1444 self.ui.status(_("requesting all changes\n"))
1444
1445
1445 if not fetch:
1446 if not fetch:
1446 self.ui.status(_("no changes found\n"))
1447 self.ui.status(_("no changes found\n"))
1447 return 0
1448 return 0
1448
1449
1449 if heads is None:
1450 if heads is None:
1450 cg = remote.changegroup(fetch, 'pull')
1451 cg = remote.changegroup(fetch, 'pull')
1451 else:
1452 else:
1452 if 'changegroupsubset' not in remote.capabilities:
1453 if 'changegroupsubset' not in remote.capabilities:
1453 raise util.Abort(_("Partial pull cannot be done because other repository doesn't support changegroupsubset."))
1454 raise util.Abort(_("Partial pull cannot be done because other repository doesn't support changegroupsubset."))
1454 cg = remote.changegroupsubset(fetch, heads, 'pull')
1455 cg = remote.changegroupsubset(fetch, heads, 'pull')
1455 return self.addchangegroup(cg, 'pull', remote.url())
1456 return self.addchangegroup(cg, 'pull', remote.url())
1456 finally:
1457 finally:
1457 del lock
1458 del lock
1458
1459
1459 def push(self, remote, force=False, revs=None):
1460 def push(self, remote, force=False, revs=None):
1460 # there are two ways to push to remote repo:
1461 # there are two ways to push to remote repo:
1461 #
1462 #
1462 # addchangegroup assumes local user can lock remote
1463 # addchangegroup assumes local user can lock remote
1463 # repo (local filesystem, old ssh servers).
1464 # repo (local filesystem, old ssh servers).
1464 #
1465 #
1465 # unbundle assumes local user cannot lock remote repo (new ssh
1466 # unbundle assumes local user cannot lock remote repo (new ssh
1466 # servers, http servers).
1467 # servers, http servers).
1467
1468
1468 if remote.capable('unbundle'):
1469 if remote.capable('unbundle'):
1469 return self.push_unbundle(remote, force, revs)
1470 return self.push_unbundle(remote, force, revs)
1470 return self.push_addchangegroup(remote, force, revs)
1471 return self.push_addchangegroup(remote, force, revs)
1471
1472
1472 def prepush(self, remote, force, revs):
1473 def prepush(self, remote, force, revs):
1473 base = {}
1474 base = {}
1474 remote_heads = remote.heads()
1475 remote_heads = remote.heads()
1475 inc = self.findincoming(remote, base, remote_heads, force=force)
1476 inc = self.findincoming(remote, base, remote_heads, force=force)
1476
1477
1477 update, updated_heads = self.findoutgoing(remote, base, remote_heads)
1478 update, updated_heads = self.findoutgoing(remote, base, remote_heads)
1478 if revs is not None:
1479 if revs is not None:
1479 msng_cl, bases, heads = self.changelog.nodesbetween(update, revs)
1480 msng_cl, bases, heads = self.changelog.nodesbetween(update, revs)
1480 else:
1481 else:
1481 bases, heads = update, self.changelog.heads()
1482 bases, heads = update, self.changelog.heads()
1482
1483
1483 if not bases:
1484 if not bases:
1484 self.ui.status(_("no changes found\n"))
1485 self.ui.status(_("no changes found\n"))
1485 return None, 1
1486 return None, 1
1486 elif not force:
1487 elif not force:
1487 # check if we're creating new remote heads
1488 # check if we're creating new remote heads
1488 # to be a remote head after push, node must be either
1489 # to be a remote head after push, node must be either
1489 # - unknown locally
1490 # - unknown locally
1490 # - a local outgoing head descended from update
1491 # - a local outgoing head descended from update
1491 # - a remote head that's known locally and not
1492 # - a remote head that's known locally and not
1492 # ancestral to an outgoing head
1493 # ancestral to an outgoing head
1493
1494
1494 warn = 0
1495 warn = 0
1495
1496
1496 if remote_heads == [nullid]:
1497 if remote_heads == [nullid]:
1497 warn = 0
1498 warn = 0
1498 elif not revs and len(heads) > len(remote_heads):
1499 elif not revs and len(heads) > len(remote_heads):
1499 warn = 1
1500 warn = 1
1500 else:
1501 else:
1501 newheads = list(heads)
1502 newheads = list(heads)
1502 for r in remote_heads:
1503 for r in remote_heads:
1503 if r in self.changelog.nodemap:
1504 if r in self.changelog.nodemap:
1504 desc = self.changelog.heads(r, heads)
1505 desc = self.changelog.heads(r, heads)
1505 l = [h for h in heads if h in desc]
1506 l = [h for h in heads if h in desc]
1506 if not l:
1507 if not l:
1507 newheads.append(r)
1508 newheads.append(r)
1508 else:
1509 else:
1509 newheads.append(r)
1510 newheads.append(r)
1510 if len(newheads) > len(remote_heads):
1511 if len(newheads) > len(remote_heads):
1511 warn = 1
1512 warn = 1
1512
1513
1513 if warn:
1514 if warn:
1514 self.ui.warn(_("abort: push creates new remote heads!\n"))
1515 self.ui.warn(_("abort: push creates new remote heads!\n"))
1515 self.ui.status(_("(did you forget to merge?"
1516 self.ui.status(_("(did you forget to merge?"
1516 " use push -f to force)\n"))
1517 " use push -f to force)\n"))
1517 return None, 0
1518 return None, 0
1518 elif inc:
1519 elif inc:
1519 self.ui.warn(_("note: unsynced remote changes!\n"))
1520 self.ui.warn(_("note: unsynced remote changes!\n"))
1520
1521
1521
1522
1522 if revs is None:
1523 if revs is None:
1523 cg = self.changegroup(update, 'push')
1524 cg = self.changegroup(update, 'push')
1524 else:
1525 else:
1525 cg = self.changegroupsubset(update, revs, 'push')
1526 cg = self.changegroupsubset(update, revs, 'push')
1526 return cg, remote_heads
1527 return cg, remote_heads
1527
1528
1528 def push_addchangegroup(self, remote, force, revs):
1529 def push_addchangegroup(self, remote, force, revs):
1529 lock = remote.lock()
1530 lock = remote.lock()
1530 try:
1531 try:
1531 ret = self.prepush(remote, force, revs)
1532 ret = self.prepush(remote, force, revs)
1532 if ret[0] is not None:
1533 if ret[0] is not None:
1533 cg, remote_heads = ret
1534 cg, remote_heads = ret
1534 return remote.addchangegroup(cg, 'push', self.url())
1535 return remote.addchangegroup(cg, 'push', self.url())
1535 return ret[1]
1536 return ret[1]
1536 finally:
1537 finally:
1537 del lock
1538 del lock
1538
1539
1539 def push_unbundle(self, remote, force, revs):
1540 def push_unbundle(self, remote, force, revs):
1540 # local repo finds heads on server, finds out what revs it
1541 # local repo finds heads on server, finds out what revs it
1541 # must push. once revs transferred, if server finds it has
1542 # must push. once revs transferred, if server finds it has
1542 # different heads (someone else won commit/push race), server
1543 # different heads (someone else won commit/push race), server
1543 # aborts.
1544 # aborts.
1544
1545
1545 ret = self.prepush(remote, force, revs)
1546 ret = self.prepush(remote, force, revs)
1546 if ret[0] is not None:
1547 if ret[0] is not None:
1547 cg, remote_heads = ret
1548 cg, remote_heads = ret
1548 if force: remote_heads = ['force']
1549 if force: remote_heads = ['force']
1549 return remote.unbundle(cg, remote_heads, 'push')
1550 return remote.unbundle(cg, remote_heads, 'push')
1550 return ret[1]
1551 return ret[1]
1551
1552
1552 def changegroupinfo(self, nodes, source):
1553 def changegroupinfo(self, nodes, source):
1553 if self.ui.verbose or source == 'bundle':
1554 if self.ui.verbose or source == 'bundle':
1554 self.ui.status(_("%d changesets found\n") % len(nodes))
1555 self.ui.status(_("%d changesets found\n") % len(nodes))
1555 if self.ui.debugflag:
1556 if self.ui.debugflag:
1556 self.ui.debug(_("List of changesets:\n"))
1557 self.ui.debug(_("List of changesets:\n"))
1557 for node in nodes:
1558 for node in nodes:
1558 self.ui.debug("%s\n" % hex(node))
1559 self.ui.debug("%s\n" % hex(node))
1559
1560
1560 def changegroupsubset(self, bases, heads, source, extranodes=None):
1561 def changegroupsubset(self, bases, heads, source, extranodes=None):
1561 """This function generates a changegroup consisting of all the nodes
1562 """This function generates a changegroup consisting of all the nodes
1562 that are descendents of any of the bases, and ancestors of any of
1563 that are descendents of any of the bases, and ancestors of any of
1563 the heads.
1564 the heads.
1564
1565
1565 It is fairly complex as determining which filenodes and which
1566 It is fairly complex as determining which filenodes and which
1566 manifest nodes need to be included for the changeset to be complete
1567 manifest nodes need to be included for the changeset to be complete
1567 is non-trivial.
1568 is non-trivial.
1568
1569
1569 Another wrinkle is doing the reverse, figuring out which changeset in
1570 Another wrinkle is doing the reverse, figuring out which changeset in
1570 the changegroup a particular filenode or manifestnode belongs to.
1571 the changegroup a particular filenode or manifestnode belongs to.
1571
1572
1572 The caller can specify some nodes that must be included in the
1573 The caller can specify some nodes that must be included in the
1573 changegroup using the extranodes argument. It should be a dict
1574 changegroup using the extranodes argument. It should be a dict
1574 where the keys are the filenames (or 1 for the manifest), and the
1575 where the keys are the filenames (or 1 for the manifest), and the
1575 values are lists of (node, linknode) tuples, where node is a wanted
1576 values are lists of (node, linknode) tuples, where node is a wanted
1576 node and linknode is the changelog node that should be transmitted as
1577 node and linknode is the changelog node that should be transmitted as
1577 the linkrev.
1578 the linkrev.
1578 """
1579 """
1579
1580
1580 self.hook('preoutgoing', throw=True, source=source)
1581 self.hook('preoutgoing', throw=True, source=source)
1581
1582
1582 # Set up some initial variables
1583 # Set up some initial variables
1583 # Make it easy to refer to self.changelog
1584 # Make it easy to refer to self.changelog
1584 cl = self.changelog
1585 cl = self.changelog
1585 # msng is short for missing - compute the list of changesets in this
1586 # msng is short for missing - compute the list of changesets in this
1586 # changegroup.
1587 # changegroup.
1587 msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads)
1588 msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads)
1588 self.changegroupinfo(msng_cl_lst, source)
1589 self.changegroupinfo(msng_cl_lst, source)
1589 # Some bases may turn out to be superfluous, and some heads may be
1590 # Some bases may turn out to be superfluous, and some heads may be
1590 # too. nodesbetween will return the minimal set of bases and heads
1591 # too. nodesbetween will return the minimal set of bases and heads
1591 # necessary to re-create the changegroup.
1592 # necessary to re-create the changegroup.
1592
1593
1593 # Known heads are the list of heads that it is assumed the recipient
1594 # Known heads are the list of heads that it is assumed the recipient
1594 # of this changegroup will know about.
1595 # of this changegroup will know about.
1595 knownheads = {}
1596 knownheads = {}
1596 # We assume that all parents of bases are known heads.
1597 # We assume that all parents of bases are known heads.
1597 for n in bases:
1598 for n in bases:
1598 for p in cl.parents(n):
1599 for p in cl.parents(n):
1599 if p != nullid:
1600 if p != nullid:
1600 knownheads[p] = 1
1601 knownheads[p] = 1
1601 knownheads = knownheads.keys()
1602 knownheads = knownheads.keys()
1602 if knownheads:
1603 if knownheads:
1603 # Now that we know what heads are known, we can compute which
1604 # Now that we know what heads are known, we can compute which
1604 # changesets are known. The recipient must know about all
1605 # changesets are known. The recipient must know about all
1605 # changesets required to reach the known heads from the null
1606 # changesets required to reach the known heads from the null
1606 # changeset.
1607 # changeset.
1607 has_cl_set, junk, junk = cl.nodesbetween(None, knownheads)
1608 has_cl_set, junk, junk = cl.nodesbetween(None, knownheads)
1608 junk = None
1609 junk = None
1609 # Transform the list into an ersatz set.
1610 # Transform the list into an ersatz set.
1610 has_cl_set = dict.fromkeys(has_cl_set)
1611 has_cl_set = dict.fromkeys(has_cl_set)
1611 else:
1612 else:
1612 # If there were no known heads, the recipient cannot be assumed to
1613 # If there were no known heads, the recipient cannot be assumed to
1613 # know about any changesets.
1614 # know about any changesets.
1614 has_cl_set = {}
1615 has_cl_set = {}
1615
1616
1616 # Make it easy to refer to self.manifest
1617 # Make it easy to refer to self.manifest
1617 mnfst = self.manifest
1618 mnfst = self.manifest
1618 # We don't know which manifests are missing yet
1619 # We don't know which manifests are missing yet
1619 msng_mnfst_set = {}
1620 msng_mnfst_set = {}
1620 # Nor do we know which filenodes are missing.
1621 # Nor do we know which filenodes are missing.
1621 msng_filenode_set = {}
1622 msng_filenode_set = {}
1622
1623
1623 junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex
1624 junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex
1624 junk = None
1625 junk = None
1625
1626
1626 # A changeset always belongs to itself, so the changenode lookup
1627 # A changeset always belongs to itself, so the changenode lookup
1627 # function for a changenode is identity.
1628 # function for a changenode is identity.
1628 def identity(x):
1629 def identity(x):
1629 return x
1630 return x
1630
1631
1631 # A function generating function. Sets up an environment for the
1632 # A function generating function. Sets up an environment for the
1632 # inner function.
1633 # inner function.
1633 def cmp_by_rev_func(revlog):
1634 def cmp_by_rev_func(revlog):
1634 # Compare two nodes by their revision number in the environment's
1635 # Compare two nodes by their revision number in the environment's
1635 # revision history. Since the revision number both represents the
1636 # revision history. Since the revision number both represents the
1636 # most efficient order to read the nodes in, and represents a
1637 # most efficient order to read the nodes in, and represents a
1637 # topological sorting of the nodes, this function is often useful.
1638 # topological sorting of the nodes, this function is often useful.
1638 def cmp_by_rev(a, b):
1639 def cmp_by_rev(a, b):
1639 return cmp(revlog.rev(a), revlog.rev(b))
1640 return cmp(revlog.rev(a), revlog.rev(b))
1640 return cmp_by_rev
1641 return cmp_by_rev
1641
1642
1642 # If we determine that a particular file or manifest node must be a
1643 # If we determine that a particular file or manifest node must be a
1643 # node that the recipient of the changegroup will already have, we can
1644 # node that the recipient of the changegroup will already have, we can
1644 # also assume the recipient will have all the parents. This function
1645 # also assume the recipient will have all the parents. This function
1645 # prunes them from the set of missing nodes.
1646 # prunes them from the set of missing nodes.
1646 def prune_parents(revlog, hasset, msngset):
1647 def prune_parents(revlog, hasset, msngset):
1647 haslst = hasset.keys()
1648 haslst = hasset.keys()
1648 haslst.sort(cmp_by_rev_func(revlog))
1649 haslst.sort(cmp_by_rev_func(revlog))
1649 for node in haslst:
1650 for node in haslst:
1650 parentlst = [p for p in revlog.parents(node) if p != nullid]
1651 parentlst = [p for p in revlog.parents(node) if p != nullid]
1651 while parentlst:
1652 while parentlst:
1652 n = parentlst.pop()
1653 n = parentlst.pop()
1653 if n not in hasset:
1654 if n not in hasset:
1654 hasset[n] = 1
1655 hasset[n] = 1
1655 p = [p for p in revlog.parents(n) if p != nullid]
1656 p = [p for p in revlog.parents(n) if p != nullid]
1656 parentlst.extend(p)
1657 parentlst.extend(p)
1657 for n in hasset:
1658 for n in hasset:
1658 msngset.pop(n, None)
1659 msngset.pop(n, None)
1659
1660
1660 # This is a function generating function used to set up an environment
1661 # This is a function generating function used to set up an environment
1661 # for the inner function to execute in.
1662 # for the inner function to execute in.
1662 def manifest_and_file_collector(changedfileset):
1663 def manifest_and_file_collector(changedfileset):
1663 # This is an information gathering function that gathers
1664 # This is an information gathering function that gathers
1664 # information from each changeset node that goes out as part of
1665 # information from each changeset node that goes out as part of
1665 # the changegroup. The information gathered is a list of which
1666 # the changegroup. The information gathered is a list of which
1666 # manifest nodes are potentially required (the recipient may
1667 # manifest nodes are potentially required (the recipient may
1667 # already have them) and total list of all files which were
1668 # already have them) and total list of all files which were
1668 # changed in any changeset in the changegroup.
1669 # changed in any changeset in the changegroup.
1669 #
1670 #
1670 # We also remember the first changenode we saw any manifest
1671 # We also remember the first changenode we saw any manifest
1671 # referenced by so we can later determine which changenode 'owns'
1672 # referenced by so we can later determine which changenode 'owns'
1672 # the manifest.
1673 # the manifest.
1673 def collect_manifests_and_files(clnode):
1674 def collect_manifests_and_files(clnode):
1674 c = cl.read(clnode)
1675 c = cl.read(clnode)
1675 for f in c[3]:
1676 for f in c[3]:
1676 # This is to make sure we only have one instance of each
1677 # This is to make sure we only have one instance of each
1677 # filename string for each filename.
1678 # filename string for each filename.
1678 changedfileset.setdefault(f, f)
1679 changedfileset.setdefault(f, f)
1679 msng_mnfst_set.setdefault(c[0], clnode)
1680 msng_mnfst_set.setdefault(c[0], clnode)
1680 return collect_manifests_and_files
1681 return collect_manifests_and_files
1681
1682
1682 # Figure out which manifest nodes (of the ones we think might be part
1683 # Figure out which manifest nodes (of the ones we think might be part
1683 # of the changegroup) the recipient must know about and remove them
1684 # of the changegroup) the recipient must know about and remove them
1684 # from the changegroup.
1685 # from the changegroup.
1685 def prune_manifests():
1686 def prune_manifests():
1686 has_mnfst_set = {}
1687 has_mnfst_set = {}
1687 for n in msng_mnfst_set:
1688 for n in msng_mnfst_set:
1688 # If a 'missing' manifest thinks it belongs to a changenode
1689 # If a 'missing' manifest thinks it belongs to a changenode
1689 # the recipient is assumed to have, obviously the recipient
1690 # the recipient is assumed to have, obviously the recipient
1690 # must have that manifest.
1691 # must have that manifest.
1691 linknode = cl.node(mnfst.linkrev(n))
1692 linknode = cl.node(mnfst.linkrev(n))
1692 if linknode in has_cl_set:
1693 if linknode in has_cl_set:
1693 has_mnfst_set[n] = 1
1694 has_mnfst_set[n] = 1
1694 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set)
1695 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set)
1695
1696
1696 # Use the information collected in collect_manifests_and_files to say
1697 # Use the information collected in collect_manifests_and_files to say
1697 # which changenode any manifestnode belongs to.
1698 # which changenode any manifestnode belongs to.
1698 def lookup_manifest_link(mnfstnode):
1699 def lookup_manifest_link(mnfstnode):
1699 return msng_mnfst_set[mnfstnode]
1700 return msng_mnfst_set[mnfstnode]
1700
1701
1701 # A function generating function that sets up the initial environment
1702 # A function generating function that sets up the initial environment
1702 # the inner function.
1703 # the inner function.
1703 def filenode_collector(changedfiles):
1704 def filenode_collector(changedfiles):
1704 next_rev = [0]
1705 next_rev = [0]
1705 # This gathers information from each manifestnode included in the
1706 # This gathers information from each manifestnode included in the
1706 # changegroup about which filenodes the manifest node references
1707 # changegroup about which filenodes the manifest node references
1707 # so we can include those in the changegroup too.
1708 # so we can include those in the changegroup too.
1708 #
1709 #
1709 # It also remembers which changenode each filenode belongs to. It
1710 # It also remembers which changenode each filenode belongs to. It
1710 # does this by assuming the a filenode belongs to the changenode
1711 # does this by assuming the a filenode belongs to the changenode
1711 # the first manifest that references it belongs to.
1712 # the first manifest that references it belongs to.
1712 def collect_msng_filenodes(mnfstnode):
1713 def collect_msng_filenodes(mnfstnode):
1713 r = mnfst.rev(mnfstnode)
1714 r = mnfst.rev(mnfstnode)
1714 if r == next_rev[0]:
1715 if r == next_rev[0]:
1715 # If the last rev we looked at was the one just previous,
1716 # If the last rev we looked at was the one just previous,
1716 # we only need to see a diff.
1717 # we only need to see a diff.
1717 deltamf = mnfst.readdelta(mnfstnode)
1718 deltamf = mnfst.readdelta(mnfstnode)
1718 # For each line in the delta
1719 # For each line in the delta
1719 for f, fnode in deltamf.items():
1720 for f, fnode in deltamf.items():
1720 f = changedfiles.get(f, None)
1721 f = changedfiles.get(f, None)
1721 # And if the file is in the list of files we care
1722 # And if the file is in the list of files we care
1722 # about.
1723 # about.
1723 if f is not None:
1724 if f is not None:
1724 # Get the changenode this manifest belongs to
1725 # Get the changenode this manifest belongs to
1725 clnode = msng_mnfst_set[mnfstnode]
1726 clnode = msng_mnfst_set[mnfstnode]
1726 # Create the set of filenodes for the file if
1727 # Create the set of filenodes for the file if
1727 # there isn't one already.
1728 # there isn't one already.
1728 ndset = msng_filenode_set.setdefault(f, {})
1729 ndset = msng_filenode_set.setdefault(f, {})
1729 # And set the filenode's changelog node to the
1730 # And set the filenode's changelog node to the
1730 # manifest's if it hasn't been set already.
1731 # manifest's if it hasn't been set already.
1731 ndset.setdefault(fnode, clnode)
1732 ndset.setdefault(fnode, clnode)
1732 else:
1733 else:
1733 # Otherwise we need a full manifest.
1734 # Otherwise we need a full manifest.
1734 m = mnfst.read(mnfstnode)
1735 m = mnfst.read(mnfstnode)
1735 # For every file in we care about.
1736 # For every file in we care about.
1736 for f in changedfiles:
1737 for f in changedfiles:
1737 fnode = m.get(f, None)
1738 fnode = m.get(f, None)
1738 # If it's in the manifest
1739 # If it's in the manifest
1739 if fnode is not None:
1740 if fnode is not None:
1740 # See comments above.
1741 # See comments above.
1741 clnode = msng_mnfst_set[mnfstnode]
1742 clnode = msng_mnfst_set[mnfstnode]
1742 ndset = msng_filenode_set.setdefault(f, {})
1743 ndset = msng_filenode_set.setdefault(f, {})
1743 ndset.setdefault(fnode, clnode)
1744 ndset.setdefault(fnode, clnode)
1744 # Remember the revision we hope to see next.
1745 # Remember the revision we hope to see next.
1745 next_rev[0] = r + 1
1746 next_rev[0] = r + 1
1746 return collect_msng_filenodes
1747 return collect_msng_filenodes
1747
1748
1748 # We have a list of filenodes we think we need for a file, lets remove
1749 # We have a list of filenodes we think we need for a file, lets remove
1749 # all those we now the recipient must have.
1750 # all those we now the recipient must have.
1750 def prune_filenodes(f, filerevlog):
1751 def prune_filenodes(f, filerevlog):
1751 msngset = msng_filenode_set[f]
1752 msngset = msng_filenode_set[f]
1752 hasset = {}
1753 hasset = {}
1753 # If a 'missing' filenode thinks it belongs to a changenode we
1754 # If a 'missing' filenode thinks it belongs to a changenode we
1754 # assume the recipient must have, then the recipient must have
1755 # assume the recipient must have, then the recipient must have
1755 # that filenode.
1756 # that filenode.
1756 for n in msngset:
1757 for n in msngset:
1757 clnode = cl.node(filerevlog.linkrev(n))
1758 clnode = cl.node(filerevlog.linkrev(n))
1758 if clnode in has_cl_set:
1759 if clnode in has_cl_set:
1759 hasset[n] = 1
1760 hasset[n] = 1
1760 prune_parents(filerevlog, hasset, msngset)
1761 prune_parents(filerevlog, hasset, msngset)
1761
1762
1762 # A function generator function that sets up the a context for the
1763 # A function generator function that sets up the a context for the
1763 # inner function.
1764 # inner function.
1764 def lookup_filenode_link_func(fname):
1765 def lookup_filenode_link_func(fname):
1765 msngset = msng_filenode_set[fname]
1766 msngset = msng_filenode_set[fname]
1766 # Lookup the changenode the filenode belongs to.
1767 # Lookup the changenode the filenode belongs to.
1767 def lookup_filenode_link(fnode):
1768 def lookup_filenode_link(fnode):
1768 return msngset[fnode]
1769 return msngset[fnode]
1769 return lookup_filenode_link
1770 return lookup_filenode_link
1770
1771
1771 # Add the nodes that were explicitly requested.
1772 # Add the nodes that were explicitly requested.
1772 def add_extra_nodes(name, nodes):
1773 def add_extra_nodes(name, nodes):
1773 if not extranodes or name not in extranodes:
1774 if not extranodes or name not in extranodes:
1774 return
1775 return
1775
1776
1776 for node, linknode in extranodes[name]:
1777 for node, linknode in extranodes[name]:
1777 if node not in nodes:
1778 if node not in nodes:
1778 nodes[node] = linknode
1779 nodes[node] = linknode
1779
1780
1780 # Now that we have all theses utility functions to help out and
1781 # Now that we have all theses utility functions to help out and
1781 # logically divide up the task, generate the group.
1782 # logically divide up the task, generate the group.
1782 def gengroup():
1783 def gengroup():
1783 # The set of changed files starts empty.
1784 # The set of changed files starts empty.
1784 changedfiles = {}
1785 changedfiles = {}
1785 # Create a changenode group generator that will call our functions
1786 # Create a changenode group generator that will call our functions
1786 # back to lookup the owning changenode and collect information.
1787 # back to lookup the owning changenode and collect information.
1787 group = cl.group(msng_cl_lst, identity,
1788 group = cl.group(msng_cl_lst, identity,
1788 manifest_and_file_collector(changedfiles))
1789 manifest_and_file_collector(changedfiles))
1789 for chnk in group:
1790 for chnk in group:
1790 yield chnk
1791 yield chnk
1791
1792
1792 # The list of manifests has been collected by the generator
1793 # The list of manifests has been collected by the generator
1793 # calling our functions back.
1794 # calling our functions back.
1794 prune_manifests()
1795 prune_manifests()
1795 add_extra_nodes(1, msng_mnfst_set)
1796 add_extra_nodes(1, msng_mnfst_set)
1796 msng_mnfst_lst = msng_mnfst_set.keys()
1797 msng_mnfst_lst = msng_mnfst_set.keys()
1797 # Sort the manifestnodes by revision number.
1798 # Sort the manifestnodes by revision number.
1798 msng_mnfst_lst.sort(cmp_by_rev_func(mnfst))
1799 msng_mnfst_lst.sort(cmp_by_rev_func(mnfst))
1799 # Create a generator for the manifestnodes that calls our lookup
1800 # Create a generator for the manifestnodes that calls our lookup
1800 # and data collection functions back.
1801 # and data collection functions back.
1801 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link,
1802 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link,
1802 filenode_collector(changedfiles))
1803 filenode_collector(changedfiles))
1803 for chnk in group:
1804 for chnk in group:
1804 yield chnk
1805 yield chnk
1805
1806
1806 # These are no longer needed, dereference and toss the memory for
1807 # These are no longer needed, dereference and toss the memory for
1807 # them.
1808 # them.
1808 msng_mnfst_lst = None
1809 msng_mnfst_lst = None
1809 msng_mnfst_set.clear()
1810 msng_mnfst_set.clear()
1810
1811
1811 if extranodes:
1812 if extranodes:
1812 for fname in extranodes:
1813 for fname in extranodes:
1813 if isinstance(fname, int):
1814 if isinstance(fname, int):
1814 continue
1815 continue
1815 msng_filenode_set.setdefault(fname, {})
1816 msng_filenode_set.setdefault(fname, {})
1816 changedfiles[fname] = 1
1817 changedfiles[fname] = 1
1817 # Go through all our files in order sorted by name.
1818 # Go through all our files in order sorted by name.
1818 for fname in util.sort(changedfiles):
1819 for fname in util.sort(changedfiles):
1819 filerevlog = self.file(fname)
1820 filerevlog = self.file(fname)
1820 if not len(filerevlog):
1821 if not len(filerevlog):
1821 raise util.Abort(_("empty or missing revlog for %s") % fname)
1822 raise util.Abort(_("empty or missing revlog for %s") % fname)
1822 # Toss out the filenodes that the recipient isn't really
1823 # Toss out the filenodes that the recipient isn't really
1823 # missing.
1824 # missing.
1824 if fname in msng_filenode_set:
1825 if fname in msng_filenode_set:
1825 prune_filenodes(fname, filerevlog)
1826 prune_filenodes(fname, filerevlog)
1826 add_extra_nodes(fname, msng_filenode_set[fname])
1827 add_extra_nodes(fname, msng_filenode_set[fname])
1827 msng_filenode_lst = msng_filenode_set[fname].keys()
1828 msng_filenode_lst = msng_filenode_set[fname].keys()
1828 else:
1829 else:
1829 msng_filenode_lst = []
1830 msng_filenode_lst = []
1830 # If any filenodes are left, generate the group for them,
1831 # If any filenodes are left, generate the group for them,
1831 # otherwise don't bother.
1832 # otherwise don't bother.
1832 if len(msng_filenode_lst) > 0:
1833 if len(msng_filenode_lst) > 0:
1833 yield changegroup.chunkheader(len(fname))
1834 yield changegroup.chunkheader(len(fname))
1834 yield fname
1835 yield fname
1835 # Sort the filenodes by their revision #
1836 # Sort the filenodes by their revision #
1836 msng_filenode_lst.sort(cmp_by_rev_func(filerevlog))
1837 msng_filenode_lst.sort(cmp_by_rev_func(filerevlog))
1837 # Create a group generator and only pass in a changenode
1838 # Create a group generator and only pass in a changenode
1838 # lookup function as we need to collect no information
1839 # lookup function as we need to collect no information
1839 # from filenodes.
1840 # from filenodes.
1840 group = filerevlog.group(msng_filenode_lst,
1841 group = filerevlog.group(msng_filenode_lst,
1841 lookup_filenode_link_func(fname))
1842 lookup_filenode_link_func(fname))
1842 for chnk in group:
1843 for chnk in group:
1843 yield chnk
1844 yield chnk
1844 if fname in msng_filenode_set:
1845 if fname in msng_filenode_set:
1845 # Don't need this anymore, toss it to free memory.
1846 # Don't need this anymore, toss it to free memory.
1846 del msng_filenode_set[fname]
1847 del msng_filenode_set[fname]
1847 # Signal that no more groups are left.
1848 # Signal that no more groups are left.
1848 yield changegroup.closechunk()
1849 yield changegroup.closechunk()
1849
1850
1850 if msng_cl_lst:
1851 if msng_cl_lst:
1851 self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source)
1852 self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source)
1852
1853
1853 return util.chunkbuffer(gengroup())
1854 return util.chunkbuffer(gengroup())
1854
1855
1855 def changegroup(self, basenodes, source):
1856 def changegroup(self, basenodes, source):
1856 """Generate a changegroup of all nodes that we have that a recipient
1857 """Generate a changegroup of all nodes that we have that a recipient
1857 doesn't.
1858 doesn't.
1858
1859
1859 This is much easier than the previous function as we can assume that
1860 This is much easier than the previous function as we can assume that
1860 the recipient has any changenode we aren't sending them."""
1861 the recipient has any changenode we aren't sending them."""
1861
1862
1862 self.hook('preoutgoing', throw=True, source=source)
1863 self.hook('preoutgoing', throw=True, source=source)
1863
1864
1864 cl = self.changelog
1865 cl = self.changelog
1865 nodes = cl.nodesbetween(basenodes, None)[0]
1866 nodes = cl.nodesbetween(basenodes, None)[0]
1866 revset = dict.fromkeys([cl.rev(n) for n in nodes])
1867 revset = dict.fromkeys([cl.rev(n) for n in nodes])
1867 self.changegroupinfo(nodes, source)
1868 self.changegroupinfo(nodes, source)
1868
1869
1869 def identity(x):
1870 def identity(x):
1870 return x
1871 return x
1871
1872
1872 def gennodelst(log):
1873 def gennodelst(log):
1873 for r in log:
1874 for r in log:
1874 n = log.node(r)
1875 n = log.node(r)
1875 if log.linkrev(n) in revset:
1876 if log.linkrev(n) in revset:
1876 yield n
1877 yield n
1877
1878
1878 def changed_file_collector(changedfileset):
1879 def changed_file_collector(changedfileset):
1879 def collect_changed_files(clnode):
1880 def collect_changed_files(clnode):
1880 c = cl.read(clnode)
1881 c = cl.read(clnode)
1881 for fname in c[3]:
1882 for fname in c[3]:
1882 changedfileset[fname] = 1
1883 changedfileset[fname] = 1
1883 return collect_changed_files
1884 return collect_changed_files
1884
1885
1885 def lookuprevlink_func(revlog):
1886 def lookuprevlink_func(revlog):
1886 def lookuprevlink(n):
1887 def lookuprevlink(n):
1887 return cl.node(revlog.linkrev(n))
1888 return cl.node(revlog.linkrev(n))
1888 return lookuprevlink
1889 return lookuprevlink
1889
1890
1890 def gengroup():
1891 def gengroup():
1891 # construct a list of all changed files
1892 # construct a list of all changed files
1892 changedfiles = {}
1893 changedfiles = {}
1893
1894
1894 for chnk in cl.group(nodes, identity,
1895 for chnk in cl.group(nodes, identity,
1895 changed_file_collector(changedfiles)):
1896 changed_file_collector(changedfiles)):
1896 yield chnk
1897 yield chnk
1897
1898
1898 mnfst = self.manifest
1899 mnfst = self.manifest
1899 nodeiter = gennodelst(mnfst)
1900 nodeiter = gennodelst(mnfst)
1900 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)):
1901 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)):
1901 yield chnk
1902 yield chnk
1902
1903
1903 for fname in util.sort(changedfiles):
1904 for fname in util.sort(changedfiles):
1904 filerevlog = self.file(fname)
1905 filerevlog = self.file(fname)
1905 if not len(filerevlog):
1906 if not len(filerevlog):
1906 raise util.Abort(_("empty or missing revlog for %s") % fname)
1907 raise util.Abort(_("empty or missing revlog for %s") % fname)
1907 nodeiter = gennodelst(filerevlog)
1908 nodeiter = gennodelst(filerevlog)
1908 nodeiter = list(nodeiter)
1909 nodeiter = list(nodeiter)
1909 if nodeiter:
1910 if nodeiter:
1910 yield changegroup.chunkheader(len(fname))
1911 yield changegroup.chunkheader(len(fname))
1911 yield fname
1912 yield fname
1912 lookup = lookuprevlink_func(filerevlog)
1913 lookup = lookuprevlink_func(filerevlog)
1913 for chnk in filerevlog.group(nodeiter, lookup):
1914 for chnk in filerevlog.group(nodeiter, lookup):
1914 yield chnk
1915 yield chnk
1915
1916
1916 yield changegroup.closechunk()
1917 yield changegroup.closechunk()
1917
1918
1918 if nodes:
1919 if nodes:
1919 self.hook('outgoing', node=hex(nodes[0]), source=source)
1920 self.hook('outgoing', node=hex(nodes[0]), source=source)
1920
1921
1921 return util.chunkbuffer(gengroup())
1922 return util.chunkbuffer(gengroup())
1922
1923
1923 def addchangegroup(self, source, srctype, url, emptyok=False):
1924 def addchangegroup(self, source, srctype, url, emptyok=False):
1924 """add changegroup to repo.
1925 """add changegroup to repo.
1925
1926
1926 return values:
1927 return values:
1927 - nothing changed or no source: 0
1928 - nothing changed or no source: 0
1928 - more heads than before: 1+added heads (2..n)
1929 - more heads than before: 1+added heads (2..n)
1929 - less heads than before: -1-removed heads (-2..-n)
1930 - less heads than before: -1-removed heads (-2..-n)
1930 - number of heads stays the same: 1
1931 - number of heads stays the same: 1
1931 """
1932 """
1932 def csmap(x):
1933 def csmap(x):
1933 self.ui.debug(_("add changeset %s\n") % short(x))
1934 self.ui.debug(_("add changeset %s\n") % short(x))
1934 return len(cl)
1935 return len(cl)
1935
1936
1936 def revmap(x):
1937 def revmap(x):
1937 return cl.rev(x)
1938 return cl.rev(x)
1938
1939
1939 if not source:
1940 if not source:
1940 return 0
1941 return 0
1941
1942
1942 self.hook('prechangegroup', throw=True, source=srctype, url=url)
1943 self.hook('prechangegroup', throw=True, source=srctype, url=url)
1943
1944
1944 changesets = files = revisions = 0
1945 changesets = files = revisions = 0
1945
1946
1946 # write changelog data to temp files so concurrent readers will not see
1947 # write changelog data to temp files so concurrent readers will not see
1947 # inconsistent view
1948 # inconsistent view
1948 cl = self.changelog
1949 cl = self.changelog
1949 cl.delayupdate()
1950 cl.delayupdate()
1950 oldheads = len(cl.heads())
1951 oldheads = len(cl.heads())
1951
1952
1952 tr = self.transaction()
1953 tr = self.transaction()
1953 try:
1954 try:
1954 trp = weakref.proxy(tr)
1955 trp = weakref.proxy(tr)
1955 # pull off the changeset group
1956 # pull off the changeset group
1956 self.ui.status(_("adding changesets\n"))
1957 self.ui.status(_("adding changesets\n"))
1957 cor = len(cl) - 1
1958 cor = len(cl) - 1
1958 chunkiter = changegroup.chunkiter(source)
1959 chunkiter = changegroup.chunkiter(source)
1959 if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok:
1960 if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok:
1960 raise util.Abort(_("received changelog group is empty"))
1961 raise util.Abort(_("received changelog group is empty"))
1961 cnr = len(cl) - 1
1962 cnr = len(cl) - 1
1962 changesets = cnr - cor
1963 changesets = cnr - cor
1963
1964
1964 # pull off the manifest group
1965 # pull off the manifest group
1965 self.ui.status(_("adding manifests\n"))
1966 self.ui.status(_("adding manifests\n"))
1966 chunkiter = changegroup.chunkiter(source)
1967 chunkiter = changegroup.chunkiter(source)
1967 # no need to check for empty manifest group here:
1968 # no need to check for empty manifest group here:
1968 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1969 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1969 # no new manifest will be created and the manifest group will
1970 # no new manifest will be created and the manifest group will
1970 # be empty during the pull
1971 # be empty during the pull
1971 self.manifest.addgroup(chunkiter, revmap, trp)
1972 self.manifest.addgroup(chunkiter, revmap, trp)
1972
1973
1973 # process the files
1974 # process the files
1974 self.ui.status(_("adding file changes\n"))
1975 self.ui.status(_("adding file changes\n"))
1975 while 1:
1976 while 1:
1976 f = changegroup.getchunk(source)
1977 f = changegroup.getchunk(source)
1977 if not f:
1978 if not f:
1978 break
1979 break
1979 self.ui.debug(_("adding %s revisions\n") % f)
1980 self.ui.debug(_("adding %s revisions\n") % f)
1980 fl = self.file(f)
1981 fl = self.file(f)
1981 o = len(fl)
1982 o = len(fl)
1982 chunkiter = changegroup.chunkiter(source)
1983 chunkiter = changegroup.chunkiter(source)
1983 if fl.addgroup(chunkiter, revmap, trp) is None:
1984 if fl.addgroup(chunkiter, revmap, trp) is None:
1984 raise util.Abort(_("received file revlog group is empty"))
1985 raise util.Abort(_("received file revlog group is empty"))
1985 revisions += len(fl) - o
1986 revisions += len(fl) - o
1986 files += 1
1987 files += 1
1987
1988
1988 # make changelog see real files again
1989 # make changelog see real files again
1989 cl.finalize(trp)
1990 cl.finalize(trp)
1990
1991
1991 newheads = len(self.changelog.heads())
1992 newheads = len(self.changelog.heads())
1992 heads = ""
1993 heads = ""
1993 if oldheads and newheads != oldheads:
1994 if oldheads and newheads != oldheads:
1994 heads = _(" (%+d heads)") % (newheads - oldheads)
1995 heads = _(" (%+d heads)") % (newheads - oldheads)
1995
1996
1996 self.ui.status(_("added %d changesets"
1997 self.ui.status(_("added %d changesets"
1997 " with %d changes to %d files%s\n")
1998 " with %d changes to %d files%s\n")
1998 % (changesets, revisions, files, heads))
1999 % (changesets, revisions, files, heads))
1999
2000
2000 if changesets > 0:
2001 if changesets > 0:
2001 self.hook('pretxnchangegroup', throw=True,
2002 self.hook('pretxnchangegroup', throw=True,
2002 node=hex(self.changelog.node(cor+1)), source=srctype,
2003 node=hex(self.changelog.node(cor+1)), source=srctype,
2003 url=url)
2004 url=url)
2004
2005
2005 tr.close()
2006 tr.close()
2006 finally:
2007 finally:
2007 del tr
2008 del tr
2008
2009
2009 if changesets > 0:
2010 if changesets > 0:
2010 # forcefully update the on-disk branch cache
2011 # forcefully update the on-disk branch cache
2011 self.ui.debug(_("updating the branch cache\n"))
2012 self.ui.debug(_("updating the branch cache\n"))
2012 self.branchtags()
2013 self.branchtags()
2013 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
2014 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
2014 source=srctype, url=url)
2015 source=srctype, url=url)
2015
2016
2016 for i in xrange(cor + 1, cnr + 1):
2017 for i in xrange(cor + 1, cnr + 1):
2017 self.hook("incoming", node=hex(self.changelog.node(i)),
2018 self.hook("incoming", node=hex(self.changelog.node(i)),
2018 source=srctype, url=url)
2019 source=srctype, url=url)
2019
2020
2020 # never return 0 here:
2021 # never return 0 here:
2021 if newheads < oldheads:
2022 if newheads < oldheads:
2022 return newheads - oldheads - 1
2023 return newheads - oldheads - 1
2023 else:
2024 else:
2024 return newheads - oldheads + 1
2025 return newheads - oldheads + 1
2025
2026
2026
2027
2027 def stream_in(self, remote):
2028 def stream_in(self, remote):
2028 fp = remote.stream_out()
2029 fp = remote.stream_out()
2029 l = fp.readline()
2030 l = fp.readline()
2030 try:
2031 try:
2031 resp = int(l)
2032 resp = int(l)
2032 except ValueError:
2033 except ValueError:
2033 raise util.UnexpectedOutput(
2034 raise util.UnexpectedOutput(
2034 _('Unexpected response from remote server:'), l)
2035 _('Unexpected response from remote server:'), l)
2035 if resp == 1:
2036 if resp == 1:
2036 raise util.Abort(_('operation forbidden by server'))
2037 raise util.Abort(_('operation forbidden by server'))
2037 elif resp == 2:
2038 elif resp == 2:
2038 raise util.Abort(_('locking the remote repository failed'))
2039 raise util.Abort(_('locking the remote repository failed'))
2039 elif resp != 0:
2040 elif resp != 0:
2040 raise util.Abort(_('the server sent an unknown error code'))
2041 raise util.Abort(_('the server sent an unknown error code'))
2041 self.ui.status(_('streaming all changes\n'))
2042 self.ui.status(_('streaming all changes\n'))
2042 l = fp.readline()
2043 l = fp.readline()
2043 try:
2044 try:
2044 total_files, total_bytes = map(int, l.split(' ', 1))
2045 total_files, total_bytes = map(int, l.split(' ', 1))
2045 except (ValueError, TypeError):
2046 except (ValueError, TypeError):
2046 raise util.UnexpectedOutput(
2047 raise util.UnexpectedOutput(
2047 _('Unexpected response from remote server:'), l)
2048 _('Unexpected response from remote server:'), l)
2048 self.ui.status(_('%d files to transfer, %s of data\n') %
2049 self.ui.status(_('%d files to transfer, %s of data\n') %
2049 (total_files, util.bytecount(total_bytes)))
2050 (total_files, util.bytecount(total_bytes)))
2050 start = time.time()
2051 start = time.time()
2051 for i in xrange(total_files):
2052 for i in xrange(total_files):
2052 # XXX doesn't support '\n' or '\r' in filenames
2053 # XXX doesn't support '\n' or '\r' in filenames
2053 l = fp.readline()
2054 l = fp.readline()
2054 try:
2055 try:
2055 name, size = l.split('\0', 1)
2056 name, size = l.split('\0', 1)
2056 size = int(size)
2057 size = int(size)
2057 except (ValueError, TypeError):
2058 except (ValueError, TypeError):
2058 raise util.UnexpectedOutput(
2059 raise util.UnexpectedOutput(
2059 _('Unexpected response from remote server:'), l)
2060 _('Unexpected response from remote server:'), l)
2060 self.ui.debug(_('adding %s (%s)\n') % (name, util.bytecount(size)))
2061 self.ui.debug(_('adding %s (%s)\n') % (name, util.bytecount(size)))
2061 ofp = self.sopener(name, 'w')
2062 ofp = self.sopener(name, 'w')
2062 for chunk in util.filechunkiter(fp, limit=size):
2063 for chunk in util.filechunkiter(fp, limit=size):
2063 ofp.write(chunk)
2064 ofp.write(chunk)
2064 ofp.close()
2065 ofp.close()
2065 elapsed = time.time() - start
2066 elapsed = time.time() - start
2066 if elapsed <= 0:
2067 if elapsed <= 0:
2067 elapsed = 0.001
2068 elapsed = 0.001
2068 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
2069 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
2069 (util.bytecount(total_bytes), elapsed,
2070 (util.bytecount(total_bytes), elapsed,
2070 util.bytecount(total_bytes / elapsed)))
2071 util.bytecount(total_bytes / elapsed)))
2071 self.invalidate()
2072 self.invalidate()
2072 return len(self.heads()) + 1
2073 return len(self.heads()) + 1
2073
2074
2074 def clone(self, remote, heads=[], stream=False):
2075 def clone(self, remote, heads=[], stream=False):
2075 '''clone remote repository.
2076 '''clone remote repository.
2076
2077
2077 keyword arguments:
2078 keyword arguments:
2078 heads: list of revs to clone (forces use of pull)
2079 heads: list of revs to clone (forces use of pull)
2079 stream: use streaming clone if possible'''
2080 stream: use streaming clone if possible'''
2080
2081
2081 # now, all clients that can request uncompressed clones can
2082 # now, all clients that can request uncompressed clones can
2082 # read repo formats supported by all servers that can serve
2083 # read repo formats supported by all servers that can serve
2083 # them.
2084 # them.
2084
2085
2085 # if revlog format changes, client will have to check version
2086 # if revlog format changes, client will have to check version
2086 # and format flags on "stream" capability, and use
2087 # and format flags on "stream" capability, and use
2087 # uncompressed only if compatible.
2088 # uncompressed only if compatible.
2088
2089
2089 if stream and not heads and remote.capable('stream'):
2090 if stream and not heads and remote.capable('stream'):
2090 return self.stream_in(remote)
2091 return self.stream_in(remote)
2091 return self.pull(remote, heads)
2092 return self.pull(remote, heads)
2092
2093
2093 # used to avoid circular references so destructors work
2094 # used to avoid circular references so destructors work
2094 def aftertrans(files):
2095 def aftertrans(files):
2095 renamefiles = [tuple(t) for t in files]
2096 renamefiles = [tuple(t) for t in files]
2096 def a():
2097 def a():
2097 for src, dest in renamefiles:
2098 for src, dest in renamefiles:
2098 util.rename(src, dest)
2099 util.rename(src, dest)
2099 return a
2100 return a
2100
2101
2101 def instance(ui, path, create):
2102 def instance(ui, path, create):
2102 return localrepository(ui, util.drop_scheme('file', path), create)
2103 return localrepository(ui, util.drop_scheme('file', path), create)
2103
2104
2104 def islocal(path):
2105 def islocal(path):
2105 return True
2106 return True
@@ -1,127 +1,292 b''
1 # store.py - repository store handling for Mercurial
1 # store.py - repository store handling for Mercurial
2 #
2 #
3 # Copyright 2008 Matt Mackall <mpm@selenic.com>
3 # Copyright 2008 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from i18n import _
8 import os, stat, osutil, util
9 import os, stat, osutil, util
9
10
11 _sha = util.sha1
12
10 def _buildencodefun():
13 def _buildencodefun():
11 e = '_'
14 e = '_'
12 win_reserved = [ord(x) for x in '\\:*?"<>|']
15 win_reserved = [ord(x) for x in '\\:*?"<>|']
13 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ])
16 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ])
14 for x in (range(32) + range(126, 256) + win_reserved):
17 for x in (range(32) + range(126, 256) + win_reserved):
15 cmap[chr(x)] = "~%02x" % x
18 cmap[chr(x)] = "~%02x" % x
16 for x in range(ord("A"), ord("Z")+1) + [ord(e)]:
19 for x in range(ord("A"), ord("Z")+1) + [ord(e)]:
17 cmap[chr(x)] = e + chr(x).lower()
20 cmap[chr(x)] = e + chr(x).lower()
18 dmap = {}
21 dmap = {}
19 for k, v in cmap.iteritems():
22 for k, v in cmap.iteritems():
20 dmap[v] = k
23 dmap[v] = k
21 def decode(s):
24 def decode(s):
22 i = 0
25 i = 0
23 while i < len(s):
26 while i < len(s):
24 for l in xrange(1, 4):
27 for l in xrange(1, 4):
25 try:
28 try:
26 yield dmap[s[i:i+l]]
29 yield dmap[s[i:i+l]]
27 i += l
30 i += l
28 break
31 break
29 except KeyError:
32 except KeyError:
30 pass
33 pass
31 else:
34 else:
32 raise KeyError
35 raise KeyError
33 return (lambda s: "".join([cmap[c] for c in s]),
36 return (lambda s: "".join([cmap[c] for c in s]),
34 lambda s: "".join(list(decode(s))))
37 lambda s: "".join(list(decode(s))))
35
38
36 encodefilename, decodefilename = _buildencodefun()
39 encodefilename, decodefilename = _buildencodefun()
37
40
41 def _build_lower_encodefun():
42 win_reserved = [ord(x) for x in '\\:*?"<>|']
43 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ])
44 for x in (range(32) + range(126, 256) + win_reserved):
45 cmap[chr(x)] = "~%02x" % x
46 for x in range(ord("A"), ord("Z")+1):
47 cmap[chr(x)] = chr(x).lower()
48 return lambda s: "".join([cmap[c] for c in s])
49
50 lowerencode = _build_lower_encodefun()
51
52 _windows_reserved_filenames = '''con prn aux nul
53 com1 com2 com3 com4 com5 com6 com7 com8 com9
54 lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
55 def auxencode(path):
56 res = []
57 for n in path.split('/'):
58 if n:
59 base = n.split('.')[0]
60 if base and (base in _windows_reserved_filenames):
61 # encode third letter ('aux' -> 'au~78')
62 ec = "~%02x" % ord(n[2])
63 n = n[0:2] + ec + n[3:]
64 res.append(n)
65 return '/'.join(res)
66
67 MAX_PATH_LEN_IN_HGSTORE = 120
68 DIR_PREFIX_LEN = 8
69 _MAX_SHORTENED_DIRS_LEN = 8 * (DIR_PREFIX_LEN + 1) - 4
70 def hybridencode(path):
71 '''encodes path with a length limit
72
73 Encodes all paths that begin with 'data/', according to the following.
74
75 Default encoding (reversible):
76
77 Encodes all uppercase letters 'X' as '_x'. All reserved or illegal
78 characters are encoded as '~xx', where xx is the two digit hex code
79 of the character (see encodefilename).
80 Relevant path components consisting of Windows reserved filenames are
81 masked by encoding the third character ('aux' -> 'au~78', see auxencode).
82
83 Hashed encoding (not reversible):
84
85 If the default-encoded path is longer than MAX_PATH_LEN_IN_HGSTORE, a
86 non-reversible hybrid hashing of the path is done instead.
87 This encoding uses up to DIR_PREFIX_LEN characters of all directory
88 levels of the lowerencoded path, but not more levels than can fit into
89 _MAX_SHORTENED_DIRS_LEN.
90 Then follows the filler followed by the sha digest of the full path.
91 The filler is the beginning of the basename of the lowerencoded path
92 (the basename is everything after the last path separator). The filler
93 is as long as possible, filling in characters from the basename until
94 the encoded path has MAX_PATH_LEN_IN_HGSTORE characters (or all chars
95 of the basename have been taken).
96 The extension (e.g. '.i' or '.d') is preserved.
97
98 The string 'data/' at the beginning is replaced with 'dh/', if the hashed
99 encoding was used.
100 '''
101 if not path.startswith('data/'):
102 return path
103 ndpath = path[len('data/'):]
104 res = 'data/' + auxencode(encodefilename(ndpath))
105 if len(res) > MAX_PATH_LEN_IN_HGSTORE:
106 digest = _sha(path).hexdigest()
107 aep = auxencode(lowerencode(ndpath))
108 _root, ext = os.path.splitext(aep)
109 parts = aep.split('/')
110 basename = parts[-1]
111 sdirs = []
112 for p in parts[:-1]:
113 d = p[:DIR_PREFIX_LEN]
114 t = '/'.join(sdirs) + '/' + d
115 if len(t) > _MAX_SHORTENED_DIRS_LEN:
116 break
117 sdirs.append(d)
118 dirs = '/'.join(sdirs)
119 if len(dirs) > 0:
120 dirs += '/'
121 res = 'dh/' + dirs + digest + ext
122 space_left = MAX_PATH_LEN_IN_HGSTORE - len(res)
123 if space_left > 0:
124 filler = basename[:space_left]
125 res = 'dh/' + dirs + filler + digest + ext
126 return res
127
38 def _calcmode(path):
128 def _calcmode(path):
39 try:
129 try:
40 # files in .hg/ will be created using this mode
130 # files in .hg/ will be created using this mode
41 mode = os.stat(path).st_mode
131 mode = os.stat(path).st_mode
42 # avoid some useless chmods
132 # avoid some useless chmods
43 if (0777 & ~util._umask) == (0777 & mode):
133 if (0777 & ~util._umask) == (0777 & mode):
44 mode = None
134 mode = None
45 except OSError:
135 except OSError:
46 mode = None
136 mode = None
47 return mode
137 return mode
48
138
49 _data = 'data 00manifest.d 00manifest.i 00changelog.d 00changelog.i'
139 _data = 'data 00manifest.d 00manifest.i 00changelog.d 00changelog.i'
50
140
51 class basicstore:
141 class basicstore:
52 '''base class for local repository stores'''
142 '''base class for local repository stores'''
53 def __init__(self, path, opener, pathjoiner):
143 def __init__(self, path, opener, pathjoiner):
54 self.pathjoiner = pathjoiner
144 self.pathjoiner = pathjoiner
55 self.path = path
145 self.path = path
56 self.createmode = _calcmode(path)
146 self.createmode = _calcmode(path)
57 self.opener = opener(self.path)
147 self.opener = opener(self.path)
58 self.opener.createmode = self.createmode
148 self.opener.createmode = self.createmode
59
149
60 def join(self, f):
150 def join(self, f):
61 return self.pathjoiner(self.path, f)
151 return self.pathjoiner(self.path, f)
62
152
63 def _walk(self, relpath, recurse):
153 def _walk(self, relpath, recurse):
64 '''yields (unencoded, encoded, size)'''
154 '''yields (unencoded, encoded, size)'''
65 path = self.pathjoiner(self.path, relpath)
155 path = self.pathjoiner(self.path, relpath)
66 striplen = len(self.path) + len(os.sep)
156 striplen = len(self.path) + len(os.sep)
67 prefix = path[striplen:]
157 prefix = path[striplen:]
68 l = []
158 l = []
69 if os.path.isdir(path):
159 if os.path.isdir(path):
70 visit = [path]
160 visit = [path]
71 while visit:
161 while visit:
72 p = visit.pop()
162 p = visit.pop()
73 for f, kind, st in osutil.listdir(p, stat=True):
163 for f, kind, st in osutil.listdir(p, stat=True):
74 fp = self.pathjoiner(p, f)
164 fp = self.pathjoiner(p, f)
75 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
165 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
76 n = util.pconvert(fp[striplen:])
166 n = util.pconvert(fp[striplen:])
77 l.append((n, n, st.st_size))
167 l.append((n, n, st.st_size))
78 elif kind == stat.S_IFDIR and recurse:
168 elif kind == stat.S_IFDIR and recurse:
79 visit.append(fp)
169 visit.append(fp)
80 return util.sort(l)
170 return util.sort(l)
81
171
82 def datafiles(self):
172 def datafiles(self):
83 return self._walk('data', True)
173 return self._walk('data', True)
84
174
85 def walk(self):
175 def walk(self):
86 '''yields (unencoded, encoded, size)'''
176 '''yields (unencoded, encoded, size)'''
87 # yield data files first
177 # yield data files first
88 for x in self.datafiles():
178 for x in self.datafiles():
89 yield x
179 yield x
90 # yield manifest before changelog
180 # yield manifest before changelog
91 meta = self._walk('', False)
181 meta = self._walk('', False)
92 meta.reverse()
182 meta.reverse()
93 for x in meta:
183 for x in meta:
94 yield x
184 yield x
95
185
96 def copylist(self):
186 def copylist(self):
97 return ['requires'] + _data.split()
187 return ['requires'] + _data.split()
98
188
99 class encodedstore(basicstore):
189 class encodedstore(basicstore):
100 def __init__(self, path, opener, pathjoiner):
190 def __init__(self, path, opener, pathjoiner):
101 self.pathjoiner = pathjoiner
191 self.pathjoiner = pathjoiner
102 self.path = self.pathjoiner(path, 'store')
192 self.path = self.pathjoiner(path, 'store')
103 self.createmode = _calcmode(self.path)
193 self.createmode = _calcmode(self.path)
104 op = opener(self.path)
194 op = opener(self.path)
105 op.createmode = self.createmode
195 op.createmode = self.createmode
106 self.opener = lambda f, *args, **kw: op(encodefilename(f), *args, **kw)
196 self.opener = lambda f, *args, **kw: op(encodefilename(f), *args, **kw)
107
197
108 def datafiles(self):
198 def datafiles(self):
109 for a, b, size in self._walk('data', True):
199 for a, b, size in self._walk('data', True):
110 try:
200 try:
111 a = decodefilename(a)
201 a = decodefilename(a)
112 except KeyError:
202 except KeyError:
113 a = None
203 a = None
114 yield a, b, size
204 yield a, b, size
115
205
116 def join(self, f):
206 def join(self, f):
117 return self.pathjoiner(self.path, encodefilename(f))
207 return self.pathjoiner(self.path, encodefilename(f))
118
208
119 def copylist(self):
209 def copylist(self):
120 return (['requires', '00changelog.i'] +
210 return (['requires', '00changelog.i'] +
121 [self.pathjoiner('store', f) for f in _data.split()])
211 [self.pathjoiner('store', f) for f in _data.split()])
122
212
213 def fncache(opener):
214 '''yields the entries in the fncache file'''
215 try:
216 fp = opener('fncache', mode='rb')
217 except IOError:
218 # skip nonexistent file
219 return
220 for n, line in enumerate(fp):
221 if (len(line) < 2) or (line[-1] != '\n'):
222 t = _('invalid entry in fncache, line %s') % (n + 1)
223 raise util.Abort(t)
224 yield line[:-1]
225 fp.close()
226
227 class fncacheopener(object):
228 def __init__(self, opener):
229 self.opener = opener
230 self.entries = None
231
232 def loadfncache(self):
233 self.entries = {}
234 for f in fncache(self.opener):
235 self.entries[f] = True
236
237 def __call__(self, path, mode='r', *args, **kw):
238 if mode not in ('r', 'rb') and path.startswith('data/'):
239 if self.entries is None:
240 self.loadfncache()
241 if path not in self.entries:
242 self.opener('fncache', 'ab').write(path + '\n')
243 # fncache may contain non-existent files after rollback / strip
244 self.entries[path] = True
245 return self.opener(hybridencode(path), mode, *args, **kw)
246
247 class fncachestore(basicstore):
248 def __init__(self, path, opener, pathjoiner):
249 self.pathjoiner = pathjoiner
250 self.path = self.pathjoiner(path, 'store')
251 self.createmode = _calcmode(self.path)
252 self._op = opener(self.path)
253 self._op.createmode = self.createmode
254 self.opener = fncacheopener(self._op)
255
256 def join(self, f):
257 return self.pathjoiner(self.path, hybridencode(f))
258
259 def datafiles(self):
260 rewrite = False
261 existing = []
262 pjoin = self.pathjoiner
263 spath = self.path
264 for f in fncache(self._op):
265 ef = hybridencode(f)
266 try:
267 st = os.stat(pjoin(spath, ef))
268 yield f, ef, st.st_size
269 existing.append(f)
270 except OSError:
271 # nonexistent entry
272 rewrite = True
273 if rewrite:
274 # rewrite fncache to remove nonexistent entries
275 # (may be caused by rollback / strip)
276 fp = self._op('fncache', mode='wb')
277 for p in existing:
278 fp.write(p + '\n')
279 fp.close()
280
281 def copylist(self):
282 d = _data + ' dh fncache'
283 return (['requires', '00changelog.i'] +
284 [self.pathjoiner('store', f) for f in d.split()])
285
123 def store(requirements, path, opener, pathjoiner=None):
286 def store(requirements, path, opener, pathjoiner=None):
124 pathjoiner = pathjoiner or os.path.join
287 pathjoiner = pathjoiner or os.path.join
125 if 'store' in requirements:
288 if 'store' in requirements:
289 if 'fncache' in requirements:
290 return fncachestore(path, opener, pathjoiner)
126 return encodedstore(path, opener, pathjoiner)
291 return encodedstore(path, opener, pathjoiner)
127 return basicstore(path, opener, pathjoiner)
292 return basicstore(path, opener, pathjoiner)
@@ -1,47 +1,61 b''
1 #!/bin/sh
1 #!/bin/sh
2
2
3 CONTRIBDIR=$TESTDIR/../contrib
3 CONTRIBDIR=$TESTDIR/../contrib
4
4
5 echo % prepare repo-a
5 mkdir repo-a
6 mkdir repo-a
6 cd repo-a
7 cd repo-a
7 hg init
8 hg init
8
9
9 echo this is file a > a
10 echo this is file a > a
10 hg add a
11 hg add a
11 hg commit -m first -d '0 0'
12 hg commit -m first -d '0 0'
12
13
13 echo adding to file a >> a
14 echo adding to file a >> a
14 hg commit -m second -d '0 0'
15 hg commit -m second -d '0 0'
15
16
16 echo adding more to file a >> a
17 echo adding more to file a >> a
17 hg commit -m third -d '0 0'
18 hg commit -m third -d '0 0'
18
19
19 hg verify
20 hg verify
20
21
21 echo dumping revlog of file a to stdout:
22 echo
23 echo % dumping revlog of file a to stdout
22 python $CONTRIBDIR/dumprevlog .hg/store/data/a.i
24 python $CONTRIBDIR/dumprevlog .hg/store/data/a.i
23 echo dumprevlog done
25 echo % dumprevlog done
24
26
25 # dump all revlogs to file repo.dump
27 echo
28 echo % dump all revlogs to file repo.dump
26 find .hg/store -name "*.i" | sort | xargs python $CONTRIBDIR/dumprevlog > ../repo.dump
29 find .hg/store -name "*.i" | sort | xargs python $CONTRIBDIR/dumprevlog > ../repo.dump
27
30
28 cd ..
31 cd ..
29
32
30 mkdir repo-b
33 mkdir repo-b
31 cd repo-b
34 cd repo-b
32 hg init
35 hg init
33
36
34 echo undumping:
37 echo
38 echo % undumping into repo-b
35 python $CONTRIBDIR/undumprevlog < ../repo.dump
39 python $CONTRIBDIR/undumprevlog < ../repo.dump
36 echo undumping done
40 echo % undumping done
41
42 cd ..
37
43
44 echo
45 echo % clone --pull repo-b repo-c to rebuild fncache
46 hg clone --pull -U repo-b repo-c
47
48 cd repo-c
49
50 echo
51 echo % verify repo-c
38 hg verify
52 hg verify
39
53
40 cd ..
54 cd ..
41
55
42 echo comparing repos:
56 echo
43 hg -R repo-b incoming repo-a
57 echo % comparing repos
44 hg -R repo-a incoming repo-b
58 hg -R repo-c incoming repo-a
45 echo comparing done
59 hg -R repo-a incoming repo-c
46
60
47 exit 0
61 exit 0
@@ -1,53 +1,67 b''
1 % prepare repo-a
1 checking changesets
2 checking changesets
2 checking manifests
3 checking manifests
3 crosschecking files in changesets and manifests
4 crosschecking files in changesets and manifests
4 checking files
5 checking files
5 1 files, 3 changesets, 3 total revisions
6 1 files, 3 changesets, 3 total revisions
6 dumping revlog of file a to stdout:
7
8 % dumping revlog of file a to stdout
7 file: .hg/store/data/a.i
9 file: .hg/store/data/a.i
8 node: 183d2312b35066fb6b3b449b84efc370d50993d0
10 node: 183d2312b35066fb6b3b449b84efc370d50993d0
9 linkrev: 0
11 linkrev: 0
10 parents: 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000
12 parents: 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000
11 length: 15
13 length: 15
12 -start-
14 -start-
13 this is file a
15 this is file a
14
16
15 -end-
17 -end-
16 node: b1047953b6e6b633c0d8197eaa5116fbdfd3095b
18 node: b1047953b6e6b633c0d8197eaa5116fbdfd3095b
17 linkrev: 1
19 linkrev: 1
18 parents: 183d2312b35066fb6b3b449b84efc370d50993d0 0000000000000000000000000000000000000000
20 parents: 183d2312b35066fb6b3b449b84efc370d50993d0 0000000000000000000000000000000000000000
19 length: 32
21 length: 32
20 -start-
22 -start-
21 this is file a
23 this is file a
22 adding to file a
24 adding to file a
23
25
24 -end-
26 -end-
25 node: 8c4fd1f7129b8cdec6c7f58bf48fb5237a4030c1
27 node: 8c4fd1f7129b8cdec6c7f58bf48fb5237a4030c1
26 linkrev: 2
28 linkrev: 2
27 parents: b1047953b6e6b633c0d8197eaa5116fbdfd3095b 0000000000000000000000000000000000000000
29 parents: b1047953b6e6b633c0d8197eaa5116fbdfd3095b 0000000000000000000000000000000000000000
28 length: 54
30 length: 54
29 -start-
31 -start-
30 this is file a
32 this is file a
31 adding to file a
33 adding to file a
32 adding more to file a
34 adding more to file a
33
35
34 -end-
36 -end-
35 dumprevlog done
37 % dumprevlog done
36 undumping:
38
39 % dump all revlogs to file repo.dump
40
41 % undumping into repo-b
37 .hg/store/00changelog.i
42 .hg/store/00changelog.i
38 .hg/store/00manifest.i
43 .hg/store/00manifest.i
39 .hg/store/data/a.i
44 .hg/store/data/a.i
40 undumping done
45 % undumping done
46
47 % clone --pull repo-b repo-c to rebuild fncache
48 requesting all changes
49 adding changesets
50 adding manifests
51 adding file changes
52 added 3 changesets with 3 changes to 1 files
53
54 % verify repo-c
41 checking changesets
55 checking changesets
42 checking manifests
56 checking manifests
43 crosschecking files in changesets and manifests
57 crosschecking files in changesets and manifests
44 checking files
58 checking files
45 1 files, 3 changesets, 3 total revisions
59 1 files, 3 changesets, 3 total revisions
46 comparing repos:
60
61 % comparing repos
47 comparing with repo-a
62 comparing with repo-a
48 searching for changes
63 searching for changes
49 no changes found
64 no changes found
50 comparing with repo-b
65 comparing with repo-c
51 searching for changes
66 searching for changes
52 no changes found
67 no changes found
53 comparing done
@@ -1,54 +1,56 b''
1 % before commit
1 % before commit
2 % store can be written by the group, other files cannot
2 % store can be written by the group, other files cannot
3 % store is setgid
3 % store is setgid
4 00700 ./.hg/
4 00700 ./.hg/
5 00600 ./.hg/00changelog.i
5 00600 ./.hg/00changelog.i
6 00600 ./.hg/requires
6 00600 ./.hg/requires
7 00770 ./.hg/store/
7 00770 ./.hg/store/
8
8
9 % after commit
9 % after commit
10 % working dir files can only be written by the owner
10 % working dir files can only be written by the owner
11 % files created in .hg can be written by the group
11 % files created in .hg can be written by the group
12 % (in particular, store/**, dirstate, branch cache file, undo files)
12 % (in particular, store/**, dirstate, branch cache file, undo files)
13 % new directories are setgid
13 % new directories are setgid
14 00700 ./.hg/
14 00700 ./.hg/
15 00600 ./.hg/00changelog.i
15 00600 ./.hg/00changelog.i
16 00660 ./.hg/dirstate
16 00660 ./.hg/dirstate
17 00600 ./.hg/requires
17 00600 ./.hg/requires
18 00770 ./.hg/store/
18 00770 ./.hg/store/
19 00660 ./.hg/store/00changelog.i
19 00660 ./.hg/store/00changelog.i
20 00660 ./.hg/store/00manifest.i
20 00660 ./.hg/store/00manifest.i
21 00770 ./.hg/store/data/
21 00770 ./.hg/store/data/
22 00770 ./.hg/store/data/dir/
22 00770 ./.hg/store/data/dir/
23 00660 ./.hg/store/data/dir/bar.i
23 00660 ./.hg/store/data/dir/bar.i
24 00660 ./.hg/store/data/foo.i
24 00660 ./.hg/store/data/foo.i
25 00660 ./.hg/store/fncache
25 00660 ./.hg/store/undo
26 00660 ./.hg/store/undo
26 00660 ./.hg/undo.branch
27 00660 ./.hg/undo.branch
27 00660 ./.hg/undo.dirstate
28 00660 ./.hg/undo.dirstate
28 00700 ./dir/
29 00700 ./dir/
29 00600 ./dir/bar
30 00600 ./dir/bar
30 00600 ./foo
31 00600 ./foo
31
32
32 % before push
33 % before push
33 % group can write everything
34 % group can write everything
34 00770 ../push/.hg/
35 00770 ../push/.hg/
35 00660 ../push/.hg/00changelog.i
36 00660 ../push/.hg/00changelog.i
36 00660 ../push/.hg/requires
37 00660 ../push/.hg/requires
37 00770 ../push/.hg/store/
38 00770 ../push/.hg/store/
38
39
39 % after push
40 % after push
40 % group can still write everything
41 % group can still write everything
41 00770 ../push/.hg/
42 00770 ../push/.hg/
42 00660 ../push/.hg/00changelog.i
43 00660 ../push/.hg/00changelog.i
43 00660 ../push/.hg/branch.cache
44 00660 ../push/.hg/branch.cache
44 00660 ../push/.hg/requires
45 00660 ../push/.hg/requires
45 00770 ../push/.hg/store/
46 00770 ../push/.hg/store/
46 00660 ../push/.hg/store/00changelog.i
47 00660 ../push/.hg/store/00changelog.i
47 00660 ../push/.hg/store/00manifest.i
48 00660 ../push/.hg/store/00manifest.i
48 00770 ../push/.hg/store/data/
49 00770 ../push/.hg/store/data/
49 00770 ../push/.hg/store/data/dir/
50 00770 ../push/.hg/store/data/dir/
50 00660 ../push/.hg/store/data/dir/bar.i
51 00660 ../push/.hg/store/data/dir/bar.i
51 00660 ../push/.hg/store/data/foo.i
52 00660 ../push/.hg/store/data/foo.i
53 00660 ../push/.hg/store/fncache
52 00660 ../push/.hg/store/undo
54 00660 ../push/.hg/store/undo
53 00660 ../push/.hg/undo.branch
55 00660 ../push/.hg/undo.branch
54 00660 ../push/.hg/undo.dirstate
56 00660 ../push/.hg/undo.dirstate
@@ -1,69 +1,70 b''
1 # creating 'local'
1 # creating 'local'
2 store created
2 store created
3 00changelog.i created
3 00changelog.i created
4 revlogv1
4 revlogv1
5 store
5 store
6 fncache
6 adding foo
7 adding foo
7 # creating repo with old format
8 # creating repo with old format
8 revlogv1
9 revlogv1
9 #test failure
10 #test failure
10 abort: repository local already exists!
11 abort: repository local already exists!
11 # init+push to remote2
12 # init+push to remote2
12 comparing with local
13 comparing with local
13 changeset: 0:c4e059d443be
14 changeset: 0:c4e059d443be
14 tag: tip
15 tag: tip
15 user: test
16 user: test
16 date: Mon Jan 12 13:46:40 1970 +0000
17 date: Mon Jan 12 13:46:40 1970 +0000
17 summary: init
18 summary: init
18
19
19 pushing to ssh://user@dummy/remote2
20 pushing to ssh://user@dummy/remote2
20 searching for changes
21 searching for changes
21 remote: adding changesets
22 remote: adding changesets
22 remote: adding manifests
23 remote: adding manifests
23 remote: adding file changes
24 remote: adding file changes
24 remote: added 1 changesets with 1 changes to 1 files
25 remote: added 1 changesets with 1 changes to 1 files
25 # clone to remote1
26 # clone to remote1
26 searching for changes
27 searching for changes
27 remote: adding changesets
28 remote: adding changesets
28 remote: adding manifests
29 remote: adding manifests
29 remote: adding file changes
30 remote: adding file changes
30 remote: added 1 changesets with 1 changes to 1 files
31 remote: added 1 changesets with 1 changes to 1 files
31 # init to existing repo
32 # init to existing repo
32 abort: repository remote1 already exists!
33 abort: repository remote1 already exists!
33 abort: could not create remote repo!
34 abort: could not create remote repo!
34 # clone to existing repo
35 # clone to existing repo
35 abort: repository remote1 already exists!
36 abort: repository remote1 already exists!
36 abort: could not create remote repo!
37 abort: could not create remote repo!
37 # output of dummyssh
38 # output of dummyssh
38 Got arguments 1:user@dummy 2:hg init remote2
39 Got arguments 1:user@dummy 2:hg init remote2
39 Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio
40 Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio
40 Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio
41 Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio
41 Got arguments 1:user@dummy 2:hg init remote1
42 Got arguments 1:user@dummy 2:hg init remote1
42 Got arguments 1:user@dummy 2:hg -R remote1 serve --stdio
43 Got arguments 1:user@dummy 2:hg -R remote1 serve --stdio
43 Got arguments 1:user@dummy 2:hg init remote1
44 Got arguments 1:user@dummy 2:hg init remote1
44 Got arguments 1:user@dummy 2:hg init remote1
45 Got arguments 1:user@dummy 2:hg init remote1
45 # comparing repositories
46 # comparing repositories
46 0:c4e059d443be
47 0:c4e059d443be
47 0:c4e059d443be
48 0:c4e059d443be
48 0:c4e059d443be
49 0:c4e059d443be
49 # check names for repositories (clashes with URL schemes, special chars)
50 # check names for repositories (clashes with URL schemes, special chars)
50 # hg init "bundle"
51 # hg init "bundle"
51 ok
52 ok
52 # hg init "file"
53 # hg init "file"
53 ok
54 ok
54 # hg init "hg"
55 # hg init "hg"
55 ok
56 ok
56 # hg init "http"
57 # hg init "http"
57 ok
58 ok
58 # hg init "https"
59 # hg init "https"
59 ok
60 ok
60 # hg init "old-http"
61 # hg init "old-http"
61 ok
62 ok
62 # hg init "ssh"
63 # hg init "ssh"
63 ok
64 ok
64 # hg init "static-http"
65 # hg init "static-http"
65 ok
66 ok
66 # hg init " "
67 # hg init " "
67 ok
68 ok
68 # hg init "with space"
69 # hg init "with space"
69 ok
70 ok
@@ -1,34 +1,31 b''
1 % prepare repo
1 % prepare repo
2 adding FOO.txt
2 adding FOO.txt
3 adding QUICK.txt
3 adding QUICK.txt
4 adding bar.txt
4 adding bar.txt
5
5
6 % verify
6 % verify
7 checking changesets
7 checking changesets
8 checking manifests
8 checking manifests
9 crosschecking files in changesets and manifests
9 crosschecking files in changesets and manifests
10 checking files
10 checking files
11 3 files, 1 changesets, 3 total revisions
11 3 files, 1 changesets, 3 total revisions
12
12
13 % introduce some bugs in repo
13 % introduce some bugs in repo
14
14
15 % verify
15 % verify
16 checking changesets
16 checking changesets
17 checking manifests
17 checking manifests
18 crosschecking files in changesets and manifests
18 crosschecking files in changesets and manifests
19 checking files
19 checking files
20 ?: cannot decode filename 'data/X_f_o_o.txt.i'
21 data/FOO.txt.i@0: missing revlog!
20 data/FOO.txt.i@0: missing revlog!
22 0: empty or missing FOO.txt
21 0: empty or missing FOO.txt
23 FOO.txt@0: f62022d3d590 in manifests not found
22 FOO.txt@0: f62022d3d590 in manifests not found
24 data/QUICK.txt.i@0: missing revlog!
23 data/QUICK.txt.i@0: missing revlog!
25 0: empty or missing QUICK.txt
24 0: empty or missing QUICK.txt
26 QUICK.txt@0: 88b857db8eba in manifests not found
25 QUICK.txt@0: 88b857db8eba in manifests not found
27 data/bar.txt.i@0: missing revlog!
26 data/bar.txt.i@0: missing revlog!
28 0: empty or missing bar.txt
27 0: empty or missing bar.txt
29 bar.txt@0: 256559129457 in manifests not found
28 bar.txt@0: 256559129457 in manifests not found
30 warning: orphan revlog 'data/xbar.txt.i'
31 3 files, 1 changesets, 0 total revisions
29 3 files, 1 changesets, 0 total revisions
32 1 warnings encountered!
30 9 integrity errors encountered!
33 10 integrity errors encountered!
34 (first damaged changeset appears to be 0)
31 (first damaged changeset appears to be 0)
General Comments 0
You need to be logged in to leave comments. Login now