On Sun, 27 Nov 2005, Petr Baudis wrote:
Dear diary, on Sun, Nov 27, 2005 at 07:01:37PM CET, I got a letter
where Linus Torvalds [off-list ref] said that...
quoted
If you use "-r", it acts the way you'd expect. If you _don't_ use "-r", it
acts strangely, but very consistently with git-diff-tree: it only ever
shows the _first_ part of a pathname. So
git-ls-tree HEAD drivers/char/
should show just one entry: "drivers". While adding a "-r" should show all
files under drivers (and the trees leading up to it).
And yes, you're right. That's a much bigger change by my suggested diff,
and more likely to cause confusion.
Ugh. That's really weird. Wouldn't a better approach be to fix
git-ls-files to behave more sanely? (That is, listing the entry for
drivers/char instead of drivers?)
Well, it's not actually confusing if you see a path spec for what it is:
it's not a filename, it's a _pattern_.
So you should always do
git-ls-tree -r pattern
(and yes, we could even hardcode "-r", because git-ls-tree without it
really is a pretty strange thing).
The _real_ strangeness in "git-ls-tree" is that it shows the tree nodes at
all, which no other git tool does when it recurses.
To get more a "git-ls-files" approach, this trivial patch (on top of my
previous one) enables recursion (and right now you can't disable it any
way), and doesn't show partial trees.
I could make it work much more like git-ls-files, in that it could accept
wildcards. Something like
git-ls-tree HEAD '*.c'
would show all C files (recursively), the same way git-ls-files does for
the index.
Hmm?
Linus
----
diff --git a/ls-tree.c b/ls-tree.c
index 598b729..cf0dbbc 100644
--- a/ls-tree.c
+++ b/ls-tree.c
@@ -11,7 +11,7 @@
static int line_termination = '\n';
#define LS_RECURSIVE 1
#define LS_TREE_ONLY 2
-static int ls_options = 0;
+static int ls_options = LS_RECURSIVE;
static const char ls_tree_usage[] =
"git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
@@ -19,16 +19,15 @@ static const char ls_tree_usage[] =
static int show_tree(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
{
const char *type = "blob";
- int retval = 0;
if (S_ISDIR(mode)) {
- type = "tree";
if (ls_options & LS_RECURSIVE)
- retval = READ_TREE_RECURSIVE;
+ return READ_TREE_RECURSIVE;
+ type = "tree";
}
printf("%06o %s %s\t%.*s%s%c", mode, type, sha1_to_hex(sha1), baselen, base, pathname, line_termination);
- return retval;
+ return 0;
}
int main(int argc, const char **argv)