def findcommonoutgoing(repo, other, onlyheads=None, force=False, commoninc=None, portable=False): '''Return an outgoing instance to identify the nodes present in repo but not in other. If onlyheads is given, only nodes ancestral to nodes in onlyheads (inclusive) are included. If you already know the local repo's heads, passing them in onlyheads is faster than letting them be recomputed here. If commoninc is given, it must the the result of a prior call to findcommonincoming(repo, other, force) to avoid recomputing it here. If portable is given, compute more conservative common and missingheads, to make bundles created from the instance more portable.''' # declare an empty outgoing object to be filled later og = outgoing(repo.changelog, None, None) # get common set if not provided if commoninc is None: commoninc = findcommonincoming(repo, other, force=force) og.commonheads, _any, _hds = commoninc # compute outgoing if not repo._phaseroots[phases.secret]: og.missingheads = onlyheads or repo.heads() elif onlyheads is None: # use visible heads as it should be cached og.missingheads = phases.visibleheads(repo) og.excluded = [ctx.node() for ctx in repo.set('secret()')] else: # compute common, missing and exclude secret stuff sets = repo.changelog.findcommonmissing(og.commonheads, onlyheads) og._common, allmissing = sets og._missing = missing = [] og.excluded = excluded = [] for node in allmissing: if repo[node].phase() >= phases.secret: excluded.append(node) else: missing.append(node) if excluded: # update missing heads missingheads = phases.newheads(repo, onlyheads, excluded) else: missingheads = onlyheads og.missingheads = missingheads if portable: # recompute common and missingheads as if -r<rev> had been given for # each head of missing, and --base <rev> for each head of the proper # ancestors of missing og._computecommonmissing() cl = repo.changelog missingrevs = set(cl.rev(n) for n in og._missing) og._common = set(cl.ancestors(*missingrevs)) - missingrevs commonheads = set(og.commonheads) og.missingheads = [h for h in og.missingheads if h not in commonheads] return og
def findcommonoutgoing(repo, other, onlyheads=None, force=False, commoninc=None): '''Return an outgoing instance to identify the nodes present in repo but not in other. If onlyheads is given, only nodes ancestral to nodes in onlyheads (inclusive) are included. If you already know the local repo's heads, passing them in onlyheads is faster than letting them be recomputed here. If commoninc is given, it must the the result of a prior call to findcommonincoming(repo, other, force) to avoid recomputing it here.''' # declare an empty outgoing object to be filled later og = outgoing(repo.changelog, None, None) # get common set if not provided if commoninc is None: commoninc = findcommonincoming(repo, other, force=force) og.commonheads, _any, _hds = commoninc # compute outgoing if not repo._phaseroots[phases.secret]: og.missingheads = onlyheads or repo.heads() elif onlyheads is None: # use visible heads as it should be cached og.missingheads = phases.visibleheads(repo) og.excluded = [ctx.node() for ctx in repo.set('secret()')] else: # compute common, missing and exclude secret stuff sets = repo.changelog.findcommonmissing(og.commonheads, onlyheads) og._common, allmissing = sets og._missing = missing = [] og.excluded = excluded = [] for node in allmissing: if repo[node].phase() >= phases.secret: excluded.append(node) else: missing.append(node) if excluded: # update missing heads missingheads = phases.newheads(repo, onlyheads, excluded) else: missingheads = onlyheads og.missingheads = missingheads return og
def heads(repo, proto): h = phases.visibleheads(repo) return encodelist(h) + "\n"
def findcommonheads(ui, local, remote, initialsamplesize=100, fullsamplesize=200, abortwhenunrelated=True): '''Return a tuple (common, anyincoming, remoteheads) used to identify missing nodes from or in remote. shortcutlocal determines whether we try use direct access to localrepo if remote is actually local. ''' roundtrips = 0 cl = local.changelog dag = dagutil.revlogdag(cl) # early exit if we know all the specified remote heads already ui.debug("query 1; heads\n") roundtrips += 1 ownheads = dag.heads() sample = ownheads if remote.local(): # stopgap until we have a proper localpeer that supports batch() srvheadhashes = phases.visibleheads(remote) yesno = remote.known(dag.externalizeall(sample)) elif remote.capable('batch'): batch = remote.batch() srvheadhashesref = batch.heads() yesnoref = batch.known(dag.externalizeall(sample)) batch.submit() srvheadhashes = srvheadhashesref.value yesno = yesnoref.value else: # compatibitity with pre-batch, but post-known remotes during 1.9 devel srvheadhashes = remote.heads() sample = [] if cl.tip() == nullid: if srvheadhashes != [nullid]: return [nullid], True, srvheadhashes return [nullid], False, [] # start actual discovery (we note this before the next "if" for # compatibility reasons) ui.status(_("searching for changes\n")) srvheads = dag.internalizeall(srvheadhashes, filterunknown=True) if len(srvheads) == len(srvheadhashes): ui.debug("all remote heads known locally\n") return ( srvheadhashes, False, srvheadhashes, ) if sample and util.all(yesno): ui.note(_("all local heads known remotely\n")) ownheadhashes = dag.externalizeall(ownheads) return ( ownheadhashes, True, srvheadhashes, ) # full blown discovery undecided = dag.nodeset( ) # own nodes where I don't know if remote knows them common = set() # own nodes I know we both know missing = set() # own nodes I know remote lacks # treat remote heads (and maybe own heads) as a first implicit sample response common.update(dag.ancestorset(srvheads)) undecided.difference_update(common) full = False while undecided: if sample: commoninsample = set(n for i, n in enumerate(sample) if yesno[i]) common.update(dag.ancestorset(commoninsample, common)) missinginsample = [n for i, n in enumerate(sample) if not yesno[i]] missing.update(dag.descendantset(missinginsample, missing)) undecided.difference_update(missing) undecided.difference_update(common) if not undecided: break if full: ui.note(_("sampling from both directions\n")) sample = _takefullsample(dag, undecided, size=fullsamplesize) elif common: # use cheapish initial sample ui.debug("taking initial sample\n") sample = _takefullsample(dag, undecided, size=fullsamplesize) else: # use even cheaper initial sample ui.debug("taking quick initial sample\n") sample = _takequicksample(dag, undecided, size=initialsamplesize, initial=True) roundtrips += 1 ui.progress(_('searching'), roundtrips, unit=_('queries')) ui.debug("query %i; still undecided: %i, sample size is: %i\n" % (roundtrips, len(undecided), len(sample))) # indices between sample and externalized version must match sample = list(sample) yesno = remote.known(dag.externalizeall(sample)) full = True result = dag.headsetofconnecteds(common) ui.progress(_('searching'), None) ui.debug("%d total queries\n" % roundtrips) if not result and srvheadhashes != [nullid]: if abortwhenunrelated: raise util.Abort(_("repository is unrelated")) else: ui.warn(_("warning: repository is unrelated\n")) return ( set([nullid]), True, srvheadhashes, ) anyincoming = (srvheadhashes != [nullid]) return dag.externalizeall(result), anyincoming, srvheadhashes
def check_heads(): heads = phases.visibleheads(repo) heads_hash = util.sha1(''.join(sorted(heads))).digest() return (their_heads == ['force'] or their_heads == heads or their_heads == ['hashed', heads_hash])
def findcommonheads(ui, local, remote, initialsamplesize=100, fullsamplesize=200, abortwhenunrelated=True): """Return a tuple (common, anyincoming, remoteheads) used to identify missing nodes from or in remote. shortcutlocal determines whether we try use direct access to localrepo if remote is actually local. """ roundtrips = 0 cl = local.changelog dag = dagutil.revlogdag(cl) # early exit if we know all the specified remote heads already ui.debug("query 1; heads\n") roundtrips += 1 ownheads = dag.heads() sample = ownheads if remote.local(): # stopgap until we have a proper localpeer that supports batch() srvheadhashes = phases.visibleheads(remote) yesno = remote.known(dag.externalizeall(sample)) elif remote.capable("batch"): batch = remote.batch() srvheadhashesref = batch.heads() yesnoref = batch.known(dag.externalizeall(sample)) batch.submit() srvheadhashes = srvheadhashesref.value yesno = yesnoref.value else: # compatibitity with pre-batch, but post-known remotes during 1.9 devel srvheadhashes = remote.heads() sample = [] if cl.tip() == nullid: if srvheadhashes != [nullid]: return [nullid], True, srvheadhashes return [nullid], False, [] # start actual discovery (we note this before the next "if" for # compatibility reasons) ui.status(_("searching for changes\n")) srvheads = dag.internalizeall(srvheadhashes, filterunknown=True) if len(srvheads) == len(srvheadhashes): ui.debug("all remote heads known locally\n") return (srvheadhashes, False, srvheadhashes) if sample and util.all(yesno): ui.note(_("all local heads known remotely\n")) ownheadhashes = dag.externalizeall(ownheads) return (ownheadhashes, True, srvheadhashes) # full blown discovery undecided = dag.nodeset() # own nodes where I don't know if remote knows them common = set() # own nodes I know we both know missing = set() # own nodes I know remote lacks # treat remote heads (and maybe own heads) as a first implicit sample response common.update(dag.ancestorset(srvheads)) undecided.difference_update(common) full = False while undecided: if sample: commoninsample = set(n for i, n in enumerate(sample) if yesno[i]) common.update(dag.ancestorset(commoninsample, common)) missinginsample = [n for i, n in enumerate(sample) if not yesno[i]] missing.update(dag.descendantset(missinginsample, missing)) undecided.difference_update(missing) undecided.difference_update(common) if not undecided: break if full: ui.note(_("sampling from both directions\n")) sample = _takefullsample(dag, undecided, size=fullsamplesize) elif common: # use cheapish initial sample ui.debug("taking initial sample\n") sample = _takefullsample(dag, undecided, size=fullsamplesize) else: # use even cheaper initial sample ui.debug("taking quick initial sample\n") sample = _takequicksample(dag, undecided, size=initialsamplesize, initial=True) roundtrips += 1 ui.progress(_("searching"), roundtrips, unit=_("queries")) ui.debug("query %i; still undecided: %i, sample size is: %i\n" % (roundtrips, len(undecided), len(sample))) # indices between sample and externalized version must match sample = list(sample) yesno = remote.known(dag.externalizeall(sample)) full = True result = dag.headsetofconnecteds(common) ui.progress(_("searching"), None) ui.debug("%d total queries\n" % roundtrips) if not result and srvheadhashes != [nullid]: if abortwhenunrelated: raise util.Abort(_("repository is unrelated")) else: ui.warn(_("warning: repository is unrelated\n")) return (set([nullid]), True, srvheadhashes) anyincoming = srvheadhashes != [nullid] return dag.externalizeall(result), anyincoming, srvheadhashes