X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=rev-parse.c;h=62e16af33c29ddd6a9c8b2d9755dc11804d86bc4;hb=b34c39cf31e370dad3bcfba29ee8cd023c40fd6b;hp=6bf205a8f53c6af76bb1cc4df7bf37e46d378890;hpb=8233340ce6eb700eb2cd9c0fef4d1705997c499b;p=git.git diff --git a/rev-parse.c b/rev-parse.c index 6bf205a8f..62e16af33 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -39,15 +39,15 @@ static int is_rev_argument(const char *arg) "--header", "--max-age=", "--max-count=", - "--merge-order", "--min-age=", "--no-merges", "--objects", + "--objects-edge", "--parents", "--pretty", - "--show-breaks", "--sparse", "--topo-order", + "--date-order", "--unpacked", NULL }; @@ -107,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) @@ -147,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) @@ -160,13 +166,15 @@ int main(int argc, char **argv) unsigned char sha1[20]; const char *prefix = setup_git_directory(); + git_config(git_default_config); + for (i = 1; i < argc; i++) { - struct stat st; char *arg = argv[i]; char *dotdot; - + if (as_is) { - show_file(arg); + if (show_file(arg) && as_is < 2) + verify_filename(prefix, arg); continue; } if (!strcmp(arg,"-n")) { @@ -186,7 +194,7 @@ int main(int argc, char **argv) if (*arg == '-') { if (!strcmp(arg, "--")) { - as_is = 1; + as_is = 2; /* Pass on the "--" if we show anything but files.. */ if (filter & (DO_FLAGS | DO_REVS)) show_file(arg); @@ -219,12 +227,12 @@ int main(int argc, char **argv) continue; } if (!strcmp(arg, "--short") || - !strncmp(arg, "--short=", 9)) { + !strncmp(arg, "--short=", 8)) { filter &= ~(DO_FLAGS|DO_NOREV); verify = 1; abbrev = DEFAULT_ABBREV; - if (arg[8] == '=') - abbrev = strtoul(arg + 9, NULL, 10); + if (arg[7] == '=') + abbrev = strtoul(arg + 8, NULL, 10); if (abbrev < MINIMUM_ABBREV) abbrev = MINIMUM_ABBREV; else if (40 <= abbrev) @@ -296,9 +304,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,16 +313,17 @@ int main(int argc, char **argv) dotdot = strstr(arg, ".."); if (dotdot) { unsigned char end[20]; - char *n = dotdot+2; + char *next = dotdot + 2; + char *this = arg; *dotdot = 0; - if (!get_sha1(arg, sha1)) { - if (!*n) - n = "HEAD"; - if (!get_sha1(n, end)) { - show_rev(NORMAL, end, n); - show_rev(REVERSED, sha1, arg); - continue; - } + if (!*next) + next = "HEAD"; + if (dotdot == arg) + this = "HEAD"; + if (!get_sha1(this, sha1) && !get_sha1(next, end)) { + show_rev(NORMAL, end, next); + show_rev(REVERSED, sha1, this); + continue; } *dotdot = '.'; } @@ -327,14 +335,12 @@ 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 ((filter & DO_REVS) && - (filter & DO_NONFLAGS) && /* !def && */ - lstat(arg, &st) < 0) - die("'%s': %s", arg, strerror(errno)); - as_is = 1; - show_file(arg); + verify_filename(prefix, arg); } show_default(); if (verify && revs_count != 1)