Add option --ignore-unnamed-heads

This option allows the user to ignore only unnamed heads (compared to --force
which ignores all non-fatal issues). The intended use is for a future plugin
converting unnamed heads to named branches.
This commit is contained in:
Ondrej Stanek
2020-07-31 10:30:53 +02:00
parent 2a9dd53d14
commit 50631c4b34
2 changed files with 12 additions and 7 deletions

View File

@@ -475,7 +475,7 @@ def branchtip(repo, heads):
break break
return tip return tip
def verify_heads(ui,repo,cache,force,branchesmap): def verify_heads(ui,repo,cache,force,ignore_unnamed_heads,branchesmap):
branches={} branches={}
for bn, heads in repo.branchmap().iteritems(): for bn, heads in repo.branchmap().iteritems():
branches[bn] = branchtip(repo, heads) branches[bn] = branchtip(repo, heads)
@@ -506,13 +506,14 @@ def verify_heads(ui,repo,cache,force,branchesmap):
% repo.changelog.rev(h) % repo.changelog.rev(h)
) )
unnamed_heads=True unnamed_heads=True
if not force and not ignore_unnamed_heads: return False
t[branch]=True t[branch]=True
if unnamed_heads and not force: return False if unnamed_heads and not force and not ignore_unnamed_heads: return False
return True return True
def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile, def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,
authors={},branchesmap={},tagsmap={}, authors={},branchesmap={},tagsmap={},
sob=False,force=False,hgtags=False,notes=False,encoding='',fn_encoding='', sob=False,force=False,ignore_unnamed_heads=False,hgtags=False,notes=False,encoding='',fn_encoding='',
plugins={}): plugins={}):
def check_cache(filename, contents): def check_cache(filename, contents):
if len(contents) == 0: if len(contents) == 0:
@@ -533,7 +534,7 @@ def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,
ui,repo=setup_repo(repourl) ui,repo=setup_repo(repourl)
if not verify_heads(ui,repo,heads_cache,force,branchesmap): if not verify_heads(ui,repo,heads_cache,force,ignore_unnamed_heads,branchesmap):
return 1 return 1
try: try:
@@ -619,7 +620,9 @@ if __name__=='__main__':
parser.add_option("-T","--tags",dest="tagsfile", parser.add_option("-T","--tags",dest="tagsfile",
help="Read tags map from TAGSFILE") help="Read tags map from TAGSFILE")
parser.add_option("-f","--force",action="store_true",dest="force", parser.add_option("-f","--force",action="store_true",dest="force",
default=False,help="Ignore validation errors by force") default=False,help="Ignore validation errors by force, implies --ignore-unnamed-heads")
parser.add_option("--ignore-unnamed-heads",action="store_true",dest="ignore_unnamed_heads",
default=False,help="Ignore unnamed head errors")
parser.add_option("-M","--default-branch",dest="default_branch", parser.add_option("-M","--default-branch",dest="default_branch",
help="Set the default branch") help="Set the default branch")
parser.add_option("-o","--origin",dest="origin_name", parser.add_option("-o","--origin",dest="origin_name",
@@ -715,6 +718,8 @@ if __name__=='__main__':
sys.exit(hg2git(options.repourl,m,options.marksfile,options.mappingfile, sys.exit(hg2git(options.repourl,m,options.marksfile,options.mappingfile,
options.headsfile, options.statusfile, options.headsfile, options.statusfile,
authors=a,branchesmap=b,tagsmap=t, authors=a,branchesmap=b,tagsmap=t,
sob=options.sob,force=options.force,hgtags=options.hgtags, sob=options.sob,force=options.force,
ignore_unnamed_heads=options.ignore_unnamed_heads,
hgtags=options.hgtags,
notes=options.notes,encoding=encoding,fn_encoding=fn_encoding, notes=options.notes,encoding=encoding,fn_encoding=fn_encoding,
plugins=plugins_dict)) plugins=plugins_dict))

View File

@@ -45,7 +45,7 @@ if [ -z "${PYTHON}" ]; then
exit 1 exit 1
fi fi
USAGE="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [--hgtags] [-A <file>] [-B <file>] [-T <file>] [-M <name>] [-o <name>] [--hg-hash] [-e <encoding>]" USAGE="[--quiet] [-r <repo>] [--force] [--ignore-unnamed-heads] [-m <max>] [-s] [--hgtags] [-A <file>] [-B <file>] [-T <file>] [-M <name>] [-o <name>] [--hg-hash] [-e <encoding>]"
LONG_USAGE="Import hg repository <repo> up to either tip or <max> LONG_USAGE="Import hg repository <repo> up to either tip or <max>
If <repo> is omitted, use last hg repository as obtained from state file, If <repo> is omitted, use last hg repository as obtained from state file,
GIT_DIR/$PFX-$SFX_STATE by default. GIT_DIR/$PFX-$SFX_STATE by default.