hg debugcrdump should also use globalrev

Summary:
This command uses svnrev directly. However once we migrate to www-hg, this fields will
go and we can only use globalrev instead.

Let's add that and put it behind a config.

More context: https://fb.workplace.com/groups/248282915800791/permalink/372855146676900/

Differential Revision: D16560447

fbshipit-source-id: de3100ed1e6cc39eaaeff2fe11af04d2f1e2c41a
This commit is contained in:
Shu-Ting Tseng 2019-07-31 09:11:02 -07:00 committed by Facebook Github Bot
parent bfc5ee0878
commit 01394c9202
4 changed files with 41 additions and 7 deletions

View File

@ -150,13 +150,18 @@ def crdump(ui, repo, *revs, **opts):
if pbctx:
rdata["public_base"] = {"node": hex(pbctx.node())}
try:
hgsubversion = extensions.find("hgsubversion")
svnrev = hgsubversion.util.getsvnrev(pbctx)
# There are no abstractions in hgsubversion for doing
# it see hgsubversion/svncommands.py:267
rdata["public_base"]["svnrev"] = (
svnrev.split("@")[1] if svnrev else None
)
if ui.configbool("hgsubversion", "useglobalrevindebugcrdump"):
globalrevs = extensions.find("globalrevs")
globalrev = globalrevs.getglobalrev(ui, pbctx)
rdata["public_base"]["svnrev"] = globalrev
else:
hgsubversion = extensions.find("hgsubversion")
svnrev = hgsubversion.util.getsvnrev(pbctx)
# There are no abstractions in hgsubversion for doing
# it see hgsubversion/svncommands.py:267
rdata["public_base"]["svnrev"] = (
svnrev.split("@")[1] if svnrev else None
)
except KeyError:
pass
rdata["patch_file"] = dumppatch(ui, repo, ctx, outdir, contextlines)

View File

@ -407,6 +407,14 @@ def _revsetglobalrev(repo, subset, x):
return subset & smartset.baseset(_lookupglobalrev(repo, globalrev))
def getglobalrev(ui, ctx, defval=None):
"""Wrapper around _getglobalrev. See _getglobalrev for more detail."""
grev = _getglobalrev(ui, ctx.extra())
if grev:
return grev
return defval
def _getglobalrev(ui, commitextra):
grev = commitextra.get(EXTRASGLOBALREVKEY)

View File

@ -25,6 +25,9 @@ Config::
# Skip the post-push pull and rebase. This only works in single-writer
# scenario and should only be used in HG -> SVN reverse sync.
skippostpushpulls = False
# In `hg debugcrdump`, it uses svn revision number by default. When enabled,
# the command will give globalrev instead.
useglobalrevindebugcrdump = False
"""
from __future__ import absolute_import
@ -439,6 +442,7 @@ configitem("hgsubversion", "skippostpushpulls", default=False)
# If this configuration is true, the `svnrev` template keyword would be
# effectively disabled and querying for it would return nothing.
configitem("hgsubversion", "disablesvnrevkeyword ", default=False)
configitem("hgsubversion", "useglobalrevindebugcrdump ", default=False)
@templatekeyword("svnrev")

View File

@ -309,6 +309,9 @@ Test basic dump of two commits
######## old
62000a
#if jq
Test crdump not dumping binaries
@ -476,3 +479,17 @@ Test non-ASCII characters
],
"output_directory": "*" (glob)
}
#if jq
Test use globalrev instead of svnrev
$ echo y > Y
$ hg commit --config "extensions.commitextras=" -Aqm "commit with globalrev and svnrev" --extra convert_revision="svn:2c7ba8d8-a2f7-0310-a573-de162e16dcc7/tfb/trunk/www@1234567" --extra global_rev="100098765"
$ hg phase -pfr '.'
$ echo z > Z
$ hg commit -Aqm "local commit"
$ hg debugcrdump --config 'extensions.hgsubversion=' --config 'extensions.globalrevs=' -r . | jq '.commits[].public_base.svnrev'
"1234567"
$ hg debugcrdump --config 'extensions.hgsubversion=' --config 'extensions.globalrevs=' --config "hgsubversion.useglobalrevindebugcrdump=True" -r . | jq '.commits[].public_base.svnrev'
"100098765"
#endif