[PATCH] files: recurse into subrepos automatically with an explicit path
Matt Harbison
mharbison72 at gmail.com
Thu May 21 00:28:03 UTC 2015
On Wed, 20 May 2015 00:40:15 -0400, Martin von Zweigbergk
<martinvonz at google.com> wrote:
> Somewhat of topic: I'm working on a series that makes "match.files()"
> have
> the empty list as a valid value even for matchers other than
> always-matchers. I noticed that narrowmatcher can make match.files()
> empty.
> Have you run into any bugs caused by that (code interpreting that as
> "match
> all files in subrepo")? I'm working on it because it will help another
> series, but I wonder if it might help existing code as well.
Just the opposite actually:
http://selenic.com/repo/hg//rev/ef4538ba67ef
The only thing a subrepo needs is if an explicit path is named on the
command line, it needs to be in files() so that automatic entry (without
-S) into the subrepo occurs. It does look like there are a few subrepo
methods that assume files() is populated, and so does the base archive
method. Not sure how it would react to your changes.
I should probably move the matchessubrepo() method below to the matcher,
since I've done it a few slightly different ways now, and some subrepo
supported methods don't use it at all. Then you could customize it if you
need to. That said, I'm not sure what to call it, since the matcher
doesn't know about subrepos- this is really just a dir check.
I'm almost positive I've seen a comment along the lines of "empty files
means match everything", and I'm betting it is in largefiles somewhere.
I'm assuming your change is -I/-X related? I don't think subrepos have
much coverage for that.
> On Tue, May 19, 2015, 20:53 Matt Harbison <mharbison72 at gmail.com> wrote:
>
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1431916967 14400
>> # Sun May 17 22:42:47 2015 -0400
>> # Node ID a956025619e7af9f1dff763430f07dac6b84fd13
>> # Parent a39c35e8e559e238f311c647679e8de3b91748c6
>> files: recurse into subrepos automatically with an explicit path
>>
>> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
>> --- a/mercurial/cmdutil.py
>> +++ b/mercurial/cmdutil.py
>> @@ -2297,12 +2297,16 @@
>> fm.write('path', fmt, m.rel(f))
>> ret = 0
>>
>> - if subrepos:
>> - for subpath in sorted(ctx.substate):
>> + for subpath in sorted(ctx.substate):
>> + def matchessubrepo(subpath):
>> + return (m.always() or m.exact(subpath)
>> + or any(f.startswith(subpath + '/') for f in
>> m.files()))
>> +
>> + if subrepos or matchessubrepo(subpath):
>> sub = ctx.sub(subpath)
>> try:
>> submatch = matchmod.narrowmatcher(subpath, m)
>> - if sub.printfiles(ui, submatch, fm, fmt) == 0:
>> + if sub.printfiles(ui, submatch, fm, fmt, subrepos) ==
>> 0:
>> ret = 0
>> except error.LookupError:
>> ui.status(_("skipping missing subrepository: %s\n")
>> diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt
>> --- a/mercurial/help/subrepos.txt
>> +++ b/mercurial/help/subrepos.txt
>> @@ -109,8 +109,10 @@
>> elements. Subversion subrepositories are currently silently
>> ignored.
>>
>> :files: files does not recurse into subrepos unless -S/--subrepos is
>> - specified. Git and Subversion subrepositories are currently
>> - silently ignored.
>> + specified. However, if you specify the full path of a file or
>> + directory in a subrepo, it will be displayed even without
>> + -S/--subrepos being specified. Git and Subversion subrepositories
>> + are currently silently ignored.
>>
>> :forget: forget currently only handles exact file matches in subrepos.
>> Git and Subversion subrepositories are currently silently ignored.
>> diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
>> --- a/mercurial/subrepo.py
>> +++ b/mercurial/subrepo.py
>> @@ -504,7 +504,7 @@
>> """Resolve the fileset expression for this repo"""
>> return set()
>>
>> - def printfiles(self, ui, m, fm, fmt):
>> + def printfiles(self, ui, m, fm, fmt, subrepos):
>> """handle the files command for this subrepo"""
>> return 1
>>
>> @@ -904,7 +904,7 @@
>> return ctx.flags(name)
>>
>> @annotatesubrepoerror
>> - def printfiles(self, ui, m, fm, fmt):
>> + def printfiles(self, ui, m, fm, fmt, subrepos):
>> # If the parent context is a workingctx, use the workingctx
>> here
>> for
>> # consistency.
>> if self._ctx.rev() is None:
>> @@ -912,7 +912,7 @@
>> else:
>> rev = self._state[1]
>> ctx = self._repo[rev]
>> - return cmdutil.files(ui, ctx, m, fm, fmt, True)
>> + return cmdutil.files(ui, ctx, m, fm, fmt, subrepos)
>>
>> @annotatesubrepoerror
>> def getfileset(self, expr):
>> diff --git a/tests/test-subrepo-deep-nested-change.t
>> b/tests/test-subrepo-deep-nested-change.t
>> --- a/tests/test-subrepo-deep-nested-change.t
>> +++ b/tests/test-subrepo-deep-nested-change.t
>> @@ -232,6 +232,18 @@
>> sub1/sub2/sub2 (glob)
>> sub1/sub2/test.txt (glob)
>>
>> + $ hg files sub1
>> + sub1/.hgsub (glob)
>> + sub1/.hgsubstate (glob)
>> + sub1/foo (glob)
>> + sub1/sub1 (glob)
>> + sub1/sub2/folder/bar (glob)
>> + sub1/sub2/x.txt (glob)
>> +
>> + $ hg files sub1/sub2
>> + sub1/sub2/folder/bar (glob)
>> + sub1/sub2/x.txt (glob)
>> +
>> $ hg files -S -r '.^' sub1/sub2/folder
>> sub1/sub2/folder/test.txt (glob)
>>
>> @@ -239,7 +251,7 @@
>> sub1/sub2/missing: no such file in rev 78026e779ea6 (glob)
>> [1]
>>
>> - $ hg files -S -r '.^' sub1/
>> + $ hg files -r '.^' sub1/
>> sub1/.hgsub (glob)
>> sub1/.hgsubstate (glob)
>> sub1/sub1 (glob)
>> @@ -247,7 +259,7 @@
>> sub1/sub2/sub2 (glob)
>> sub1/sub2/test.txt (glob)
>>
>> - $ hg files -S -r '.^' sub1/sub2
>> + $ hg files -r '.^' sub1/sub2
>> sub1/sub2/folder/test.txt (glob)
>> sub1/sub2/sub2 (glob)
>> sub1/sub2/test.txt (glob)
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list