aboutsummaryrefslogtreecommitdiff
path: root/ls-files.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-03-07 11:59:17 -0800
committerJunio C Hamano <junkio@cox.net>2006-03-17 14:10:24 -0800
commitad0cae4cb9364b02b74b17f98f818a8e07372693 (patch)
treeb0eb548a7bfb8fc037a0627272f612a20e213731 /ls-files.c
parentcb85bfe5dfd7504dfee43ae49a76edb92e8d8eb0 (diff)
downloadgit-ad0cae4cb9364b02b74b17f98f818a8e07372693.tar.gz
git-ad0cae4cb9364b02b74b17f98f818a8e07372693.tar.xz
ls-files: add --abbrev[=<n>] option
Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'ls-files.c')
-rw-r--r--ls-files.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/ls-files.c b/ls-files.c
index df25c8c01..585f6a7ff 100644
--- a/ls-files.c
+++ b/ls-files.c
@@ -11,6 +11,7 @@
#include "cache.h"
#include "quote.h"
+static int abbrev = 0;
static int show_deleted = 0;
static int show_cached = 0;
static int show_others = 0;
@@ -488,7 +489,8 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
printf("%s%06o %s %d\t",
tag,
ntohl(ce->ce_mode),
- sha1_to_hex(ce->sha1),
+ abbrev ? find_unique_abbrev(ce->sha1,abbrev)
+ : sha1_to_hex(ce->sha1),
ce_stage(ce));
write_name_quoted("", 0, ce->name + offset,
line_terminator, stdout);
@@ -629,7 +631,8 @@ static void verify_pathspec(void)
static const char ls_files_usage[] =
"git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
- "[ --exclude-per-directory=<filename> ] [--full-name] [--] [<file>]*";
+ "[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] "
+ "[--] [<file>]*";
int main(int argc, const char **argv)
{
@@ -736,6 +739,18 @@ int main(int argc, const char **argv)
error_unmatch = 1;
continue;
}
+ if (!strncmp(arg, "--abbrev=", 9)) {
+ abbrev = strtoul(arg+9, NULL, 10);
+ if (abbrev && abbrev < MINIMUM_ABBREV)
+ abbrev = MINIMUM_ABBREV;
+ else if (abbrev > 40)
+ abbrev = 40;
+ continue;
+ }
+ if (!strcmp(arg, "--abbrev")) {
+ abbrev = DEFAULT_ABBREV;
+ continue;
+ }
if (*arg == '-')
usage(ls_files_usage);
break;