Code

Documentation: adjust to AsciiDoc 8
[git.git] / builtin-ls-tree.c
index b8d0d88ba85d7c9770f64288971963250dc3391c..1cb4dca277b511315d3b914239c57621fc60bcf3 100644 (file)
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "blob.h"
 #include "tree.h"
+#include "commit.h"
 #include "quote.h"
 #include "builtin.h"
 
@@ -14,11 +15,11 @@ static int line_termination = '\n';
 #define LS_TREE_ONLY 2
 #define LS_SHOW_TREES 4
 #define LS_NAME_ONLY 8
-static int abbrev = 0;
-static int ls_options = 0;
+static int abbrev;
+static int ls_options;
 static const char **pathspec;
-static int chomp_prefix = 0;
-static const char *prefix;
+static int chomp_prefix;
+static const char *ls_tree_prefix;
 
 static const char ls_tree_usage[] =
        "git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]";
@@ -59,7 +60,24 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
        int retval = 0;
        const char *type = blob_type;
 
-       if (S_ISDIR(mode)) {
+       if (S_ISDIRLNK(mode)) {
+               /*
+                * Maybe we want to have some recursive version here?
+                *
+                * Something like:
+                *
+               if (show_subprojects(base, baselen, pathname)) {
+                       if (fork()) {
+                               chdir(base);
+                               exec ls-tree;
+                       }
+                       waitpid();
+               }
+                *
+                * ..or similar..
+                */
+               type = commit_type;
+       } else if (S_ISDIR(mode)) {
                if (show_recursive(base, baselen, pathname)) {
                        retval = READ_TREE_RECURSIVE;
                        if (!(ls_options & LS_SHOW_TREES))
@@ -71,7 +89,7 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
                return 0;
 
        if (chomp_prefix &&
-           (baselen < chomp_prefix || memcmp(prefix, base, chomp_prefix)))
+           (baselen < chomp_prefix || memcmp(ls_tree_prefix, base, chomp_prefix)))
                return 0;
 
        if (!(ls_options & LS_NAME_ONLY))
@@ -85,13 +103,13 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
        return retval;
 }
 
-int cmd_ls_tree(int argc, const char **argv, char **envp)
+int cmd_ls_tree(int argc, const char **argv, const char *prefix)
 {
        unsigned char sha1[20];
        struct tree *tree;
 
-       prefix = setup_git_directory();
        git_config(git_default_config);
+       ls_tree_prefix = prefix;
        if (prefix && *prefix)
                chomp_prefix = strlen(prefix);
        while (1 < argc && argv[1][0] == '-') {
@@ -118,7 +136,7 @@ int cmd_ls_tree(int argc, const char **argv, char **envp)
                                chomp_prefix = 0;
                                break;
                        }
-                       if (!strncmp(argv[1]+2, "abbrev=",7)) {
+                       if (!prefixcmp(argv[1]+2, "abbrev=")) {
                                abbrev = strtoul(argv[1]+9, NULL, 10);
                                if (abbrev && abbrev < MINIMUM_ABBREV)
                                        abbrev = MINIMUM_ABBREV;