##// END OF EJS Templates
discovery: drop findoutgoing and simplify findcommonincoming's api...
Peter Arrenbrecht -
r14073:72c84f24 default
parent child Browse files
Show More
@@ -238,15 +238,14 def patchbomb(ui, repo, *revs, **opts):
238 238 dest = ui.expandpath(dest or 'default-push', dest or 'default')
239 239 dest, branches = hg.parseurl(dest)
240 240 revs, checkout = hg.addbranchrevs(repo, repo, branches, revs)
241 if revs:
242 revs = [repo.lookup(rev) for rev in revs]
243 241 other = hg.repository(hg.remoteui(repo, opts), dest)
244 242 ui.status(_('comparing with %s\n') % url.hidepassword(dest))
245 o = discovery.findoutgoing(repo, other)
243 common, _anyinc, _heads = discovery.findcommonincoming(repo, other)
244 nodes = revs and map(repo.lookup, revs) or revs
245 o = repo.changelog.findmissing(common, heads=nodes)
246 246 if not o:
247 247 ui.status(_("no changes found\n"))
248 248 return []
249 o = repo.changelog.nodesbetween(o, revs)[0]
250 249 return [str(repo.changelog.rev(r)) for r in o]
251 250
252 251 def getpatches(revs):
@@ -494,10 +494,10 def transplant(ui, repo, *revs, **opts):
494 494 and then resume where you left off by calling :hg:`transplant
495 495 --continue/-c`.
496 496 '''
497 def incwalk(repo, incoming, branches, match=util.always):
497 def incwalk(repo, commmon, branches, match=util.always):
498 498 if not branches:
499 499 branches = None
500 for node in repo.changelog.nodesbetween(incoming, branches)[0]:
500 for node in repo.changelog.findmissing(common, branches):
501 501 if match(node):
502 502 yield node
503 503
@@ -552,7 +552,7 def transplant(ui, repo, *revs, **opts):
552 552 if source:
553 553 sourcerepo = ui.expandpath(source)
554 554 source = hg.repository(ui, sourcerepo)
555 source, common, incoming, bundle = bundlerepo.getremotechanges(ui, repo,
555 source, common, anyinc, bundle = bundlerepo.getremotechanges(ui, repo,
556 556 source, force=True)
557 557 else:
558 558 source = repo
@@ -577,7 +577,7 def transplant(ui, repo, *revs, **opts):
577 577 revmap[int(r)] = source.lookup(r)
578 578 elif opts.get('all') or not merges:
579 579 if source != repo:
580 alltransplants = incwalk(source, incoming, branches,
580 alltransplants = incwalk(source, common, branches,
581 581 match=matchfn)
582 582 else:
583 583 alltransplants = transplantwalk(source, p1, branches,
@@ -287,9 +287,8 def instance(ui, path, create):
287 287 return bundlerepository(ui, repopath, bundlename)
288 288
289 289 def getremotechanges(ui, repo, other, revs=None, bundlename=None,
290 force=False, usecommon=False):
291 tmp = discovery.findcommonincoming(repo, other, heads=revs, force=force,
292 commononly=usecommon)
290 force=False):
291 tmp = discovery.findcommonincoming(repo, other, heads=revs, force=force)
293 292 common, incoming, rheads = tmp
294 293 if not incoming:
295 294 try:
@@ -305,7 +304,7 def getremotechanges(ui, repo, other, re
305 304 if revs is None and other.capable('changegroupsubset'):
306 305 revs = rheads
307 306
308 if usecommon:
307 if other.capable('getbundle'):
309 308 cg = other.getbundle('incoming', common=common, heads=revs)
310 309 elif revs is None:
311 310 cg = other.changegroup(incoming, "incoming")
@@ -696,49 +696,21 def bundle(ui, repo, fname, dest=None, *
696 696 if dest:
697 697 raise util.Abort(_("--base is incompatible with specifying "
698 698 "a destination"))
699 base = [repo.lookup(rev) for rev in base]
700 # create the right base
701 # XXX: nodesbetween / changegroup* should be "fixed" instead
702 o = []
703 has = set((nullid,))
704 for n in base:
705 has.update(repo.changelog.reachable(n))
706 if revs:
707 revs = [repo.lookup(rev) for rev in revs]
708 visit = revs[:]
709 has.difference_update(visit)
710 else:
711 visit = repo.changelog.heads()
712 seen = {}
713 while visit:
714 n = visit.pop(0)
715 parents = [p for p in repo.changelog.parents(n) if p not in has]
716 if len(parents) == 0:
717 if n not in has:
718 o.append(n)
719 else:
720 for p in parents:
721 if p not in seen:
722 seen[p] = 1
723 visit.append(p)
699 common = [repo.lookup(rev) for rev in base]
724 700 else:
725 701 dest = ui.expandpath(dest or 'default-push', dest or 'default')
726 702 dest, branches = hg.parseurl(dest, opts.get('branch'))
727 703 other = hg.repository(hg.remoteui(repo, opts), dest)
728 704 revs, checkout = hg.addbranchrevs(repo, other, branches, revs)
729 if revs:
730 revs = [repo.lookup(rev) for rev in revs]
731 o = discovery.findoutgoing(repo, other, force=opts.get('force'))
732
733 if not o:
705 inc = discovery.findcommonincoming(repo, other, force=opts.get('force'))
706 common, _anyinc, _heads = inc
707
708 nodes = revs and map(repo.lookup, revs) or revs
709 cg = repo.getbundle('bundle', common=common, heads=nodes)
710 if not cg:
734 711 ui.status(_("no changes found\n"))
735 712 return 1
736 713
737 if revs:
738 cg = repo.changegroupsubset(o, revs, 'bundle')
739 else:
740 cg = repo.changegroup(o, 'bundle')
741
742 714 bundletype = opts.get('type', 'bzip2').lower()
743 715 btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
744 716 bundletype = btypes.get(bundletype)
@@ -3959,9 +3931,9 def summary(ui, repo, **opts):
3959 3931 other = hg.repository(hg.remoteui(repo, {}), dest)
3960 3932 ui.debug('comparing with %s\n' % url.hidepassword(dest))
3961 3933 repo.ui.pushbuffer()
3962 o = discovery.findoutgoing(repo, other)
3934 common, _anyinc, _heads = discovery.findcommonincoming(repo, other)
3963 3935 repo.ui.popbuffer()
3964 o = repo.changelog.nodesbetween(o, None)[0]
3936 o = repo.changelog.findmissing(common=common)
3965 3937 if o:
3966 3938 t.append(_('%d outgoing') % len(o))
3967 3939 if 'bookmarks' in other.listkeys('namespaces'):
@@ -9,14 +9,19 from node import nullid, short
9 9 from i18n import _
10 10 import util, error
11 11
12 def findcommonincoming(repo, remote, heads=None, force=False, commononly=False):
13 """Return a tuple (common, missing, heads) used to identify missing nodes
14 from remote. "missing" is either a boolean indicating if any nodes are missing
15 (when commononly=True), or else a list of the root nodes of the missing set.
12 def findcommonincoming(repo, remote, heads=None, force=False):
13 """Return a tuple (common, anyincoming, heads) used to identify the common
14 subset of nodes between repo and remote.
16 15
17 If a list of heads is specified, return only nodes which are heads
18 or ancestors of these heads.
16 "common" is a list of (at least) the heads of the common subset.
17 "anyincoming" is testable as a boolean indicating if any nodes are missing
18 locally. If remote does not support getbundle, this actually is a list of
19 roots of the nodes that would be incoming, to be supplied to
20 changegroupsubset. No code except for pull should be relying on this fact
21 any longer.
22 "heads" is either the supplied heads, or else the remote's heads.
19 23 """
24
20 25 m = repo.changelog.nodemap
21 26 search = []
22 27 fetch = set()
@@ -37,7 +42,7 def findcommonincoming(repo, remote, hea
37 42 # and start by examining the heads
38 43 repo.ui.status(_("searching for changes\n"))
39 44
40 if commononly:
45 if remote.capable('getbundle'):
41 46 myheads = repo.heads()
42 47 known = remote.known(myheads)
43 48 if util.all(known):
@@ -155,45 +160,6 def findcommonincoming(repo, remote, hea
155 160
156 161 return base, list(fetch), heads
157 162
158 def findoutgoing(repo, remote, base=None, remoteheads=None, force=False):
159 """Return list of nodes that are roots of subsets not in remote
160
161 If base dict is specified, assume that these nodes and their parents
162 exist on the remote side.
163 If remotehead is specified, assume it is the list of the heads from
164 the remote repository.
165 """
166 if base is None:
167 base = findcommonincoming(repo, remote, heads=remoteheads,
168 force=force)[0]
169 else:
170 base = list(base)
171
172 repo.ui.debug("common changesets up to "
173 + " ".join(map(short, base)) + "\n")
174
175 remain = set(repo.changelog.nodemap)
176
177 # prune everything remote has from the tree
178 remain.remove(nullid)
179 remove = base
180 while remove:
181 n = remove.pop(0)
182 if n in remain:
183 remain.remove(n)
184 for p in repo.changelog.parents(n):
185 remove.append(p)
186
187 # find every node whose parents have been pruned
188 subset = []
189 # find every remote head that will get new children
190 for n in remain:
191 p1, p2 = repo.changelog.parents(n)
192 if p1 not in remain and p2 not in remain:
193 subset.append(n)
194
195 return subset
196
197 163 def prepush(repo, remote, force, revs, newbranch):
198 164 '''Analyze the local and remote repositories and determine which
199 165 changesets need to be pushed to the remote. Return value depends
@@ -209,14 +175,13 def prepush(repo, remote, force, revs, n
209 175 successive changegroup chunks ready to be sent over the wire and
210 176 remoteheads is the list of remote heads.'''
211 177 remoteheads = remote.heads()
212 common, inc, rheads = findcommonincoming(repo, remote, heads=remoteheads,
178 common, inc, _rheads = findcommonincoming(repo, remote, heads=remoteheads,
213 179 force=force)
214 180
215 181 cl = repo.changelog
216 update = findoutgoing(repo, remote, common, remoteheads)
217 outg, bases, heads = cl.nodesbetween(update, revs)
182 outg = cl.findmissing(common, revs)
218 183
219 if not bases:
184 if not outg:
220 185 repo.ui.status(_("no changes found\n"))
221 186 return None, 1
222 187
@@ -317,8 +282,7 def prepush(repo, remote, force, revs, n
317 282
318 283 if revs is None:
319 284 # use the fast path, no race possible on push
320 nodes = repo.changelog.findmissing(common)
321 cg = repo._changegroup(nodes, 'push')
285 cg = repo._changegroup(outg, 'push')
322 286 else:
323 cg = repo.changegroupsubset(update, revs, 'push')
287 cg = repo.getbundle('push', heads=revs, common=common)
324 288 return cg, remoteheads
@@ -426,19 +426,14 def _incoming(displaychlist, subreporecu
426 426
427 427 if revs:
428 428 revs = [other.lookup(rev) for rev in revs]
429 usecommon = other.capable('getbundle')
430 other, common, incoming, bundle = bundlerepo.getremotechanges(ui, repo, other,
431 revs, opts["bundle"], opts["force"],
432 usecommon=usecommon)
433 if not incoming:
429 other, common, anyinc, bundle = bundlerepo.getremotechanges(ui, repo, other,
430 revs, opts["bundle"], opts["force"])
431 if not anyinc:
434 432 ui.status(_("no changes found\n"))
435 433 return subreporecurse()
436 434
437 435 try:
438 if usecommon:
439 436 chlist = other.changelog.findmissing(common, revs)
440 else:
441 chlist = other.changelog.nodesbetween(incoming, revs)[0]
442 437 displayer = cmdutil.show_changeset(ui, other, opts, buffered)
443 438
444 439 # XXX once graphlog extension makes it into core,
@@ -488,12 +483,13 def _outgoing(ui, repo, dest, opts):
488 483 revs = [repo.lookup(rev) for rev in revs]
489 484
490 485 other = repository(remoteui(repo, opts), dest)
491 o = discovery.findoutgoing(repo, other, force=opts.get('force'))
486 inc = discovery.findcommonincoming(repo, other, force=opts.get('force'))
487 common, _anyinc, _heads = inc
488 o = repo.changelog.findmissing(common, revs)
492 489 if not o:
493 490 ui.status(_("no changes found\n"))
494 491 return None
495
496 return repo.changelog.nodesbetween(o, revs)[0]
492 return o
497 493
498 494 def outgoing(ui, repo, dest, opts):
499 495 def recurse():
@@ -1327,9 +1327,8 class localrepository(repo.repository):
1327 1327 def pull(self, remote, heads=None, force=False):
1328 1328 lock = self.lock()
1329 1329 try:
1330 usecommon = remote.capable('getbundle')
1331 1330 tmp = discovery.findcommonincoming(self, remote, heads=heads,
1332 force=force, commononly=usecommon)
1331 force=force)
1333 1332 common, fetch, rheads = tmp
1334 1333 if not fetch:
1335 1334 self.ui.status(_("no changes found\n"))
@@ -1341,7 +1340,7 class localrepository(repo.repository):
1341 1340 # issue1320, avoid a race if remote changed after discovery
1342 1341 heads = rheads
1343 1342
1344 if usecommon:
1343 if remote.capable('getbundle'):
1345 1344 cg = remote.getbundle('pull', common=common,
1346 1345 heads=heads or rheads)
1347 1346 elif heads is None:
@@ -1475,6 +1474,8 class localrepository(repo.repository):
1475 1474 if not heads:
1476 1475 heads = cl.heads()
1477 1476 common, missing = cl.findcommonmissing(common, heads)
1477 if not missing:
1478 return None
1478 1479 return self._changegroupsubset(common, missing, heads, source)
1479 1480
1480 1481 def _changegroupsubset(self, commonrevs, csets, heads, source):
@@ -554,10 +554,10 def outgoing(repo, subset, x):
554 554 revs = [repo.lookup(rev) for rev in revs]
555 555 other = hg.repository(hg.remoteui(repo, {}), dest)
556 556 repo.ui.pushbuffer()
557 o = discovery.findoutgoing(repo, other)
557 common, _anyinc, _heads = discovery.findcommonincoming(repo, other)
558 558 repo.ui.popbuffer()
559 559 cl = repo.changelog
560 o = set([cl.rev(r) for r in repo.changelog.nodesbetween(o, revs)[0]])
560 o = set([cl.rev(r) for r in repo.changelog.findmissing(common, revs)])
561 561 return [r for r in subset if r in o]
562 562
563 563 def p1(repo, subset, x):
@@ -83,7 +83,6 Extension disabled for lack of a hook
83 83 """
84 84 pushing to ../b
85 85 searching for changes
86 common changesets up to 6675d58eff77
87 86 3 changesets found
88 87 list of changesets:
89 88 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -137,7 +136,6 Extension disabled for lack of acl.sourc
137 136 """
138 137 pushing to ../b
139 138 searching for changes
140 common changesets up to 6675d58eff77
141 139 invalidating branch cache (tip differs)
142 140 3 changesets found
143 141 list of changesets:
@@ -195,7 +193,6 No [acl.allow]/[acl.deny]
195 193 """
196 194 pushing to ../b
197 195 searching for changes
198 common changesets up to 6675d58eff77
199 196 invalidating branch cache (tip differs)
200 197 3 changesets found
201 198 list of changesets:
@@ -262,7 +259,6 Empty [acl.allow]
262 259 """
263 260 pushing to ../b
264 261 searching for changes
265 common changesets up to 6675d58eff77
266 262 invalidating branch cache (tip differs)
267 263 3 changesets found
268 264 list of changesets:
@@ -327,7 +323,6 fred is allowed inside foo/
327 323 """
328 324 pushing to ../b
329 325 searching for changes
330 common changesets up to 6675d58eff77
331 326 3 changesets found
332 327 list of changesets:
333 328 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -396,7 +391,6 Empty [acl.deny]
396 391 """
397 392 pushing to ../b
398 393 searching for changes
399 common changesets up to 6675d58eff77
400 394 3 changesets found
401 395 list of changesets:
402 396 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -462,7 +456,6 fred is allowed inside foo/, but not foo
462 456 """
463 457 pushing to ../b
464 458 searching for changes
465 common changesets up to 6675d58eff77
466 459 3 changesets found
467 460 list of changesets:
468 461 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -533,7 +526,6 fred is allowed inside foo/, but not foo
533 526 """
534 527 pushing to ../b
535 528 searching for changes
536 common changesets up to 6675d58eff77
537 529 3 changesets found
538 530 list of changesets:
539 531 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -601,7 +593,6 fred is allowed inside foo/, but not foo
601 593 """
602 594 pushing to ../b
603 595 searching for changes
604 common changesets up to 6675d58eff77
605 596 3 changesets found
606 597 list of changesets:
607 598 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -671,7 +662,6 barney is allowed everywhere
671 662 """
672 663 pushing to ../b
673 664 searching for changes
674 common changesets up to 6675d58eff77
675 665 3 changesets found
676 666 list of changesets:
677 667 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -744,7 +734,6 wilma can change files with a .txt exten
744 734 """
745 735 pushing to ../b
746 736 searching for changes
747 common changesets up to 6675d58eff77
748 737 invalidating branch cache (tip differs)
749 738 3 changesets found
750 739 list of changesets:
@@ -822,7 +811,6 file specified by acl.config does not ex
822 811 """
823 812 pushing to ../b
824 813 searching for changes
825 common changesets up to 6675d58eff77
826 814 3 changesets found
827 815 list of changesets:
828 816 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -893,7 +881,6 betty is allowed inside foo/ by a acl.co
893 881 """
894 882 pushing to ../b
895 883 searching for changes
896 common changesets up to 6675d58eff77
897 884 3 changesets found
898 885 list of changesets:
899 886 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -976,7 +963,6 acl.config can set only [acl.allow]/[acl
976 963 """
977 964 pushing to ../b
978 965 searching for changes
979 common changesets up to 6675d58eff77
980 966 3 changesets found
981 967 list of changesets:
982 968 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -1050,7 +1036,6 fred is always allowed
1050 1036 """
1051 1037 pushing to ../b
1052 1038 searching for changes
1053 common changesets up to 6675d58eff77
1054 1039 invalidating branch cache (tip differs)
1055 1040 3 changesets found
1056 1041 list of changesets:
@@ -1121,7 +1106,6 no one is allowed inside foo/Bar/
1121 1106 """
1122 1107 pushing to ../b
1123 1108 searching for changes
1124 common changesets up to 6675d58eff77
1125 1109 invalidating branch cache (tip differs)
1126 1110 3 changesets found
1127 1111 list of changesets:
@@ -1195,7 +1179,6 OS-level groups
1195 1179 """
1196 1180 pushing to ../b
1197 1181 searching for changes
1198 common changesets up to 6675d58eff77
1199 1182 3 changesets found
1200 1183 list of changesets:
1201 1184 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -1266,7 +1249,6 OS-level groups
1266 1249 """
1267 1250 pushing to ../b
1268 1251 searching for changes
1269 common changesets up to 6675d58eff77
1270 1252 invalidating branch cache (tip differs)
1271 1253 3 changesets found
1272 1254 list of changesets:
@@ -1378,7 +1360,6 No branch acls specified
1378 1360 """
1379 1361 pushing to ../b
1380 1362 searching for changes
1381 common changesets up to 07e028174695
1382 1363 4 changesets found
1383 1364 list of changesets:
1384 1365 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -1456,7 +1437,6 Branch acl deny test
1456 1437 """
1457 1438 pushing to ../b
1458 1439 searching for changes
1459 common changesets up to 07e028174695
1460 1440 invalidating branch cache (tip differs)
1461 1441 4 changesets found
1462 1442 list of changesets:
@@ -1533,7 +1513,6 Branch acl empty allow test
1533 1513 """
1534 1514 pushing to ../b
1535 1515 searching for changes
1536 common changesets up to 07e028174695
1537 1516 4 changesets found
1538 1517 list of changesets:
1539 1518 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -1605,7 +1584,6 Branch acl allow other
1605 1584 """
1606 1585 pushing to ../b
1607 1586 searching for changes
1608 common changesets up to 07e028174695
1609 1587 4 changesets found
1610 1588 list of changesets:
1611 1589 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -1671,7 +1649,6 Branch acl allow other
1671 1649 """
1672 1650 pushing to ../b
1673 1651 searching for changes
1674 common changesets up to 07e028174695
1675 1652 4 changesets found
1676 1653 list of changesets:
1677 1654 ef1ea85a6374b77d6da9dcda9541f498f2d17df7
@@ -1754,7 +1731,6 push foobar into the remote
1754 1731 """
1755 1732 pushing to ../b
1756 1733 searching for changes
1757 common changesets up to 07e028174695
1758 1734 invalidating branch cache (tip differs)
1759 1735 4 changesets found
1760 1736 list of changesets:
@@ -1837,7 +1813,6 Branch acl conflicting deny
1837 1813 """
1838 1814 pushing to ../b
1839 1815 searching for changes
1840 common changesets up to 07e028174695
1841 1816 invalidating branch cache (tip differs)
1842 1817 4 changesets found
1843 1818 list of changesets:
@@ -231,7 +231,8 empty bundle
231 231 issue76 msg2163
232 232
233 233 $ hg -R test bundle --base 3 -r 3 -r 3 test-bundle-cset-3.hg
234 1 changesets found
234 no changes found
235 [1]
235 236
236 237 Issue1910: 'hg bundle --base $head' does not exclude $head from
237 238 result
@@ -562,7 +562,6 bundle single branch
562 562
563 563 $ hg bundle bundle.hg part --debug
564 564 searching for changes
565 common changesets up to c0025332f9ed
566 565 2 changesets found
567 566 list of changesets:
568 567 d2ae7f538514cd87c17547b0de4cea71fe1af9fb
@@ -39,7 +39,6
39 39 found new branch changeset 1c9246a22a0a
40 40 found new changesets starting at 1c9246a22a0a
41 41 1 total queries
42 common changesets up to d8d565842d04
43 42 new remote heads on branch 'default'
44 43 new remote head 1e108cc5548c
45 44 abort: push creates new remote heads on branch 'default'!
General Comments 0
You need to be logged in to leave comments. Login now