diff hggit/git_handler.py @ 845:fffe8883960b

git_handler: mark source for rename info as Git or Mercurial See inline comments for why the additional metadata needs to be stored. This literally breaks all the hashes because of the additional metadata. The changing of hashes is unfortunate but necessary to preserve bidirectionality. While this could be broken up into multiple commits, there was no way to do that while preserving bidirectionality. Following the principle that every intermediate commit must result in a correct state, I decided to combine the commits.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 02 Dec 2014 14:17:09 -0800 (2014-12-02)
parents da804eac2b00
children 89bfb9994732
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -620,29 +620,31 @@
         for i, field, value in git_extraitems:
             git_extra.append((urllib.unquote(field), urllib.unquote(value)))
 
-        renames = []
-        for f in ctx.files():
-            if f not in ctx.manifest():
-                continue
-            rename = ctx.filectx(f).renamed()
-            if rename:
-                renames.append((rename[0], f))
+        if extra.get('hg-git-rename-source', None) != 'git':
+            renames = []
+            for f in ctx.files():
+                if f not in ctx.manifest():
+                    continue
+                rename = ctx.filectx(f).renamed()
+                if rename:
+                    renames.append((rename[0], f))
 
-        if renames:
-            for oldfile, newfile in renames:
-                if extra_in_message:
-                    extra_message += ("rename : " + oldfile + " => " +
-                                      newfile + "\n")
-                else:
-                    spec = '%s:%s' % (urllib.quote(oldfile),
-                                      urllib.quote(newfile))
-                    git_extra.append(('HG:rename', spec))
+            if renames:
+                for oldfile, newfile in renames:
+                    if extra_in_message:
+                        extra_message += ("rename : " + oldfile + " => " +
+                                          newfile + "\n")
+                    else:
+                        spec = '%s:%s' % (urllib.quote(oldfile),
+                                          urllib.quote(newfile))
+                        git_extra.append(('HG:rename', spec))
 
         # hg extra items always go at the end
         extraitems = extra.items()
         extraitems.sort()
         for key, value in extraitems:
-            if key in ('author', 'committer', 'encoding', 'message', 'branch', 'hg-git'):
+            if key in ('author', 'committer', 'encoding', 'message', 'branch',
+                       'hg-git', 'hg-git-rename-source'):
                 continue
             else:
                 if extra_in_message:
@@ -656,6 +658,13 @@
         if extra_message:
             message += "\n--HG--\n" + extra_message
 
+        if (extra.get('hg-git-rename-source', None) != 'git'
+            and not extra_in_message and not git_extra):
+            # We need to store this if no other metadata is stored. This
+            # indicates that when reimporting the commit into Mercurial we'll
+            # know not to detect renames.
+            git_extra.append(('HG:rename-source', 'hg'))
+
         return message, git_extra
 
     def get_git_incoming(self, refs):
@@ -690,6 +699,11 @@
              commit.message, commit.extra)
         if hg_renames is None:
             detect_renames = True
+            # We have to store this unconditionally, even if there are no
+            # renames detected from Git. This is because we export an extra
+            # 'HG:rename-source' Git parameter when this isn't set, which will
+            # break bidirectionality.
+            extra['hg-git-rename-source'] = 'git'
         else:
             renames = hg_renames