Patchwork [4,of,6] lfs: infer the blob store URL from an explicit pull source

login
register
mail settings
Submitter Matt Harbison
Date April 9, 2018, 4:26 a.m.
Message ID <2aecf5b7dfdaeb12a6f6.1523248004@Envy>
Download mbox | patch
Permalink /patch/30583/
State Accepted
Headers show

Comments

Matt Harbison - April 9, 2018, 4:26 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1523165019 14400
#      Sun Apr 08 01:23:39 2018 -0400
# Node ID 2aecf5b7dfdaeb12a6f6ac151d40c3b60f789abc
# Parent  3d5a3d9692c0e9f3424a3eac148bef674580885f
lfs: infer the blob store URL from an explicit pull source

I don't see any easier way to do this, so (ab)use the mechanism used by subrepos
to redirect where subrepos are pulled from when an explicit path is given.  As a
bonus, this should allow lfs blobs to be pulled into a subrepo when it is
checked out.

Unfortunately, this doesn't work for an explicit push path, because the field is
only present while subrepos are pushed, which is prior to when the main repo is.

Patch

diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py
--- a/hgext/lfs/blobstore.py
+++ b/hgext/lfs/blobstore.py
@@ -538,9 +538,16 @@  def remote(repo):
     """
     url = util.url(repo.ui.config('lfs', 'url') or '')
     if url.scheme is None:
-        # TODO: investigate 'paths.remote:lfsurl' style path customization,
-        # and fall back to inferring from 'paths.remote' if unspecified.
-        defaulturl = util.url(repo.ui.config('paths', 'default') or b'')
+        # The pull command sets this during the optional update phase, which
+        # tells exactly where the pull originated, whether 'paths.default' or
+        # explicit.  Sadly, the push command only sets this for the duration of
+        # any subrepo push, and clears it before pushing the main repo.
+        if util.safehasattr(repo, '_subtoppath'):
+            defaulturl = util.url(repo._subtoppath)
+        else:
+            # TODO: investigate 'paths.remote:lfsurl' style path customization,
+            # and fall back to inferring from 'paths.remote' if unspecified.
+            defaulturl = util.url(repo.ui.config('paths', 'default') or b'')
 
         # TODO: support local paths as well.
         if defaulturl.scheme and defaulturl.scheme != b'file':
diff --git a/tests/test-lfs-serve.t b/tests/test-lfs-serve.t
--- a/tests/test-lfs-serve.t
+++ b/tests/test-lfs-serve.t
@@ -252,7 +252,26 @@  lfs content, and the extension enabled.
   $TESTTMP/server/.hg/requires:lfs
 
   $ hg init $TESTTMP/client6_pull
-  $ hg -R $TESTTMP/client6_pull pull -q http://localhost:$HGPORT
+  $ hg -R $TESTTMP/client6_pull pull -u -v http://localhost:$HGPORT
+  pulling from http://localhost:$HGPORT/
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 6 changesets with 5 changes to 5 files (+1 heads)
+  calling hook pretxnchangegroup.lfs: hgext.lfs.checkrequireslfs
+  new changesets d437e1d24fbd:d3b84d50eacb
+  resolving manifests
+  lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
+  lfs: downloading a82f1c5cea0d40e3bb3a849686bb4e6ae47ca27e614de55c1ed0325698ef68de (25 bytes)
+  lfs: processed: a82f1c5cea0d40e3bb3a849686bb4e6ae47ca27e614de55c1ed0325698ef68de
+  getting lfs2.txt
+  lfs: found a82f1c5cea0d40e3bb3a849686bb4e6ae47ca27e614de55c1ed0325698ef68de in the local lfs store
+  getting nonlfs2.txt
+  getting nonlfs3.txt
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  updated to "d3b84d50eacb: lfs file with lfs client"
+  1 other heads for branch "default"
   $ grep 'lfs' $TESTTMP/client6_pull/.hg/requires $SERVER_REQUIRES
   $TESTTMP/client6_pull/.hg/requires:lfs
   $TESTTMP/server/.hg/requires:lfs
@@ -281,3 +300,4 @@  Misc: process dies early if a requiremen
 #else
   $ cat $TESTTMP/errors.log
 #endif
+