[PATCH 3 of 3] lfs: prefetch lfs blobs during revert

Yuya Nishihara yuya at tcha.org
Mon Feb 5 08:51:47 EST 2018


On Sun, 04 Feb 2018 01:18:25 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1517722408 18000
> #      Sun Feb 04 00:33:28 2018 -0500
> # Node ID 702a3c1d6335cd8f7cf7916029e10e22691e3091
> # Parent  e779b0c34d6989e45cabbf8da8cdfeb060134dbd
> lfs: prefetch lfs blobs during revert
> 
> The revert command oddly prints out what it will do before requesting the files
> to be prefetched.  But the 'need to transfer' line indicates the blobs are being
> grouped.
> 
> diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
> --- a/hgext/lfs/__init__.py
> +++ b/hgext/lfs/__init__.py
> @@ -333,6 +333,7 @@
>      wrapfunction(hg, 'postshare', wrapper.hgpostshare)
>  
>      wrapfunction(merge, 'applyupdates', wrapper.mergemodapplyupdates)
> +    wrapfunction(cmdutil, '_revertprefetch', wrapper._revertprefetch)
>  
>      # Make bundle choose changegroup3 instead of changegroup2. This affects
>      # "hg bundle" command. Note: it does not cover all bundle formats like
> diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
> --- a/hgext/lfs/wrapper.py
> +++ b/hgext/lfs/wrapper.py
> @@ -277,6 +277,23 @@
>  
>      return orig(repo, actions, wctx, mctx, overwrite, labels)
>  
> +def _revertprefetch(orig, repo, ctx, *files):
> +    """Prefetch the indicated files before the revert operation is performed."""
> +    orig(repo, ctx, *files)
> +
> +    pointers = []
> +    localstore = repo.svfs.lfslocalblobstore
> +
> +    for group in files:
> +        for f in group:
> +            p = pointerfromctx(ctx, f)
> +            if p and not localstore.has(p.oid()):
> +                p.filename = f
> +                pointers.append(p)
> +
> +    if pointers:
> +        repo.svfs.lfsremoteblobstore.readbatch(pointers, localstore)

This looks good to me.

It might be better to provide a single hook point for prefetching, because
it isn't a trivial task to parse merge actions into a list of files.


More information about the Mercurial-devel mailing list