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
= LS_RECURSIVE
;
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";
24 if (ls_options
& LS_RECURSIVE
)
25 return READ_TREE_RECURSIVE
;
29 printf("%06o %s %s\t%.*s%s%c", mode
, type
, sha1_to_hex(sha1
), baselen
, base
, pathname
, line_termination
);
33 int main(int argc
, const char **argv
)
35 const char **path
, *prefix
;
36 unsigned char sha1
[20];
40 prefix
= setup_git_directory();
41 while (1 < argc
&& argv
[1][0] == '-') {
47 ls_options
|= LS_RECURSIVE
;
50 ls_options
|= LS_TREE_ONLY
;
60 if (get_sha1(argv
[1], sha1
) < 0)
63 path
= get_pathspec(prefix
, argv
+ 2);
64 buf
= read_object_with_reference(sha1
, "tree", &size
, NULL
);
66 die("not a tree object");
67 read_tree_recursive(buf
, size
, "", 0, 0, path
, show_tree
);