2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
11 static int line_termination = '\n';
12 #define LS_RECURSIVE 1
13 #define LS_TREE_ONLY 2
14 static int ls_options = 0;
15 const char **pathspec;
17 static const char ls_tree_usage[] =
18 "git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
20 static int show_tree(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
22 const char *type = "blob";
26 if (ls_options & LS_RECURSIVE)
27 return READ_TREE_RECURSIVE;
31 const char *spec = *s++;
36 if (strncmp(base, spec, baselen))
38 len = strlen(pathname);
40 speclen = strlen(spec);
43 if (memcmp(pathname, spec, len))
45 return READ_TREE_RECURSIVE;
51 printf("%06o %s %s\t", mode, type, sha1_to_hex(sha1));
52 write_name_quoted(base, baselen, pathname, line_termination, stdout);
53 putchar(line_termination);
57 int main(int argc, const char **argv)
60 unsigned char sha1[20];
64 prefix = setup_git_directory();
65 while (1 < argc && argv[1][0] == '-') {
71 ls_options |= LS_RECURSIVE;
74 ls_options |= LS_TREE_ONLY;
84 if (get_sha1(argv[1], sha1) < 0)
87 pathspec = get_pathspec(prefix, argv + 2);
88 buf = read_object_with_reference(sha1, "tree", &size, NULL);
90 die("not a tree object");
91 read_tree_recursive(buf, size, "", 0, 0, pathspec, show_tree);