changeset 1088:c06d4656b77b

shared: fix compatibility with hg < 4.2
author Kevin Bullock <kbullock@ringworld.org>
date Sun, 24 Dec 2017 11:48:24 -0500
parents 3b20ecf51ed5
children e4fb9229417a
files hggit/__init__.py hggit/compat.py hggit/git_handler.py
diffstat 3 files changed, 19 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/__init__.py	Mon Nov 27 22:03:18 2017 -0600
+++ b/hggit/__init__.py	Sun Dec 24 11:48:24 2017 -0500
@@ -49,7 +49,6 @@
     revset,
     scmutil,
     templatekw,
-    vfs as vfsmod,
 )
 
 try:
@@ -74,7 +73,6 @@
     # baseset was added in hg 3.0
     pass
 
-
 demandimport.ignore.extend([
     'collections',
 ])
@@ -215,21 +213,13 @@
              lambda *args: open(os.path.join(helpdir, 'git.rst')).read())
     insort(help.helptable, entry)
 
-def _gitvfs(repo):
-    """return a vfs suitable to read git related data"""
-    # Mercurial >= 3.3:  repo.shared()
-    if repo.sharedpath != repo.path:
-        return vfsmod.vfs(repo.sharedpath)
-    else:
-        return repo.vfs
-
 def reposetup(ui, repo):
     if not isinstance(repo, gitrepo.gitrepo):
 
         if (getattr(dirstate, 'rootcache', False) and
             (not ignoremod or getattr(ignore, 'readpats', False)) and
             hgutil.safehasattr(repo, 'vfs') and
-            os.path.exists(_gitvfs(repo).join('git'))):
+            os.path.exists(compat.gitvfs(repo).join('git'))):
             # only install our dirstate wrapper if it has a hope of working
             import gitdirstate
             if ignoremod:
@@ -286,7 +276,7 @@
 def git_cleanup(ui, repo):
     '''clean up Git commit map after history editing'''
     new_map = []
-    vfs = _gitvfs(repo)
+    vfs = compat.gitvfs(repo)
     for line in vfs(GitHandler.map_file):
         gitsha, hgsha = line.strip().split(' ', 1)
         if hgsha in repo:
--- a/hggit/compat.py	Mon Nov 27 22:03:18 2017 -0600
+++ b/hggit/compat.py	Sun Dec 24 11:48:24 2017 -0500
@@ -28,6 +28,22 @@
                 s = s.replace(c, '')
         return s
 
+try:
+    from mercurial import vfs as vfsmod
+    hgvfs = vfsmod.vfs
+except ImportError:
+    # vfsmod was extracted in hg 4.2
+    from mercurial import scmutil
+    hgvfs = scmutil.vfs
+
+def gitvfs(repo):
+    """return a vfs suitable to read git related data"""
+    # Mercurial >= 3.3:  repo.shared()
+    if repo.sharedpath != repo.path:
+        return hgvfs(repo.sharedpath)
+    else:
+        return repo.vfs
+
 def passwordmgr(ui):
     try:
         realm = hgutil.urlreq.httppasswordmgrwithdefaultrealm()
--- a/hggit/git_handler.py	Mon Nov 27 22:03:18 2017 -0600
+++ b/hggit/git_handler.py	Sun Dec 24 11:48:24 2017 -0500
@@ -25,7 +25,6 @@
     phases,
     util as hgutil,
     url,
-    vfs as vfsmod,
 )
 
 import _ssh
@@ -110,7 +109,7 @@
 
         # Mercurial >= 3.3:  repo.shared()
         if dest_repo.sharedpath != dest_repo.path:
-            self.vfs = vfsmod.vfs(dest_repo.sharedpath)
+            self.vfs = compat.hgvfs(dest_repo.sharedpath)
         if compat.config(ui, 'bool', 'git', 'intree'):
             self.gitdir = self.repo.wvfs.join('.git')
         else: