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