[PATCH 5 of 6] lfs: add support for serving blob files
Matt Harbison
mharbison72 at gmail.com
Thu Mar 29 23:26:03 EDT 2018
On Thu, 29 Mar 2018 08:35:19 -0400, Yuya Nishihara <yuya at tcha.org> wrote:
> On Mon, 19 Mar 2018 00:08:28 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1521266024 14400
>> # Sat Mar 17 01:53:44 2018 -0400
>> # Node ID 7901a210c0c3c4a1f84fd21ff6e7c9b29454d6bc
>> # Parent a21db2355b92a6725ec51cd853d44a511a569bb7
>> lfs: add support for serving blob files
>>
>> diff --git a/hgext/lfs/wireprotolfsserver.py
>> b/hgext/lfs/wireprotolfsserver.py
>> --- a/hgext/lfs/wireprotolfsserver.py
>> +++ b/hgext/lfs/wireprotolfsserver.py
>> @@ -10,6 +10,7 @@ from __future__ import absolute_import
>> import datetime
>> import errno
>> import json
>> +import os
>>
>> from mercurial.hgweb import (
>> common as hgwebcommon,
>> @@ -25,6 +26,7 @@ from . import (
>> )
>>
>> HTTP_OK = hgwebcommon.HTTP_OK
>> +HTTP_CREATED = hgwebcommon.HTTP_CREATED
>> HTTP_BAD_REQUEST = hgwebcommon.HTTP_BAD_REQUEST
>>
>> def handlewsgirequest(orig, rctx, req, res, checkperm):
>> @@ -242,10 +244,46 @@ def _processbasictransfer(repo, req, res
>> """
>>
>> method = req.method
>> + oid = os.path.basename(req.dispatchpath)
>
> Nit: os.path.basename() shouldn't be used here because dispatchpath
> isn't a
> file path. Perhaps we should reject paths other than
> '.hg/lfs/objects/{oid}'.
Good point. The path check can't be too strict though, because I think
--prefix alters that. As it is, I can cause an assertion error with
certain --prefix values on default.
>
>> elif method == b'GET':
>> checkperm('pull')
>>
>> - return False
>> + res.status = hgwebcommon.statusmessage(HTTP_OK)
>> + res.headers[b'Content-Type'] = b'application/octet-stream'
>> +
>> + # TODO: figure out how to send back the file in chunks,
>> instead of
>> + # reading the whole thing.
>> + res.setbodybytes(localstore.read(oid))
>
> setbodygen()?
I saw that, but then it isn't clear to me how to close the file
descriptor, both in the normal and exceptional cases.
More information about the Mercurial-devel
mailing list