Skip to content

Commit

Permalink
rev-parse: --abbrev option.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jan 28, 2006
1 parent 46a6c26 commit d501250
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d501250

Please sign in to comment.