X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=rev-parse.c;h=9281b45d1f54dda858d7adff14e90f8e94eccc13;hb=fb2af0375bcef9f5f5cbb1f4dc9f81459ce1f4b1;hp=1c6ae76f9aa32dab77a4189a4ae6b744d39cee36;hpb=f69714c38c6f3296a4bfba0d057e0f1605373f49;p=git.git diff --git a/rev-parse.c b/rev-parse.c index 1c6ae76f..9281b45d 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -16,6 +16,7 @@ static int output_revs = 0; static int flags_only = 0; static int no_flags = 0; static int output_sq = 0; +static int symbolic = 0; #define NORMAL 0 #define REVERSED 1 @@ -69,17 +70,18 @@ static void show(const char *arg) puts(arg); } -static void show_rev(int type, const unsigned char *sha1) +static void show_rev(int type, const unsigned char *sha1, const char *name) { if (no_revs) return; output_revs++; - /* Hexadecimal string plus possibly a carret; - * this does not have to be quoted even under output_sq. - */ - printf("%s%s%c", type == show_type ? "" : "^", sha1_to_hex(sha1), - output_sq ? ' ' : '\n'); + if (type != show_type) + putchar('^'); + if (symbolic && name) + show(name); + else + show(sha1_to_hex(sha1)); } static void show_rev_arg(char *rev) @@ -105,7 +107,7 @@ static void show_arg(char *arg) if (do_rev_argument && is_rev_argument(arg)) show_rev_arg(arg); else - show_norev(arg); + show(arg); } static void show_default(void) @@ -117,16 +119,16 @@ static void show_default(void) def = NULL; if (!get_sha1(s, sha1)) { - show_rev(NORMAL, sha1); + show_rev(NORMAL, sha1, s); return; } - show_arg(s); + show_norev(s); } } static int show_reference(const char *refname, const unsigned char *sha1) { - show_rev(NORMAL, sha1); + show_rev(NORMAL, sha1, refname); return 0; } @@ -134,7 +136,8 @@ int main(int argc, char **argv) { int i, as_is = 0; unsigned char sha1[20]; - + const char *prefix = setup_git_directory(); + for (i = 1; i < argc; i++) { char *arg = argv[i]; char *dotdot; @@ -146,7 +149,7 @@ int main(int argc, char **argv) if (*arg == '-') { if (!strcmp(arg, "--")) { show_default(); - if (revs_only) + if (revs_only || flags_only) break; as_is = 1; } @@ -185,10 +188,18 @@ int main(int argc, char **argv) show_type ^= REVERSED; continue; } + if (!strcmp(arg, "--symbolic")) { + symbolic = 1; + continue; + } if (!strcmp(arg, "--all")) { for_each_ref(show_reference); continue; } + if (!strcmp(arg, "--show-prefix")) { + puts(prefix); + continue; + } show_arg(arg); continue; } @@ -204,8 +215,8 @@ int main(int argc, char **argv) if (no_revs) continue; def = NULL; - show_rev(NORMAL, end); - show_rev(REVERSED, sha1); + show_rev(NORMAL, end, n); + show_rev(REVERSED, sha1, arg); continue; } } @@ -215,14 +226,14 @@ int main(int argc, char **argv) if (no_revs) continue; def = NULL; - show_rev(NORMAL, sha1); + show_rev(NORMAL, sha1, arg); continue; } if (*arg == '^' && !get_sha1(arg+1, sha1)) { if (no_revs) continue; def = NULL; - show_rev(REVERSED, sha1); + show_rev(REVERSED, sha1, arg+1); continue; } show_default();