Patchwork D8265: git: key off `git` in .hg/requirements rather than separate file

login
register
mail settings
Submitter phabricator
Date March 10, 2020, 4:46 p.m.
Message ID <b614b3caa4f76ba0eacd57e3407d3c70@localhost.localdomain>
Download mbox | patch
Permalink /patch/45665/
State Not Applicable
Headers show

Comments

phabricator - March 10, 2020, 4:46 p.m.
durin42 marked an inline comment as done.
durin42 updated this revision to Diff 20666.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8265?vs=20665&id=20666

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8265/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8265

AFFECTED FILES
  hgext/git/__init__.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: martinvonz, mharbison72, mercurial-devel

Patch

diff --git a/hgext/git/__init__.py b/hgext/git/__init__.py
--- a/hgext/git/__init__.py
+++ b/hgext/git/__init__.py
@@ -86,19 +86,29 @@ 
 
 
 def _makestore(orig, requirements, storebasepath, vfstype):
-    # Check for presence of pygit2 only here. The assumption is that we'll
-    # run this code iff we'll later need pygit2.
-    if gitutil.get_pygit2() is None:
-        raise error.Abort(
-            _(
-                b'the git extension requires the Python '
-                b'pygit2 library to be installed'
+    reqsf = os.path.join(storebasepath, b'requires')
+    reqs = set()
+    if os.path.exists(reqsf):
+        with open(reqsf, 'rb') as f:
+            reqs = {l.strip() for l in f}
+    if b'git' in reqs:
+        if not os.path.exists(os.path.join(storebasepath, b'..', b'.git')):
+            raise error.Abort(
+                _(
+                    b'repository specified git format in '
+                    b'.hg/requires but has no .git directory'
+                )
             )
-        )
+        # Check for presence of pygit2 only here. The assumption is that we'll
+        # run this code iff we'll later need pygit2.
+        if gitutil.get_pygit2() is None:
+            raise error.Abort(
+                _(
+                    b'the git extension requires the Python '
+                    b'pygit2 library to be installed'
+                )
+            )
 
-    if os.path.exists(
-        os.path.join(storebasepath, b'this-is-git')
-    ) and os.path.exists(os.path.join(storebasepath, b'..', b'.git')):
         return gitstore(storebasepath, vfstype)
     return orig(requirements, storebasepath, vfstype)
 
@@ -128,8 +138,6 @@ 
             os.path.join(path, b'.git', b'info', b'exclude'), 'ab'
         ) as exclude:
             exclude.write(b'\n.hg\n')
-    with open(os.path.join(dothg, b'this-is-git'), 'wb') as f:
-        pass
     with open(os.path.join(dothg, b'requirements'), 'wb') as f:
         f.write(b'git\n')