With this on top of the other patches in this series, you would get:
$ git describe --contains $(git rev-parse v1.8.3 v1.8.3^0)
v1.8.3
v1.8.3
while you can still differentiate tags and the commits they point at
with:
$ git name-rev --refs=tags/\* --name-only $(git rev-parse v1.8.3 v1.8.3^0)
v1.8.3
v1.8.3^0
The difference in these two behaviours is achieved by adding --peel-to-commit
option to "name-rev" and using it when "describe" internally calls it.
Signed-off-by: Junio C Hamano <[email protected]>
---
builtin/describe.c | 1 +
builtin/name-rev.c | 35 +++++++++++++++++++++++++----------
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/builtin/describe.c b/builtin/describe.c
index b5434e4..f7adda6 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -447,6 +447,7 @@ int cmd_describe(int argc, const char **argv, const char
*prefix)
argv_array_init(&args);
argv_array_push(&args, "name-rev");
+ argv_array_push(&args, "--peel-to-commit");
argv_array_push(&args, "--name-only");
argv_array_push(&args, "--no-undefined");
if (always)
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 29a6f56..fa37731 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -15,6 +15,7 @@ typedef struct rev_name {
} rev_name;
static long cutoff = LONG_MAX;
+static int peel_to_commit;
/* How many generations are maximally preferred over _one_ merge traversal? */
#define MERGE_TRAVERSAL_WEIGHT 65535
@@ -33,7 +34,7 @@ static void name_rev(struct commit *commit,
if (commit->date < cutoff)
return;
- if (deref) {
+ if (deref && !peel_to_commit) {
char *new_name = xmalloc(strlen(tip_name)+3);
strcpy(new_name, tip_name);
strcat(new_name, "^0");
@@ -320,6 +321,8 @@ 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")),
+ OPT_BOOLEAN(0, "peel-to-commit", &peel_to_commit,
+ N_("peel tag object names in the input to a
commmit")),
OPT_END(),
};
@@ -334,7 +337,7 @@ int cmd_name_rev(int argc, const char **argv, const char
*prefix)
for (; argc; argc--, argv++) {
unsigned char sha1[20];
- struct object *o;
+ struct object *object;
struct commit *commit;
if (get_sha1(*argv, sha1)) {
@@ -343,17 +346,29 @@ int cmd_name_rev(int argc, const char **argv, const char
*prefix)
continue;
}
- o = deref_tag(parse_object(sha1), *argv, 0);
- if (!o || o->type != OBJ_COMMIT) {
+ commit = NULL;
+ object = parse_object(sha1);
+ if (object) {
+ struct object *peeled = deref_tag(object, *argv, 0);
+ if (peeled && peeled->type == OBJ_COMMIT)
+ commit = (struct commit *) peeled;
+ }
+
+ if (!object) {
+ fprintf(stderr, "Could not get object for %s.
Skipping.\n",
+ *argv);
+ continue;
+ }
+ if (peel_to_commit && !commit) {
fprintf(stderr, "Could not get commit for %s.
Skipping.\n",
- *argv);
+ *argv);
continue;
}
-
- commit = (struct commit *)o;
- if (cutoff > commit->date)
- cutoff = commit->date;
- add_object_array((struct object *)commit, *argv, &revs);
+ if (commit) {
+ if (cutoff > commit->date)
+ cutoff = commit->date;
+ }
+ add_object_array(object, *argv, &revs);
}
if (cutoff)
--
1.8.3.2-853-ga8cbcc9
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html