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;
16 static const char ls_tree_usage[] =
17 "git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
19 static int show_tree(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
21 const char *type = "blob";
26 if (ls_options & LS_RECURSIVE)
27 retval = READ_TREE_RECURSIVE;
30 printf("%06o %s %s\t%.*s%s%c", mode, type, sha1_to_hex(sha1), baselen, base, pathname, line_termination);
34 int main(int argc, const char **argv)
36 const char **path, *prefix;
37 unsigned char sha1[20];
41 prefix = setup_git_directory();
42 while (1 < argc && argv[1][0] == '-') {
48 ls_options |= LS_RECURSIVE;
51 ls_options |= LS_TREE_ONLY;
61 if (get_sha1(argv[1], sha1) < 0)
64 path = get_pathspec(prefix, argv + 2);
65 buf = read_object_with_reference(sha1, "tree", &size, NULL);
67 die("not a tree object");
68 read_tree_recursive(buf, size, "", 0, 0, path, show_tree);