hg-fast-export: support new --hgtags option

Add support for a new --hgtags option.  When given, any .hgtags
files that may be present are exported.

Normally this is not desirable.  However, when attempting to mimic
the actions of other hg exporters that always export any .hgtags
files this option can help produce matching export data.
This commit is contained in:
Kyle J. McKay
2014-03-15 00:54:45 -07:00
committed by Frej Drejhammar
parent b1d1265330
commit 5fad4e4b99
2 changed files with 22 additions and 19 deletions

View File

@@ -119,12 +119,12 @@ def get_author(logmessage,committer,authors):
return r
return committer
def export_file_contents(ctx,manifest,files):
def export_file_contents(ctx,manifest,files,hgtags):
count=0
max=len(files)
for file in files:
# Skip .hgtags files. They only get us in trouble.
if file == ".hgtags":
if not hgtags and file == ".hgtags":
sys.stderr.write('Skip %s\n' % (file))
continue
d=ctx.filectx(file).data()
@@ -156,7 +156,7 @@ def sanitize_name(name,what="branch"):
sys.stderr.write('Warning: sanitized %s [%s] to [%s]\n' % (what,name,n))
return n
def export_commit(ui,repo,revision,old_marks,max,count,authors,sob,brmap):
def export_commit(ui,repo,revision,old_marks,max,count,authors,sob,brmap,hgtags):
def get_branchname(name):
if brmap.has_key(name):
return brmap[name]
@@ -218,8 +218,8 @@ def export_commit(ui,repo,revision,old_marks,max,count,authors,sob,brmap):
(branch,type,revision+1,max,len(added),len(changed),len(removed)))
map(lambda r: wr('D %s' % r),removed)
export_file_contents(ctx,man,added)
export_file_contents(ctx,man,changed)
export_file_contents(ctx,man,added,hgtags)
export_file_contents(ctx,man,changed,hgtags)
wr()
return checkpoint(count)
@@ -306,7 +306,7 @@ def verify_heads(ui,repo,cache,force):
return True
def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,authors={},sob=False,force=False):
def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,authors={},sob=False,force=False,hgtags=False):
_max=int(m)
old_marks=load_cache(marksfile,lambda s: int(s)-1)
@@ -337,7 +337,7 @@ def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,authors={},sob=Fals
c=0
brmap={}
for rev in range(min,max):
c=export_commit(ui,repo,rev,old_marks,max,c,authors,sob,brmap)
c=export_commit(ui,repo,rev,old_marks,max,c,authors,sob,brmap,hgtags)
state_cache['tip']=max
state_cache['repo']=repourl
@@ -372,6 +372,8 @@ if __name__=='__main__':
help="URL of repo to import")
parser.add_option("-s",action="store_true",dest="sob",
default=False,help="Enable parsing Signed-off-by lines")
parser.add_option("--hgtags",action="store_true",dest="hgtags",
default=False,help="Enable exporting .hgtags files")
parser.add_option("-A","--authors",dest="authorfile",
help="Read authormap from AUTHORFILE")
parser.add_option("-f","--force",action="store_true",dest="force",
@@ -403,4 +405,4 @@ if __name__=='__main__':
set_origin_name(options.origin_name)
sys.exit(hg2git(options.repourl,m,options.marksfile,options.mappingfile,options.headsfile,
options.statusfile,authors=a,sob=options.sob,force=options.force))
options.statusfile,authors=a,sob=options.sob,force=options.force,hgtags=options.hgtags))

View File

@@ -13,7 +13,7 @@ SFX_STATE="state"
GFI_OPTS=""
PYTHON=${PYTHON:-python}
USAGE="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [-A <file>] [-M <name>] [-o <name>]"
USAGE="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [--hgtags] [-A <file>] [-M <name>] [-o <name>]"
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,
GIT_DIR/$PFX-$SFX_STATE by default.
@@ -21,16 +21,17 @@ GIT_DIR/$PFX-$SFX_STATE by default.
Note: The argument order matters.
Options:
-m Maximum revision to import
--quiet Passed to git-fast-import(1)
-s Enable parsing Signed-off-by lines
-A Read author map from file
(Same as in git-svnimport(1) and git-cvsimport(1))
-r Mercurial repository to import
-M Set the default branch name (default to 'master')
-o Use <name> as branch namespace to track upstream (eg 'origin')
--force Ignore validation errors when converting, and pass --force
to git-fast-import(1)
-m Maximum revision to import
--quiet Passed to git-fast-import(1)
-s Enable parsing Signed-off-by lines
--hgtags Enable exporting .hgtags files
-A Read author map from file
(Same as in git-svnimport(1) and git-cvsimport(1))
-r Mercurial repository to import
-M Set the default branch name (default to 'master')
-o Use <name> as branch namespace to track upstream (eg 'origin')
--force Ignore validation errors when converting, and pass --force
to git-fast-import(1)
"
. "$(git --exec-path)/git-sh-setup"