Patchwork [4,of,6] lfs: allow non-lfs exchanges when the extension is only enabled on one side

login
register
mail settings
Submitter Matt Harbison
Date Dec. 27, 2017, 8:27 a.m.
Message ID <95c326e8ae0acc171c8b.1514363276@Envy>
Download mbox | patch
Permalink /patch/26469/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 27, 2017, 8:27 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1514096796 18000
#      Sun Dec 24 01:26:36 2017 -0500
# Node ID 95c326e8ae0acc171c8b429776e52fc500ac055d
# Parent  a05cb56d887b0d94f0506fb6ad86a96dc0358c7d
lfs: allow non-lfs exchanges when the extension is only enabled on one side

Once the 'lfs' requirement is added, the extension must be loaded on both sides,
and changegroup3 used.  But there's no reason that I can see for bailing with
cryptic errors if lfs is not required, but randomly enabled somewhere.

Patch

diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -28,8 +28,9 @@ 
 
 def supportedoutgoingversions(orig, repo):
     versions = orig(repo)
-    versions.discard('01')
-    versions.discard('02')
+    if 'lfs' in repo.requirements:
+        versions.discard('01')
+        versions.discard('02')
     versions.add('03')
     return versions
 
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
@@ -70,21 +70,12 @@ 
   $ grep 'lfs' .hg/requires $SERVER_REQUIRES
   [1]
 
-TODO: fail more gracefully, or don't mandate changegroup3 for non-lfs repos.
-
   $ hg clone -q http://localhost:$HGPORT $TESTTMP/client1_clone
-  abort: HTTP Error 500: Internal Server Error
-  [255]
   $ grep 'lfs' $TESTTMP/client1_clone/.hg/requires $SERVER_REQUIRES
-  grep: $TESTTMP/client1_clone/.hg/requires: $ENOENT$
-  [2]
-
-TODO: fail more gracefully, or don't mandate changegroup3 for non-lfs repos.
+  [1]
 
   $ hg init $TESTTMP/client1_pull
   $ hg -R $TESTTMP/client1_pull pull -q http://localhost:$HGPORT
-  abort: HTTP Error 500: Internal Server Error
-  [255]
   $ grep 'lfs' $TESTTMP/client1_pull/.hg/requires $SERVER_REQUIRES
   [1]
 
@@ -104,10 +95,10 @@ 
   $ echo 'non-lfs' > nonlfs2.txt
   $ hg ci -Aqm 'non-lfs file with lfs client'
 
-TODO: fail more gracefully here
-  $ hg push -q 2>&1 | grep '^[A-Z]' || true
-  Traceback (most recent call last): (lfsremote-off !)
-  ValueError: no common changegroup version (lfsremote-off !)
+Since no lfs content has been added yet, the push is allowed, even when the
+extension is not enabled remotely.
+
+  $ hg push -q
   $ grep 'lfs' .hg/requires $SERVER_REQUIRES
   [1]
 
@@ -120,13 +111,8 @@ 
   $ grep 'lfs' $TESTTMP/client2_pull/.hg/requires $SERVER_REQUIRES
   [1]
 
-XXX: The difference here is the push failed above when the extension isn't
-enabled on the server.  The extension shouldn't need to mess with changegroup
-versions if there is no lfs content.  But the requirement needs to be
-consistently added before that can be ratcheted back.
   $ hg identify http://localhost:$HGPORT
-  1477875038c6 (lfsremote-on !)
-  000000000000 (lfsremote-off !)
+  1477875038c6
 
 --------------------------------------------------------------------------------
 Case #3: client with lfs content and the extension enabled; server with
@@ -157,13 +143,11 @@ 
   $TESTTMP/client3_pull/.hg/requires:lfs (lfsremote-on !)
   $TESTTMP/server/.hg/requires:lfs (lfsremote-on !)
 
-XXX: The difference here is the push failed above when the extension isn't
-enabled on the server.  The extension shouldn't need to mess with changegroup
-versions if there is no lfs content.  But the requirement needs to be
-consistently added before that can be ratcheted back.
+The difference here is the push failed above when the extension isn't
+enabled on the server.
   $ hg identify http://localhost:$HGPORT
   8374dc4052cb (lfsremote-on !)
-  000000000000 (lfsremote-off !)
+  1477875038c6 (lfsremote-off !)
 
 Don't bother testing the lfsremote-off cases- the server won't be able
 to launch if there's lfs content and the extension is disabled.
@@ -290,10 +274,6 @@ 
   ValueError: no common changegroup version
   Traceback (most recent call last):
   ValueError: no common changegroup version
-  Traceback (most recent call last):
-  ValueError: no common changegroup version
-  Traceback (most recent call last):
-  ValueError: no common changegroup version
 #else
   $ cat $TESTTMP/errors.log
 #endif