We don't need to use dagutil to perform a simple rev -> node
conversion.
I haven't measured, but the new code is likely faster, as we
avoid extra function calls and avoid some attribute lookups.
hg-reviewers |
We don't need to use dagutil to perform a simple rev -> node
conversion.
I haven't measured, but the new code is likely faster, as we
avoid extra function calls and avoid some attribute lookups.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/debugcommands.py (6 lines) | |||
M | mercurial/setdiscovery.py (15 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Gregory Szorc | Aug 16 2018, 3:39 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | indygreg | D4330 dagutil: remove module | |
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg |
# enable in-client legacy support | # enable in-client legacy support | ||||
remote = localrepo.locallegacypeer(remote.local()) | remote = localrepo.locallegacypeer(remote.local()) | ||||
common, _in, hds = treediscovery.findcommonincoming(repo, remote, | common, _in, hds = treediscovery.findcommonincoming(repo, remote, | ||||
force=True) | force=True) | ||||
common = set(common) | common = set(common) | ||||
if not opts.get('nonheads'): | if not opts.get('nonheads'): | ||||
ui.write(("unpruned common: %s\n") % | ui.write(("unpruned common: %s\n") % | ||||
" ".join(sorted(short(n) for n in common))) | " ".join(sorted(short(n) for n in common))) | ||||
dag = dagutil.revlogdag(repo.changelog) | cl = repo.changelog | ||||
clnode = cl.node | |||||
dag = dagutil.revlogdag(cl) | |||||
all = dag.ancestorset(dag.internalizeall(common)) | all = dag.ancestorset(dag.internalizeall(common)) | ||||
common = dag.externalizeall(dag.headsetofconnecteds(all)) | common = {clnode(r) for r in dag.headsetofconnecteds(all)} | ||||
else: | else: | ||||
nodes = None | nodes = None | ||||
if pushedrevs: | if pushedrevs: | ||||
revs = scmutil.revrange(repo, pushedrevs) | revs = scmutil.revrange(repo, pushedrevs) | ||||
nodes = [repo[r].node() for r in revs] | nodes = [repo[r].node() for r in revs] | ||||
common, any, hds = setdiscovery.findcommonheads(ui, repo, remote, | common, any, hds = setdiscovery.findcommonheads(ui, repo, remote, | ||||
ancestorsof=nodes) | ancestorsof=nodes) | ||||
common = set(common) | common = set(common) |
ancestorsof=None): | ancestorsof=None): | ||||
'''Return a tuple (common, anyincoming, remoteheads) used to identify | '''Return a tuple (common, anyincoming, remoteheads) used to identify | ||||
missing nodes from or in remote. | missing nodes from or in remote. | ||||
''' | ''' | ||||
start = util.timer() | start = util.timer() | ||||
roundtrips = 0 | roundtrips = 0 | ||||
cl = local.changelog | cl = local.changelog | ||||
clnode = cl.node | |||||
localsubset = None | localsubset = None | ||||
if ancestorsof is not None: | if ancestorsof is not None: | ||||
rev = local.changelog.rev | rev = local.changelog.rev | ||||
localsubset = [rev(n) for n in ancestorsof] | localsubset = [rev(n) for n in ancestorsof] | ||||
dag = dagutil.revlogdag(cl, localsubset=localsubset) | dag = dagutil.revlogdag(cl, localsubset=localsubset) | ||||
# early exit if we know all the specified remote heads already | # early exit if we know all the specified remote heads already | ||||
ui.debug("query 1; heads\n") | ui.debug("query 1; heads\n") | ||||
roundtrips += 1 | roundtrips += 1 | ||||
ownheads = dag.heads() | ownheads = dag.heads() | ||||
sample = _limitsample(ownheads, initialsamplesize) | sample = _limitsample(ownheads, initialsamplesize) | ||||
# indices between sample and externalized version must match | # indices between sample and externalized version must match | ||||
sample = list(sample) | sample = list(sample) | ||||
with remote.commandexecutor() as e: | with remote.commandexecutor() as e: | ||||
fheads = e.callcommand('heads', {}) | fheads = e.callcommand('heads', {}) | ||||
fknown = e.callcommand('known', { | fknown = e.callcommand('known', { | ||||
'nodes': dag.externalizeall(sample), | 'nodes': [clnode(r) for r in sample], | ||||
}) | }) | ||||
srvheadhashes, yesno = fheads.result(), fknown.result() | srvheadhashes, yesno = fheads.result(), fknown.result() | ||||
if cl.tip() == nullid: | if cl.tip() == nullid: | ||||
if srvheadhashes != [nullid]: | if srvheadhashes != [nullid]: | ||||
return [nullid], True, srvheadhashes | return [nullid], True, srvheadhashes | ||||
return [nullid], False, [] | return [nullid], False, [] | ||||
# start actual discovery (we note this before the next "if" for | # start actual discovery (we note this before the next "if" for | ||||
# compatibility reasons) | # compatibility reasons) | ||||
ui.status(_("searching for changes\n")) | ui.status(_("searching for changes\n")) | ||||
srvheads = dag.internalizeall(srvheadhashes, filterunknown=True) | srvheads = dag.internalizeall(srvheadhashes, filterunknown=True) | ||||
if len(srvheads) == len(srvheadhashes): | if len(srvheads) == len(srvheadhashes): | ||||
ui.debug("all remote heads known locally\n") | ui.debug("all remote heads known locally\n") | ||||
return (srvheadhashes, False, srvheadhashes,) | return srvheadhashes, False, srvheadhashes | ||||
if len(sample) == len(ownheads) and all(yesno): | if len(sample) == len(ownheads) and all(yesno): | ||||
ui.note(_("all local heads known remotely\n")) | ui.note(_("all local heads known remotely\n")) | ||||
ownheadhashes = dag.externalizeall(ownheads) | ownheadhashes = [clnode(r) for r in ownheads] | ||||
return (ownheadhashes, True, srvheadhashes,) | return ownheadhashes, True, srvheadhashes | ||||
# full blown discovery | # full blown discovery | ||||
# own nodes I know we both know | # own nodes I know we both know | ||||
# treat remote heads (and maybe own heads) as a first implicit sample | # treat remote heads (and maybe own heads) as a first implicit sample | ||||
# response | # response | ||||
common = cl.incrementalmissingrevs(srvheads) | common = cl.incrementalmissingrevs(srvheads) | ||||
commoninsample = set(n for i, n in enumerate(sample) if yesno[i]) | commoninsample = set(n for i, n in enumerate(sample) if yesno[i]) | ||||
progress.update(roundtrips) | progress.update(roundtrips) | ||||
ui.debug("query %i; still undecided: %i, sample size is: %i\n" | ui.debug("query %i; still undecided: %i, sample size is: %i\n" | ||||
% (roundtrips, len(undecided), len(sample))) | % (roundtrips, len(undecided), len(sample))) | ||||
# indices between sample and externalized version must match | # indices between sample and externalized version must match | ||||
sample = list(sample) | sample = list(sample) | ||||
with remote.commandexecutor() as e: | with remote.commandexecutor() as e: | ||||
yesno = e.callcommand('known', { | yesno = e.callcommand('known', { | ||||
'nodes': dag.externalizeall(sample), | 'nodes': [clnode(r) for r in sample], | ||||
}).result() | }).result() | ||||
full = True | full = True | ||||
if sample: | if sample: | ||||
commoninsample = set(n for i, n in enumerate(sample) if yesno[i]) | commoninsample = set(n for i, n in enumerate(sample) if yesno[i]) | ||||
common.addbases(commoninsample) | common.addbases(commoninsample) | ||||
common.removeancestorsfrom(undecided) | common.removeancestorsfrom(undecided) | ||||
if not result and srvheadhashes != [nullid]: | if not result and srvheadhashes != [nullid]: | ||||
if abortwhenunrelated: | if abortwhenunrelated: | ||||
raise error.Abort(_("repository is unrelated")) | raise error.Abort(_("repository is unrelated")) | ||||
else: | else: | ||||
ui.warn(_("warning: repository is unrelated\n")) | ui.warn(_("warning: repository is unrelated\n")) | ||||
return ({nullid}, True, srvheadhashes,) | return ({nullid}, True, srvheadhashes,) | ||||
anyincoming = (srvheadhashes != [nullid]) | anyincoming = (srvheadhashes != [nullid]) | ||||
return dag.externalizeall(result), anyincoming, srvheadhashes | result = {clnode(r) for r in result} | ||||
return result, anyincoming, srvheadhashes |