11ca21820a95 — Siddharth Agarwal 7 years ago
overlay: adapt diff to work with lazymanifests
2 files changed, 27 insertions(+), 2 deletions(-)

M hggit/__init__.py
M hggit/overlay.py
M hggit/__init__.py +7 -0
@@ 36,6 36,7 @@ from mercurial import help
 from mercurial import hg
 from mercurial import ignore
 from mercurial import localrepo
+from mercurial import manifest
 from mercurial.node import hex
 from mercurial import revset
 from mercurial import scmutil

          
@@ 45,6 46,7 @@ from mercurial.i18n import _
 
 import gitrepo
 import hgrepo
+import overlay
 import util
 from git_handler import GitHandler
 import verify

          
@@ 126,6 128,11 @@ def reposetup(ui, repo):
         klass = hgrepo.generate_repo_subclass(repo.__class__)
         repo.__class__ = klass
 
+if hgutil.safehasattr(manifest, '_lazymanifest'):
+    # Mercurial >= 3.4
+    extensions.wrapfunction(manifest.manifestdict, 'diff',
+                            overlay.wrapmanifestdictdiff)
+
 @command('gimport')
 def gimport(ui, repo, remote_name=None):
     '''import commits from Git to Mercurial'''

          
M hggit/overlay.py +20 -2
@@ 103,10 103,16 @@ class overlaymanifest(object):
         # below code copied from manifest.py:manifestdict.diff
         diff = {}
 
+        try:
+            m2flagget = m2.flags
+        except AttributeError:
+            # Mercurial <= 3.3
+            m2flagget = m2._flags.get
+
         for fn, n1 in self.iteritems():
             fl1 = self._flags.get(fn, '')
             n2 = m2.get(fn, None)
-            fl2 = m2._flags.get(fn, '')
+            fl2 = m2flagget(fn, '')
             if n2 is None:
                 fl2 = ''
             if n1 != n2 or fl1 != fl2:

          
@@ 116,7 122,7 @@ class overlaymanifest(object):
 
         for fn, n2 in m2.iteritems():
             if fn not in self:
-                fl2 = m2._flags.get(fn, '')
+                fl2 = m2flagget(fn, '')
                 diff[fn] = ((None, ''), (n2, fl2))
 
         return diff

          
@@ 124,6 130,18 @@ class overlaymanifest(object):
     def __delitem__(self, path):
         del self._map[path]
 
+def wrapmanifestdictdiff(orig, self, m2, clean=False):
+    '''avoid calling into lazymanifest code if m2 is an overlaymanifest'''
+    if isinstance(m2, overlaymanifest):
+        diff = m2.diff(self, clean=clean)
+        # since we calculated the diff with m2 vs m1, flip it around
+        for fn in diff:
+            c1, c2 = diff[fn]
+            diff[fn] = c2, c1
+        return diff
+    else:
+        return orig(self, m2, clean=clean)
+
 class overlayfilectx(object):
     def __init__(self, repo, path, fileid=None):
         self.repo = repo