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

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>

Junio C Hamano committed Jan 25, 2006 at 01:35 UTC d50125085a6c4775a77d45a6d294d723f6de8869
1 file changed +14
rev-parse.c
+14
@@ -20,6 +20,7 @@ static char *def = NULL;
20 #define REVERSED 1
21 static int show_type = NORMAL;
22 static int symbolic = 0;
23 +static int abbrev = 0;
24 static int output_sq = 0;
25
26 static int revs_count = 0;
@@ -95,6 +96,8 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
96 putchar('^');
97 if (symbolic && name)
98 show(name);
99 + else if (abbrev)
100 + show(find_unique_abbrev(sha1, abbrev));
101 else
102 show(sha1_to_hex(sha1));
103 }
@@ -196,6 +199,17 @@ int main(int argc, char **argv)
199 verify = 1;
200 continue;
201 }
202 + if (!strcmp(arg, "--abbrev") ||
203 + !strncmp(arg, "--abbrev=", 9)) {
204 + filter &= ~(DO_FLAGS|DO_NOREV);
205 + verify = 1;
206 + abbrev = DEFAULT_ABBREV;
207 + if (arg[8] == '=')
208 + abbrev = strtoul(arg + 9, NULL, 10);
209 + if (abbrev < 0 || 40 <= abbrev)
210 + abbrev = DEFAULT_ABBREV;
211 + continue;
212 + }
213 if (!strcmp(arg, "--sq")) {
214 output_sq = 1;
215 continue;