Patchwork [V2] lfs: respect narrowmatcher when testing to add 'lfs' requirement (issue5794)

login
register
mail settings
Submitter Matt Harbison
Date March 28, 2018, 12:33 a.m.
Message ID <f9c8f2bd9362baaeba82.1522197181@Envy>
Download mbox | patch
Permalink /patch/29913/
State Accepted
Headers show

Comments

Matt Harbison - March 28, 2018, 12:33 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1522117116 14400
#      Mon Mar 26 22:18:36 2018 -0400
# Node ID f9c8f2bd9362baaeba828f8d6eb7559a748fcc3f
# Parent  aaabd709df720e456d7f93a1c790a0dbed051b38
lfs: respect narrowmatcher when testing to add 'lfs' requirement (issue5794)

There's a similar test in lfs.wrapper.convertsink(), but I didn't update that
because I don't think that the sink repo in a convert can be narrow.

It seems reasonable that a narrow clone of an LFS repo may not necessarily be an
LFS repo.  The only potential issue is that LFS has a hard requirement for
changegroup v3, which that extension enables.  The use of treemanifest will
enable changegroup v3 in narrow clones, because allsupportedversions() in
changegroup.py preserves it when it sees a 'treemanifest' requirement.  But I
don't see where changegroup v3 is enabled for a flat manifest.
Yuya Nishihara - March 28, 2018, 12:01 p.m.
On Tue, 27 Mar 2018 20:33:01 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1522117116 14400
> #      Mon Mar 26 22:18:36 2018 -0400
> # Node ID f9c8f2bd9362baaeba828f8d6eb7559a748fcc3f
> # Parent  aaabd709df720e456d7f93a1c790a0dbed051b38
> lfs: respect narrowmatcher when testing to add 'lfs' requirement (issue5794)

Queued, thanks.

Patch

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -226,9 +226,11 @@  def reposetup(ui, repo):
                     s = repo.set('%n:%n', _bin(kwargs[r'node']), _bin(last))
                 else:
                     s = repo.set('%n', _bin(kwargs[r'node']))
+            match = repo.narrowmatch()
             for ctx in s:
                 # TODO: is there a way to just walk the files in the commit?
-                if any(ctx[f].islfs() for f in ctx.files() if f in ctx):
+                if any(ctx[f].islfs() for f in ctx.files()
+                       if f in ctx and match(f)):
                     repo.requirements.add('lfs')
                     repo._writerequirements()
                     repo.prepushoutgoinghooks.add('lfs', wrapper.prepush)
diff --git a/tests/test-narrow-commit.t b/tests/test-narrow-commit.t
--- a/tests/test-narrow-commit.t
+++ b/tests/test-narrow-commit.t
@@ -28,7 +28,11 @@  create full repo
 
   $ cd ..
 
-  $ hg clone --narrow ssh://user@dummy/master narrow --include inside
+(The lfs extension does nothing here, but this test ensures that its hook that
+determines whether to add the lfs requirement, respects the narrow boundaries.)
+
+  $ hg --config extensions.lfs= clone --narrow ssh://user@dummy/master narrow \
+  >    --include inside
   requesting all changes
   adding changesets
   adding manifests