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