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

ls-tree: add --abbrev[=<n>] option

Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed Mar 7, 2006 at 05:52 UTC cb85bfe5dfd7504dfee43ae49a76edb92e8d8eb0
2 files changed +25 -3
Documentation/git-ls-tree.txt
+8 -1
@@ -8,7 +8,9 @@ git-ls-tree - Lists the contents of a tree object
8
9 SYNOPSIS
10 --------
11 -'git-ls-tree' [-d] [-r] [-t] [-z] [--name-only] [--name-status] <tree-ish> [paths...]
11 +'git-ls-tree' [-d] [-r] [-t] [-z]
12 + [--name-only] [--name-status] [--full-name] [--abbrev=[<n>]]
13 + <tree-ish> [paths...]
14
15 DESCRIPTION
16 -----------
@@ -40,6 +42,11 @@ OPTIONS
42 --name-status::
43 List only filenames (instead of the "long" output), one per line.
44
45 +--abbrev[=<n>]::
46 + Instead of showing the full 40-byte hexadecimal object
47 + lines, show only handful hexdigits prefix.
48 + Non default number of digits can be specified with --abbrev=<n>.
49 +
50 paths::
51 When paths are given, show them (note that this isn't really raw
52 pathnames, but rather a list of patterns to match). Otherwise
ls-tree.c
+17 -2
@@ -13,13 +13,14 @@ static int line_termination = '\n';
13 #define LS_TREE_ONLY 2
14 #define LS_SHOW_TREES 4
15 #define LS_NAME_ONLY 8
16 +static int abbrev = 0;
17 static int ls_options = 0;
18 const char **pathspec;
19 static int chomp_prefix = 0;
20 static const char *prefix;
21
22 static const char ls_tree_usage[] =
22 - "git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] <tree-ish> [path...]";
23 + "git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]";
24
25 static int show_recursive(const char *base, int baselen, const char *pathname)
26 {
@@ -73,7 +74,9 @@ static int show_tree(unsigned char *sha1, const char *base, int baselen,
74 return 0;
75
76 if (!(ls_options & LS_NAME_ONLY))
76 - printf("%06o %s %s\t", mode, type, sha1_to_hex(sha1));
77 + printf("%06o %s %s\t", mode, type,
78 + abbrev ? find_unique_abbrev(sha1,abbrev)
79 + : sha1_to_hex(sha1));
80 write_name_quoted(base + chomp_prefix, baselen - chomp_prefix,
81 pathname,
82 line_termination, stdout);
@@ -113,6 +116,18 @@ int main(int argc, const char **argv)
116 chomp_prefix = 0;
117 break;
118 }
119 + if (!strncmp(argv[1]+2, "abbrev=",7)) {
120 + abbrev = strtoul(argv[1]+9, NULL, 10);
121 + if (abbrev && abbrev < MINIMUM_ABBREV)
122 + abbrev = MINIMUM_ABBREV;
123 + else if (abbrev > 40)
124 + abbrev = 40;
125 + break;
126 + }
127 + if (!strcmp(argv[1]+2, "abbrev")) {
128 + abbrev = DEFAULT_ABBREV;
129 + break;
130 + }
131 /* otherwise fallthru */
132 default:
133 usage(ls_tree_usage);