# HG changeset patch # User Dirkjan Ochtman # Date 1244647751 -7200 # Node ID eb524b95734525c88f8d1ead534836b4881d0a96 # Parent d4615986e1db89ea31639e49e15b4cbbb2a9f89c move aresamefiles() from HgChangeReceiver to util diff --git a/hgsubversion/hg_delta_editor.py b/hgsubversion/hg_delta_editor.py --- a/hgsubversion/hg_delta_editor.py +++ b/hgsubversion/hg_delta_editor.py @@ -725,30 +725,6 @@ class HgChangeReceiver(delta.Editor): def authors_file(self): return os.path.join(self.meta_data_dir, 'authors') - def aresamefiles(self, parentctx, childctx, files): - """Assuming all files exist in childctx and parentctx, return True - if none of them was changed in-between. - """ - if parentctx == childctx: - return True - if parentctx.rev() > childctx.rev(): - parentctx, childctx = childctx, parentctx - - def selfandancestors(selfctx): - yield selfctx - for ctx in selfctx.ancestors(): - yield ctx - - files = dict.fromkeys(files) - for pctx in selfandancestors(childctx): - if pctx.rev() <= parentctx.rev(): - return True - for f in pctx.files(): - if f in files: - return False - # parentctx is not an ancestor of childctx, files are unrelated - return False - # Here come all the actual editor methods @ieditor @@ -847,7 +823,7 @@ class HgChangeReceiver(delta.Editor): branch) if parentid != revlog.nullid: parentctx = self.repo.changectx(parentid) - if self.aresamefiles(parentctx, ctx, [from_file]): + if util.aresamefiles(parentctx, ctx, [from_file]): self.copies[path] = from_file @ieditor @@ -906,7 +882,7 @@ class HgChangeReceiver(delta.Editor): parentid = self.get_parent_revision(self.current_rev.revnum, branch) if parentid != revlog.nullid: parentctx = self.repo.changectx(parentid) - if self.aresamefiles(parentctx, cp_f_ctx, copies.values()): + if util.aresamefiles(parentctx, cp_f_ctx, copies.values()): self.copies.update(copies) return path diff --git a/hgsubversion/stupid.py b/hgsubversion/stupid.py --- a/hgsubversion/stupid.py +++ b/hgsubversion/stupid.py @@ -321,7 +321,7 @@ def getcopies(svn, hg_editor, branch, br if sourcectx is None: continue sources = [s[1] for s in copies] - if not hg_editor.aresamefiles(sourcectx, parentctx, sources): + if not util.aresamefiles(sourcectx, parentctx, sources): continue hgcopies.update(copies) return hgcopies diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -102,3 +102,28 @@ def swap_out_encoding(new_encoding="UTF- old = encoding.encoding encoding.encoding = new_encoding return old + + +def aresamefiles(parentctx, childctx, files): + """Assuming all files exist in childctx and parentctx, return True + if none of them was changed in-between. + """ + if parentctx == childctx: + return True + if parentctx.rev() > childctx.rev(): + parentctx, childctx = childctx, parentctx + + def selfandancestors(selfctx): + yield selfctx + for ctx in selfctx.ancestors(): + yield ctx + + files = dict.fromkeys(files) + for pctx in selfandancestors(childctx): + if pctx.rev() <= parentctx.rev(): + return True + for f in pctx.files(): + if f in files: + return False + # parentctx is not an ancestor of childctx, files are unrelated + return False