X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=rev-parse.c;h=6bf205a8f53c6af76bb1cc4df7bf37e46d378890;hb=2d310d8a018ca1a8d3e4c8a52f60ae5f57f34b31;hp=0c951af0d49da459fc6c85c32707b016bf581a57;hpb=2111168f314ac4f53932b8bbb16191a3855f5b6f;p=git.git diff --git a/rev-parse.c b/rev-parse.c index 0c951af0..6bf205a8 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; @@ -52,6 +53,10 @@ static int is_rev_argument(const char *arg) }; const char **p = rev_args; + /* accept -, like traditional "head" */ + if ((*arg == '-') && isdigit(arg[1])) + return 1; + for (;;) { const char *str = *p++; int len; @@ -95,6 +100,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)); } @@ -154,6 +161,7 @@ int main(int argc, char **argv) const char *prefix = setup_git_directory(); for (i = 1; i < argc; i++) { + struct stat st; char *arg = argv[i]; char *dotdot; @@ -161,6 +169,21 @@ int main(int argc, char **argv) show_file(arg); continue; } + if (!strcmp(arg,"-n")) { + if (++i >= argc) + die("-n requires an argument"); + if ((filter & DO_FLAGS) && (filter & DO_REVS)) { + show(arg); + show(argv[i]); + } + continue; + } + if (!strncmp(arg,"-n",2)) { + if ((filter & DO_FLAGS) && (filter & DO_REVS)) + show(arg); + continue; + } + if (*arg == '-') { if (!strcmp(arg, "--")) { as_is = 1; @@ -195,6 +218,19 @@ int main(int argc, char **argv) verify = 1; continue; } + if (!strcmp(arg, "--short") || + !strncmp(arg, "--short=", 9)) { + filter &= ~(DO_FLAGS|DO_NOREV); + verify = 1; + abbrev = DEFAULT_ABBREV; + if (arg[8] == '=') + abbrev = strtoul(arg + 9, NULL, 10); + if (abbrev < MINIMUM_ABBREV) + abbrev = MINIMUM_ABBREV; + else if (40 <= abbrev) + abbrev = 40; + continue; + } if (!strcmp(arg, "--sq")) { output_sq = 1; continue; @@ -293,6 +329,10 @@ int main(int argc, char **argv) } if (verify) die("Needed a single revision"); + if ((filter & DO_REVS) && + (filter & DO_NONFLAGS) && /* !def && */ + lstat(arg, &st) < 0) + die("'%s': %s", arg, strerror(errno)); as_is = 1; show_file(arg); }