diff src/hgext3rd/hggit_serve/_http.py @ 13:00bdfac5416c

Create Git SSH commands and add some documentation. Also cleanup. - Adds git-upload-pack and git-receive-pack as hg subcommands, to be run on the server side by git push/pull. - Starts on documentation. - Cleans up a lot of stuff.
author Paul Fisher <paul@pfish.zone>
date Thu, 19 Feb 2026 01:13:56 -0500
parents f630d9904ea7
children
line wrap: on
line diff
--- a/src/hgext3rd/hggit_serve/_http.py	Wed Feb 18 16:17:05 2026 -0500
+++ b/src/hgext3rd/hggit_serve/_http.py	Thu Feb 19 01:13:56 2026 -0500
@@ -16,7 +16,6 @@
 if t.TYPE_CHECKING:
     import mercurial.hgweb.hgweb_mod_inner as web_inner
     import mercurial.hgweb.request as hgreq
-    import mercurial.interfaces.repository as hgrepo
     import mercurial.ui as hgui
 
     PermissionCheck = t.Callable[
@@ -39,11 +38,13 @@
         for (k, v) in request.rawenv.items()
         if isinstance(v, bytes) and _CGI_VAR.match(k)
     }
+    repo = req_ctx.repo
+    assert xp.is_gitty(repo)
     fixed.update(
         {
             b'GIT_HTTP_EXPORT_ALL': b'yes',
-            b'GIT_PROJECT_ROOT': req_ctx.repo.path,
-            b'PATH_INFO': b'/git/' + request.dispatchpath,
+            b'GIT_PROJECT_ROOT': repo.githandler.gitdir,
+            b'PATH_INFO': b'/' + request.dispatchpath,
             # Since Mercurial is taking care of authorization checking,
             # we tell Git to always allow push.
             b'GIT_CONFIG_COUNT': b'1',
@@ -101,7 +102,7 @@
 ) -> bool:
     """Intercepts requests from Git, if needed."""
     perm = _git_service_permission(request)
-    repo: hgrepo.IRepo = req_ctx.repo
+    repo = req_ctx.repo
     if not perm or not xp.is_gitty(repo):
         # We only handle Git requests to Gitty repos.
         return original(req_ctx, request, response, check_permission)
@@ -155,14 +156,7 @@
                 yield more
         if perm == xp.PUSH:
             # If we pushed, we need to import any new refs back into Mercurial.
-            xp.importing_enter(repo)
-            try:
-                gh = repo.githandler
-                gh.import_git_objects(
-                    b'git-push', remote_names=(), refs=gh.git.refs.as_dict()
-                )
-            finally:
-                xp.importing_exit(repo)
+            xp.import_all(repo, b'git-http-push')
 
     response.setbodygen(write_the_rest())
     response.sendresponse()