changeset 410:eb524b957345

move aresamefiles() from HgChangeReceiver to util
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 10 Jun 2009 17:29:11 +0200
parents d4615986e1db
children d71972428fce
files hgsubversion/hg_delta_editor.py hgsubversion/stupid.py hgsubversion/util.py
diffstat 3 files changed, 28 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- 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
--- 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