[PATCH 2 of 3] hgweb: add a hook for processing LFS file transfer requests

Matt Harbison mharbison72 at gmail.com
Thu Feb 22 01:02:42 EST 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1519275362 18000
#      Wed Feb 21 23:56:02 2018 -0500
# Node ID 7a6042e238b7a90ce1d158395c42937cb0f7298c
# Parent  d38f7cc80f9dc453e7968fdb594e0a1119003d14
hgweb: add a hook for processing LFS file transfer requests

As part of this, the PUT request needs to be handled to upload files.  Unlike
the requests to the Batch API, it is known that the consumer is a Mercurial
process.  So without any interoperability concerns, the URI starts with '/.hg',
and reflects where the files are actually stored.

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -101,6 +101,11 @@
     """
     raise ErrorResponse(HTTP_NOT_FOUND)
 
+def _processlfstransfer(repo, req):
+    """A hook for the LFS extension to wrap that handles file transfer requests.
+    """
+    raise ErrorResponse(HTTP_NOT_FOUND)
+
 class requestcontext(object):
     """Holds state/context for an individual request.
 
@@ -377,10 +382,12 @@
 
             return protohandler['dispatch']()
 
-        # Route LFS Batch API requests to the appropriate handler
+        # Route LFS Batch API and transfer requests to the appropriate handler
 
         if req.env[r'PATH_INFO'] == '/.git/info/lfs/objects/batch':
             return _processlfsbatchreq(rctx.repo, req)
+        elif req.env[r'PATH_INFO'].startswith('/.hg/store/lfs/objects'):
+            return _processlfstransfer(rctx.repo, req)
 
         # translate user-visible url structure to internal structure
 
diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -111,6 +111,9 @@
             self.log_error(r"Exception happened during processing "
                            r"request '%s':%s%s", self.path, newline, tb)
 
+    def do_PUT(self):
+        self.do_POST()
+
     def do_GET(self):
         self.do_POST()
 


More information about the Mercurial-devel mailing list