diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-07-19 01:46:51 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-07-19 02:16:23 +0400 |
commit | adfc1857bdb090786fd9d22c1acec39371c76048 (patch) | |
tree | 2f0fb03ae59fac4c1495ace15b24e1fba14f9944 /builtin/name-rev.c | |
parent | 118aa4acff6afae733c206df7049ea54f7e0b282 (diff) |
describe: fix --contains when a tag is given as input
"git describe" takes a commit and gives it a name based on tags in
its neighbourhood. The command does take a commit-ish but when
given a tag that points at a commit, it should dereference the tag
before computing the name for the commit.
As the whole processing is internally delegated to name-rev, if we
unwrap tags down to the underlying commit when invoking name-rev, it
will make the name-rev issue an error message based on the unwrapped
object name (i.e. either 40-hex object name, or "$tag^0") that is
different from what the end-user gave to the command when the commit
cannot be described. Introduce an internal option --peel-tag to the
name-rev to tell it to unwrap a tag in its input from the command
line.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/name-rev.c')
-rw-r--r-- | builtin/name-rev.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 4c7cc62a9c..0aaa19e4ab 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -307,7 +307,7 @@ static void name_rev_line(char *p, struct name_ref_data *data) int cmd_name_rev(int argc, const char **argv, const char *prefix) { struct object_array revs = OBJECT_ARRAY_INIT; - int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0; + int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0; struct name_ref_data data = { 0, 0, NULL }; struct option opts[] = { OPT_BOOLEAN(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")), @@ -320,6 +320,12 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) OPT_BOOLEAN(0, "undefined", &allow_undefined, N_("allow to print `undefined` names")), OPT_BOOLEAN(0, "always", &always, N_("show abbreviated commit object as fallback")), + { + /* A Hidden OPT_BOOL */ + OPTION_SET_INT, 0, "peel-tag", &peel_tag, NULL, + N_("dereference tags in the input (internal use)"), + PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1, + }, OPT_END(), }; @@ -361,6 +367,15 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) if (cutoff > commit->date) cutoff = commit->date; } + + if (peel_tag) { + if (!commit) { + fprintf(stderr, "Could not get commit for %s. Skipping.\n", + *argv); + continue; + } + object = (struct object *)commit; + } add_object_array(object, *argv, &revs); } |