[PATCH 5 of 6] lfs: add support for serving blob files

Yuya Nishihara yuya at tcha.org
Thu Mar 29 12:35:19 UTC 2018


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}'.

>      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()?



More information about the Mercurial-devel mailing list