Patchwork [4,of,4,V3] lfs: handle paths that don't end with '/' when inferring the blob store

login
register
mail settings
Submitter Matt Harbison
Date April 11, 2018, 11:31 p.m.
Message ID <cf37bf9b296f3b9f4f24.1523489505@MATT7H-PC.attotech.com>
Download mbox | patch
Permalink /patch/30749/
State Accepted
Headers show

Comments

Matt Harbison - April 11, 2018, 11:31 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1523485409 14400
#      Wed Apr 11 18:23:29 2018 -0400
# Node ID cf37bf9b296f3b9f4f248f0f8bf3deb563033b11
# Parent  b6cfe8dcd4bb32aa963967eff4287a4643c850de
lfs: handle paths that don't end with '/' when inferring the blob store

While here, I also checked the lfs.url config directly instead of testing the
scheme, as requested by Yuya.

Patch

diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py
--- a/hgext/lfs/blobstore.py
+++ b/hgext/lfs/blobstore.py
@@ -539,23 +539,28 @@  def remote(repo, remote=None):
 
     https://github.com/git-lfs/git-lfs/blob/master/docs/api/server-discovery.md
     """
-    url = util.url(repo.ui.config('lfs', 'url') or '')
-    if url.scheme is None:
+    lfsurl = repo.ui.config('lfs', 'url')
+    url = util.url(lfsurl or '')
+    if lfsurl is None:
         if remote:
-            defaulturl = util.url(remote)
+            path = remote
         elif util.safehasattr(repo, '_subtoppath'):
             # The pull command sets this during the optional update phase, which
             # tells exactly where the pull originated, whether 'paths.default'
             # or explicit.
-            defaulturl = util.url(repo._subtoppath)
+            path = 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'')
+            path = repo.ui.config('paths', 'default') or ''
+
+        defaulturl = util.url(path)
 
         # TODO: support local paths as well.
         # TODO: consider the ssh -> https transformation that git applies
         if defaulturl.scheme in (b'http', b'https'):
+            if defaulturl.path and defaulturl.path[:-1] != b'/':
+                defaulturl.path += b'/'
             defaulturl.path = defaulturl.path or b'' + b'.git/info/lfs'
 
             url = util.url(bytes(defaulturl))