git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ls-tree and wildcards
@ 2012-05-12 15:07 Ryan McCue
  2012-05-12 15:40 ` Nguyen Thai Ngoc Duy
  2012-05-14 16:43 ` Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: Ryan McCue @ 2012-05-12 15:07 UTC (permalink / raw)
  To: git

Good evening folks,

I'm attempting to grab relevant information for files in a tree matching 
a given pattern with wildcards. The help for ls-tree indicates that it 
can accept a pattern of files to match, however I'm not able to see that.

$ git ls-tree origin/master
...
100644 blob 8c391e8fb44a38e1389a710ebf8af79612e592a6    screenshot-1.png
100644 blob ecb7159c1c02567e9cd5da83c254c538d331f733    screenshot-2.png
100644 blob f58eea7e27f98c01038262b823aa73ccd64cb01e    screenshot-3.png
100644 blob 07e64def408145660cee657a46947077374762cc    screenshot-4.png
$ git ls-tree origin/master screenshot*
$

(I've also tried quoting to ensure it's not bash playing up)

Is there some issue with the command I'm issuing? The documentation 
seems to indicate that I should be getting back the files which match 
the pattern.

Thanks,

-- 
Ryan McCue
<http://ryanmccue.info/>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ls-tree and wildcards
  2012-05-12 15:07 ls-tree and wildcards Ryan McCue
@ 2012-05-12 15:40 ` Nguyen Thai Ngoc Duy
  2012-05-12 15:46   ` Ryan McCue
  2012-05-14 16:43 ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2012-05-12 15:40 UTC (permalink / raw)
  To: Ryan McCue; +Cc: git

On Sat, May 12, 2012 at 10:07 PM, Ryan McCue <lists@rotorised.com> wrote:
> Good evening folks,
>
> I'm attempting to grab relevant information for files in a tree matching a
> given pattern with wildcards. The help for ls-tree indicates that it can
> accept a pattern of files to match, however I'm not able to see that.
>
> $ git ls-tree origin/master
> ...
> 100644 blob 8c391e8fb44a38e1389a710ebf8af79612e592a6    screenshot-1.png
> 100644 blob ecb7159c1c02567e9cd5da83c254c538d331f733    screenshot-2.png
> 100644 blob f58eea7e27f98c01038262b823aa73ccd64cb01e    screenshot-3.png
> 100644 blob 07e64def408145660cee657a46947077374762cc    screenshot-4.png
> $ git ls-tree origin/master screenshot*
> $
>
> (I've also tried quoting to ensure it's not bash playing up)
>
> Is there some issue with the command I'm issuing? The documentation seems to
> indicate that I should be getting back the files which match the pattern.

I don't think it ever does. There's a mention of "patterns" in ls-tree
man page, which is misleading. We have the facilities to do that now
("lstree -r patterns" actually) but that might break backward
compatibility. For now I guess you can just do

GIT_INDEX_FILE=/tmp/some-temporary-index git read-tree origin/master
GIT_INDEX_FILE=/tmp/some-temporary-index ls-files <patterns>

A question that might help us understand your use case and give a
better advice, or improve the system: why do you need that?
-- 
Duy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ls-tree and wildcards
  2012-05-12 15:40 ` Nguyen Thai Ngoc Duy
@ 2012-05-12 15:46   ` Ryan McCue
  0 siblings, 0 replies; 6+ messages in thread
From: Ryan McCue @ 2012-05-12 15:46 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: git

Nguyen Thai Ngoc Duy wrote:
> I don't think it ever does. There's a mention of "patterns" in ls-tree
> man page, which is misleading.

Aha, I thought this might be the case. Thanks, I'll grep ls-tree then.

> A question that might help us understand your use case and give a
> better advice, or improve the system: why do you need that?

I need to be able to get all files starting with a certain string 
("screenshot-" in this case) with certain extensions ("png", "jpg", 
"jpeg" or "gif" in this case). Passing into grep will do the trick, but 
a single command is my preferred option if it exists.

I don't mind this not existing in git (given that piping into grep will 
work just as well), but reading "patterns" on the man page made me think 
it may exist. I think the wording of that should probably be changed to 
avoid confusion.

Thanks for the response.
-- 
Ryan McCue
<http://ryanmccue.info/>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ls-tree and wildcards
  2012-05-12 15:07 ls-tree and wildcards Ryan McCue
  2012-05-12 15:40 ` Nguyen Thai Ngoc Duy
@ 2012-05-14 16:43 ` Junio C Hamano
  2012-05-15 11:29   ` Nguyen Thai Ngoc Duy
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2012-05-14 16:43 UTC (permalink / raw)
  To: Ryan McCue; +Cc: git

Ryan McCue <lists@rotorised.com> writes:

> Good evening folks,
>
> I'm attempting to grab relevant information for files in a tree
> matching a given pattern with wildcards. The help for ls-tree
> indicates that it can accept a pattern of files to match,...

There are two uses of "pattern" there, and the former is probably OK but
the latter is indeed misleading.  Back when we wrote this command, there
were two distinct "pathspec" families, and ls-tree belong to the one with
"diff" family that did *not* take anything but "leading path pattern" (the
other one from "ls-files" and "grep" family allowed wildcards).  Giving a
wildcard to the command in the "ls-tree/diff" family was never supported.

Later Nguyen and others started working on unifying the two separate
"pathspec" semantics and we are probably halfway there.  Many of the
commands from "diff/log" family now can take wildcard (there may be new
bugs in the codepaths, though), but "ls-tree" has not been converted.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ls-tree and wildcards
  2012-05-14 16:43 ` Junio C Hamano
@ 2012-05-15 11:29   ` Nguyen Thai Ngoc Duy
  2012-05-15 15:35     ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2012-05-15 11:29 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ryan McCue, git

On Mon, May 14, 2012 at 11:43 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Later Nguyen and others started working on unifying the two separate
> "pathspec" semantics and we are probably halfway there.  Many of the
> commands from "diff/log" family now can take wildcard (there may be new
> bugs in the codepaths, though), but "ls-tree" has not been converted.

Do we break backward compatibility by teaching ls-tree new pathspec
semantics? I guess directories with wildcards in the name are rare,
the chance of someone doing "ls-tree a*" is low. But I may miss
something.
-- 
Duy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ls-tree and wildcards
  2012-05-15 11:29   ` Nguyen Thai Ngoc Duy
@ 2012-05-15 15:35     ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2012-05-15 15:35 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: Ryan McCue, git

Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:

> On Mon, May 14, 2012 at 11:43 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Later Nguyen and others started working on unifying the two separate
>> "pathspec" semantics and we are probably halfway there.  Many of the
>> commands from "diff/log" family now can take wildcard (there may be new
>> bugs in the codepaths, though), but "ls-tree" has not been converted.
>
> Do we break backward compatibility by teaching ls-tree new pathspec
> semantics? I guess directories with wildcards in the name are rare,
> the chance of someone doing "ls-tree a*" is low. But I may miss
> something.

If you change ls-tree to use its paths arguments as pathspec, you will
break backward compatibility.

But nobody stops us from _adding_ an option to ls-tree to tell it to
switch between the two, i.e.

	git ls-tree HEAD -- '*.c'
	git ls-tree --pathspec HEAD -- '*.c'

The former will use the traditional "leading path match only" while the
latter uses the (to-be) unified "pathspec" semantics.

Internally, the implementation could very well do something like this
after parsing the options:

	if (!opt_pathspec)
        	prefix ":(noglob)" to all paths args

and use the updated code with magic pathspec support to handle both cases.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-05-15 15:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-12 15:07 ls-tree and wildcards Ryan McCue
2012-05-12 15:40 ` Nguyen Thai Ngoc Duy
2012-05-12 15:46   ` Ryan McCue
2012-05-14 16:43 ` Junio C Hamano
2012-05-15 11:29   ` Nguyen Thai Ngoc Duy
2012-05-15 15:35     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).