[PATCH 1 of 3] hgweb: add a hook for processing LFS Batch API requests

Matt Harbison mharbison72 at gmail.com
Mon Feb 26 12:08:42 EST 2018


> On Feb 26, 2018, at 8:47 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> 
>> On Thu, 22 Feb 2018 01:02:41 -0500, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1519274700 18000
>> #      Wed Feb 21 23:45:00 2018 -0500
>> # Node ID d38f7cc80f9dc453e7968fdb594e0a1119003d14
>> # Parent  c8891cc3fa9ec855a3bdefd3dd759d19927c6b85
>> hgweb: add a hook for processing LFS Batch API requests
>> 
>> There really isn't a clean way to give LFS a crack at intercepting the requests
>> without hardcoding some LFS knowledge in the core.  The rationale for this URI
>> is that the spec for the Batch API[1] defines the URL as the LFS server url +
>> '/objects/batch'.  The default git URLs are:
>> 
>>    Git remote: https://git-server.com/foo/bar
>>    LFS server: https://git-server.com/foo/bar.git/info/lfs
>>    Batch API: https://git-server.com/foo/bar.git/info/lfs/objects/batch
>> 
>> '.git/' seems like it's not something a user would normally track.  If we adhere
>> to how git defines the URLs, then the hg-git extension should be able to talk to
>> a git based server without any additional work.
>> 
>> [1] https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
>> 
>> 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
>> @@ -95,6 +95,12 @@
>>         urlel = os.path.dirname(urlel)
>>     return reversed(breadcrumb)
>> 
>> +def _processlfsbatchreq(repo, req):
>> +    """A hook for the LFS extension to wrap that handles requests to the Batch
>> +    API, and returns the appropriate JSON response.
>> +    """
>> +    raise ErrorResponse(HTTP_NOT_FOUND)
>> +
>> class requestcontext(object):
>>     """Holds state/context for an individual request.
>> 
>> @@ -371,6 +377,11 @@
>> 
>>             return protohandler['dispatch']()
>> 
>> +        # Route LFS Batch API requests to the appropriate handler
>> +
>> +        if req.env[r'PATH_INFO'] == '/.git/info/lfs/objects/batch':
>> +            return _processlfsbatchreq(rctx.repo, req)
> 
> (CC: indygreg as web expert)
> 
> I'm not pretty sure, but given we do "'PATH_INFO' in req.env" before,
> req.env['PATH_INFO'] could be missing.

One of the things I’m unsure of is how fundamental things like that go missing, and what to do in that case.

> And maybe we'll need some check_perm().

I’m a bit unclear on how the permission stuff works, because there’s a bit of auth stuff in lfs too.  I figured the lfs layer might need to do something, but that might be clearer after some of this stuff is in place. I can put this under an experimental config if there’s concern it might get forgotten about before the release.



More information about the Mercurial-devel mailing list