]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls-tree: further cleanup to parallel ls-files.
authorLinus Torvalds <torvalds@osdl.org>
Sun, 27 Nov 2005 19:00:09 +0000 (11:00 -0800)
committerJunio C Hamano <junkio@cox.net>
Tue, 29 Nov 2005 07:00:14 +0000 (23:00 -0800)
To get more a "git-ls-files" approach, this trivial patch (on top of my
previous one) enables recursion, and doesn't show partial trees.

[jc: after further discussion, this version enables recursion by default,
 and you can disable it with "-d" flag.

git-ls-tree -d HEAD Documentation/no/such/directory

 shows Documentation tree (without -d it shows nothing).

git-ls-tree HEAD

 shows everything from the tree.  Only to get the single level from the top

git-ls-tree -d HEAD

 is needed.  But there is no way to get the single level with pathspec.
 You need to extract the object name of Documentation tree from the parent
 tree and run

git-ls-tree -d $tree_id_of_Documentation_tree

 to get something similar to what you can get from the current

git-ls-tree HEAD Documentation
 ]

ls-tree.c

index 598b729497370ef8a91477534759933d20c8a620..cf0dbbc7e4070d81cd52027ef5c1cc983949395a 100644 (file)
--- 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)