@matheusbsbs / matheus-bagliano / commits / c639a5548a
Fork 0

ls-tree: --name-only

Fingers of some "git diff" users are trained to do --name-only which git-ls-tree unfortunately does not take. With this, cd sub/directory && git-ls-tree -r --name-only .. would show only the names not object names nor modes. I threw in another synonym --name-status only for usability, but obviously ls-tree does not do any comparison so what it does is the same as --name-only. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 1, 2005 at 14:54 UTC c639a5548a5d8414b55202592885449f66ee2f33
1 file changed +11 -2
ls-tree.c
+11 -2
@@ -12,11 +12,12 @@ static int line_termination = '\n';
12 #define LS_RECURSIVE 1
13 #define LS_TREE_ONLY 2
14 #define LS_SHOW_TREES 4
15 +#define LS_NAME_ONLY 8
16 static int ls_options = 0;
17 const char **pathspec;
18
19 static const char ls_tree_usage[] =
19 - "git-ls-tree [-d] [-r] [-t] [-z] <tree-ish> [path...]";
20 + "git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] <tree-ish> [path...]";
21
22 static int show_recursive(const char *base, int baselen, const char *pathname)
23 {
@@ -64,7 +65,8 @@ static int show_tree(unsigned char *sha1, const char *base, int baselen, const c
65 else if (ls_options & LS_TREE_ONLY)
66 return 0;
67
67 - printf("%06o %s %s\t", mode, type, sha1_to_hex(sha1));
68 + if (!(ls_options & LS_NAME_ONLY))
69 + printf("%06o %s %s\t", mode, type, sha1_to_hex(sha1));
70 write_name_quoted(base, baselen, pathname, line_termination, stdout);
71 putchar(line_termination);
72 return retval;
@@ -92,6 +94,13 @@ int main(int argc, const char **argv)
94 case 't':
95 ls_options |= LS_SHOW_TREES;
96 break;
97 + case '-':
98 + if (!strcmp(argv[1]+2, "name-only") ||
99 + !strcmp(argv[1]+2, "name-status")) {
100 + ls_options |= LS_NAME_ONLY;
101 + break;
102 + }
103 + /* otherwise fallthru */
104 default:
105 usage(ls_tree_usage);
106 }