From f75057e49a085d2d405cb9f59991753fe0b9adaf Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Sun, 10 Jan 2016 14:00:02 +0100 Subject: [PATCH] Make --hg-hash work in incremental mode When an import is restarted the first new note commit must use refs/notes/hg^0 as the parent. As refs/notes/hg is only updated at the end of a session we cannot have it present in all note commits. Neither can we generate new marks for note commits as that would require a new mapping scheme from hg versions numbers to git marks. A new mapping scheme would break existing incremental import setups. We therefore restructure the code to do the notes at the end of an import session, thus only requiring a refs/notes/hg^0 reference in the first commit. --- hg-fast-export.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/hg-fast-export.py b/hg-fast-export.py index 1f9c3f5..bf5f5b2 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -170,7 +170,7 @@ def strip_leading_slash(filename): return filename def export_commit(ui,repo,revision,old_marks,max,count,authors, - branchesmap,sob,brmap,hgtags,notes,encoding='',fn_encoding=''): + branchesmap,sob,brmap,hgtags,encoding='',fn_encoding=''): def get_branchname(name): if brmap.has_key(name): return brmap[name] @@ -235,23 +235,29 @@ def export_commit(ui,repo,revision,old_marks,max,count,authors, export_file_contents(ctx,man,changed,hgtags,fn_encoding) wr() - count=checkpoint(count) - count=generate_note(user,time,timezone,revision,ctx,count,notes) - return count + return checkpoint(count) + +def export_note(ui,repo,revision,count,authors,encoding,is_first): + (revnode,_,user,(time,timezone),_,_,_,_)=get_changeset(ui,repo,revision,authors,encoding) + + parents = [p for p in repo.changelog.parentrevs(revision) if p >= 0] -def generate_note(user,time,timezone,revision,ctx,count,notes): - if not notes: - return count wr('commit refs/notes/hg') wr('committer %s %d %s' % (user,time,timezone)) wr('data 0') + if is_first: + wr('from refs/notes/hg^0') wr('N inline :%d' % (revision+1)) - hg_hash=ctx.hex() + hg_hash=repo.changectx(str(revision)).hex() wr('data %d' % (len(hg_hash))) wr_no_nl(hg_hash) wr() return checkpoint(count) - + + wr('data %d' % (len(desc)+1)) # wtf? + wr(desc) + wr() + def export_tags(ui,repo,old_marks,mapping_cache,count,authors,tagsmap): l=repo.tagslist() for tag,node in l: @@ -374,7 +380,10 @@ def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile, brmap={} for rev in range(min,max): c=export_commit(ui,repo,rev,old_marks,max,c,authors,branchesmap, - sob,brmap,hgtags,notes,encoding,fn_encoding) + sob,brmap,hgtags,encoding,fn_encoding) + if notes: + for rev in range(min,max): + c=export_note(ui,repo,rev,c,authors, encoding, rev == min and min != 0) state_cache['tip']=max state_cache['repo']=repourl -- 2.11.4.GIT