summaryrefslogtreecommitdiff
path: root/rev-parse.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-01-25 01:35:38 -0800
committerJunio C Hamano <junkio@cox.net>2006-01-28 00:09:38 -0800
commitd50125085a6c4775a77d45a6d294d723f6de8869 (patch)
tree29eb6fc7c583f238097cfb412a91e778ea540bd0 /rev-parse.c
parent46a6c2620ba421397eec627b8eb18eb530e694fc (diff)
downloadgit-d50125085a6c4775a77d45a6d294d723f6de8869.tar.gz
rev-parse: --abbrev option.
The new option behaves just like --verify, but outputs an abbreviated object name that is unique within the repository. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'rev-parse.c')
-rw-r--r--rev-parse.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/rev-parse.c b/rev-parse.c
index 7abad35de9..42969a6fc1 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -20,6 +20,7 @@ static char *def = NULL;
#define REVERSED 1
static int show_type = NORMAL;
static int symbolic = 0;
+static int abbrev = 0;
static int output_sq = 0;
static int revs_count = 0;
@@ -95,6 +96,8 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
putchar('^');
if (symbolic && name)
show(name);
+ else if (abbrev)
+ show(find_unique_abbrev(sha1, abbrev));
else
show(sha1_to_hex(sha1));
}
@@ -196,6 +199,17 @@ int main(int argc, char **argv)
verify = 1;
continue;
}
+ if (!strcmp(arg, "--abbrev") ||
+ !strncmp(arg, "--abbrev=", 9)) {
+ filter &= ~(DO_FLAGS|DO_NOREV);
+ verify = 1;
+ abbrev = DEFAULT_ABBREV;
+ if (arg[8] == '=')
+ abbrev = strtoul(arg + 9, NULL, 10);
+ if (abbrev < 0 || 40 <= abbrev)
+ abbrev = DEFAULT_ABBREV;
+ continue;
+ }
if (!strcmp(arg, "--sq")) {
output_sq = 1;
continue;