diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2008-07-26 18:37:56 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-07-27 14:14:01 -0700 |
commit | 2122f8b963d49a59762e121c2da571c2348dcce3 (patch) | |
tree | 1a147e9da6e34a121fe2187b2cdf47eaa4522cb9 /builtin-rev-parse.c | |
parent | 47c6ef1c8def9a20b4ff40825456b45f5e63b51f (diff) | |
download | git-2122f8b963d49a59762e121c2da571c2348dcce3.tar.gz |
rev-parse: Add support for the ^! and ^@ syntax
Those shorthands are explained in the rev-parse documentation but were not
actually supported by rev-parse itself.
gitk internally uses rev-parse to interpret its command line arguments, and
being able to use these "limit with parents" syntax is handy there.
Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-rev-parse.c')
-rw-r--r-- | builtin-rev-parse.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c index aa71f4a4fa..9aa049ec17 100644 --- a/builtin-rev-parse.c +++ b/builtin-rev-parse.c @@ -241,6 +241,36 @@ static int try_difference(const char *arg) return 0; } +static int try_parent_shorthands(const char *arg) +{ + char *dotdot; + unsigned char sha1[20]; + struct commit *commit; + struct commit_list *parents; + int parents_only; + + if ((dotdot = strstr(arg, "^!"))) + parents_only = 0; + else if ((dotdot = strstr(arg, "^@"))) + parents_only = 1; + + if (!dotdot || dotdot[2]) + return 0; + + *dotdot = 0; + if (get_sha1(arg, sha1)) + return 0; + + if (!parents_only) + show_rev(NORMAL, sha1, arg); + commit = lookup_commit_reference(sha1); + for (parents = commit->parents; parents; parents = parents->next) + show_rev(parents_only ? NORMAL : REVERSED, + parents->item->object.sha1, arg); + + return 1; +} + static int parseopt_dump(const struct option *o, const char *arg, int unset) { struct strbuf *parsed = o->value; @@ -573,6 +603,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) /* Not a flag argument */ if (try_difference(arg)) continue; + if (try_parent_shorthands(arg)) + continue; name = arg; type = NORMAL; if (*arg == '^') { |