X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=rev-parse.c;h=b82f294a78994e512c4f30da5bb4ba3eca3f95b4;hb=a348ab702a84983c258e4961a58b1b9502f428c8;hp=42969a6fc1b7591b13a2fc664421e4f1da465cdb;hpb=d50125085a6c4775a77d45a6d294d723f6de8869;p=git.git diff --git a/rev-parse.c b/rev-parse.c index 42969a6f..b82f294a 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -53,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; @@ -103,12 +107,15 @@ static void show_rev(int type, const unsigned char *sha1, const char *name) } /* Output a flag, only if filter allows it. */ -static void show_flag(char *arg) +static int show_flag(char *arg) { if (!(filter & DO_FLAGS)) - return; - if (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV)) + return 0; + if (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV)) { show(arg); + return 1; + } + return 0; } static void show_default(void) @@ -143,11 +150,14 @@ static void show_datestring(const char *flag, const char *datestr) show(buffer); } -static void show_file(const char *arg) +static int show_file(const char *arg) { show_default(); - if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) + if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) { show(arg); + return 1; + } + return 0; } int main(int argc, char **argv) @@ -165,6 +175,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; @@ -199,15 +224,17 @@ int main(int argc, char **argv) verify = 1; continue; } - if (!strcmp(arg, "--abbrev") || - !strncmp(arg, "--abbrev=", 9)) { + 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 < 0 || 40 <= abbrev) - abbrev = DEFAULT_ABBREV; + if (abbrev < MINIMUM_ABBREV) + abbrev = MINIMUM_ABBREV; + else if (40 <= abbrev) + abbrev = 40; continue; } if (!strcmp(arg, "--sq")) { @@ -275,9 +302,8 @@ int main(int argc, char **argv) show_datestring("--min-age=", arg+8); continue; } - if (verify) + if (show_flag(arg) && verify) die("Needed a single revision"); - show_flag(arg); continue; } @@ -306,12 +332,13 @@ int main(int argc, char **argv) show_rev(REVERSED, sha1, arg+1); continue; } + as_is = 1; + if (!show_file(arg)) + continue; if (verify) die("Needed a single revision"); if (lstat(arg, &st) < 0) die("'%s': %s", arg, strerror(errno)); - as_is = 1; - show_file(arg); } show_default(); if (verify && revs_count != 1)