make 'got log' display tags in addition to branch references
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/got/got.c b/got/got.c
index a322f32..4fa6945 100644
--- a/got/got.c
+++ b/got/got.c
@@ -1386,8 +1386,9 @@ print_commit(struct got_commit_object *commit, struct got_object_id *id,
SIMPLEQ_FOREACH(re, refs, entry) {
char *s;
const char *name;
- if (got_object_id_cmp(re->id, id) != 0)
- continue;
+ struct got_tag_object *tag = NULL;
+ int cmp;
+
name = got_ref_get_name(re->ref);
if (strcmp(name, GOT_REF_HEAD) == 0)
continue;
@@ -1399,6 +1400,17 @@ print_commit(struct got_commit_object *commit, struct got_object_id *id,
name += 6;
if (strncmp(name, "remotes/", 8) == 0)
name += 8;
+ if (strncmp(name, "tags/", 5) == 0) {
+ err = got_object_open_as_tag(&tag, repo, re->id);
+ if (err)
+ break;
+ }
+ cmp = got_object_id_cmp(tag ?
+ got_object_tag_get_object_id(tag) : re->id, id);
+ if (tag)
+ got_object_tag_close(tag);
+ if (cmp != 0)
+ continue;
s = refs_str;
if (asprintf(&refs_str, "%s%s%s", s ? s : "", s ? ", " : "",
name) == -1) {
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index fa21749..9b8b3d3 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -124,7 +124,7 @@ function test_log_tag {
(cd $testroot/repo && git tag -a -m "test" $tag)
- echo "commit $commit_id (master)" > $testroot/stdout.expected
+ echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
(cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
> $testroot/stdout)
cmp -s $testroot/stdout.expected $testroot/stdout