From e09a14a26675411496f4a8cc0d6188ca5f20f07f Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 Mar 2023 20:37:19 -0600 Subject: [PATCH] Move parents logic inside get_filechanges This way export_commit is much simpler (already quite complex), and it's easier to modify the logic. No functional changes. Signed-off-by: Felipe Contreras --- hg-fast-export.py | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/hg-fast-export.py b/hg-fast-export.py index 923f30e..10ec63c 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -92,15 +92,31 @@ def split_dict(dleft,dright,c=[],r=[],match=file_mismatch): # change is already handled when comparing child against parent return c,r -def get_filechanges(repo,revision,parents,mleft): +def get_filechanges(repo,revision,parents,files,mleft): """Given some repository and revision, find all changed/deleted files.""" - modified,removed=[],[] - for p in parents: - if p<0: continue - mright=repo[p].manifest() - modified,removed=split_dict(mleft,mright,modified,removed) - modified.sort() - removed.sort() + if not parents: + # first revision: feed in full manifest + modified=files + removed=[] + else: + if len(parents) == 1: + # later non-merge revision: feed in changed manifest + # if we have exactly one parent, just take the changes from the + # manifest without expensively comparing checksums + f=repo.status(parents[0],revision) + modified=f.modified + f.added + removed=f.removed + else: # a merge with two parents + # later merge revision: feed in changed manifest + # for many files comparing checksums is expensive so only do it for + # merges where we really need it due to hg's revlog logic + modified,removed=[],[] + for p in parents: + if p<0: continue + mright=repo[p].manifest() + modified,removed=split_dict(mleft,mright,modified,removed) + modified.sort() + removed.sort() return modified,removed def get_author(logmessage,committer,authors): @@ -331,30 +347,19 @@ def export_commit(ui,repo,revision,old_marks,max,count,authors, wr_data(desc) man=ctx.manifest() - modified,removed,type=[],[],'' if not parents: - # first revision: feed in full manifest - modified=files type='full' else: wr(b'from %s' % revnum_to_revref(parents[0], old_marks)) if len(parents) == 1: - # later non-merge revision: feed in changed manifest - # if we have exactly one parent, just take the changes from the - # manifest without expensively comparing checksums - f=repo.status(parents[0],revision) - modified=f.modified + f.added - removed=f.removed type='simple delta' else: # a merge with two parents wr(b'merge %s' % revnum_to_revref(parents[1], old_marks)) - # later merge revision: feed in changed manifest - # for many files comparing checksums is expensive so only do it for - # merges where we really need it due to hg's revlog logic - modified,removed=get_filechanges(repo,revision,parents,man) type='thorough delta' + modified,removed=get_filechanges(repo,revision,parents,files,man) + stderr_buffer.write( b'%s: Exporting %s revision %d/%d with %d/%d modified/removed files\n' % (branch, type.encode(), revision + 1, max, len(modified), len(removed)) -- 2.11.4.GIT