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

ls-files: 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 11:59 UTC ad0cae4cb9364b02b74b17f98f818a8e07372693
2 files changed +24 -4
Documentation/git-ls-files.txt
+7 -2
@@ -14,9 +14,9 @@ SYNOPSIS
14 (-[c|d|o|i|s|u|k|m])\*
15 [-x <pattern>|--exclude=<pattern>]
16 [-X <file>|--exclude-from=<file>]
17 - [--exclude-per-directory=<file>]
17 + [--exclude-per-directory=<file>]
18 [--error-unmatch]
19 - [--full-name] [--] [<file>]\*
19 + [--full-name] [--abbrev] [--] [<file>]\*
20
21 DESCRIPTION
22 -----------
@@ -98,6 +98,11 @@ OPTIONS
98 option forces paths to be output relative to the project
99 top directory.
100
101 +--abbrev[=<n>]::
102 + Instead of showing the full 40-byte hexadecimal object
103 + lines, show only handful hexdigits prefix.
104 + Non default number of digits can be specified with --abbrev=<n>.
105 +
106 --::
107 Do not interpret any more arguments as options.
108
ls-files.c
+17 -2
@@ -11,6 +11,7 @@
11 #include "cache.h"
12 #include "quote.h"
13
14 +static int abbrev = 0;
15 static int show_deleted = 0;
16 static int show_cached = 0;
17 static int show_others = 0;
@@ -488,7 +489,8 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
489 printf("%s%06o %s %d\t",
490 tag,
491 ntohl(ce->ce_mode),
491 - sha1_to_hex(ce->sha1),
492 + abbrev ? find_unique_abbrev(ce->sha1,abbrev)
493 + : sha1_to_hex(ce->sha1),
494 ce_stage(ce));
495 write_name_quoted("", 0, ce->name + offset,
496 line_terminator, stdout);
@@ -629,7 +631,8 @@ static void verify_pathspec(void)
631 static const char ls_files_usage[] =
632 "git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
633 "[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
632 - "[ --exclude-per-directory=<filename> ] [--full-name] [--] [<file>]*";
634 + "[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] "
635 + "[--] [<file>]*";
636
637 int main(int argc, const char **argv)
638 {
@@ -736,6 +739,18 @@ int main(int argc, const char **argv)
739 error_unmatch = 1;
740 continue;
741 }
742 + if (!strncmp(arg, "--abbrev=", 9)) {
743 + abbrev = strtoul(arg+9, NULL, 10);
744 + if (abbrev && abbrev < MINIMUM_ABBREV)
745 + abbrev = MINIMUM_ABBREV;
746 + else if (abbrev > 40)
747 + abbrev = 40;
748 + continue;
749 + }
750 + if (!strcmp(arg, "--abbrev")) {
751 + abbrev = DEFAULT_ABBREV;
752 + continue;
753 + }
754 if (*arg == '-')
755 usage(ls_files_usage);
756 break;