add tagged object IDs to reference list object ID map Fixes display of "/tags/..." commit ID decorators in tog which was broken in previous commits.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
diff --git a/lib/reference.c b/lib/reference.c
index 9634212..2a0a381 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -1408,6 +1408,34 @@ struct got_reflist_object_id_map_entry {
struct got_reflist_head refs;
};
+static const struct got_error *
+add_object_id_map_entry(struct got_object_idset *idset,
+ struct got_object_id *id, struct got_reflist_entry *re)
+{
+ const struct got_error *err = NULL;
+ struct got_reflist_object_id_map_entry *ent;
+ struct got_reflist_entry *new;
+
+ ent = got_object_idset_get(idset, id);
+ if (ent == NULL) {
+ ent = malloc(sizeof(*ent));
+ if (ent == NULL)
+ return got_error_from_errno("malloc");
+
+ TAILQ_INIT(&ent->refs);
+ err = got_object_idset_add(idset, id, ent);
+ if (err)
+ return err;
+ }
+
+ err = got_reflist_entry_dup(&new, re);
+ if (err)
+ return err;
+
+ TAILQ_INSERT_TAIL(&ent->refs, new, entry);
+ return NULL;
+}
+
const struct got_error *
got_reflist_object_id_map_create(struct got_reflist_object_id_map **map,
struct got_reflist_head *refs, struct got_repository *repo)
@@ -1429,30 +1457,39 @@ got_reflist_object_id_map_create(struct got_reflist_object_id_map **map,
(*map)->idset = idset;
TAILQ_FOREACH(re, refs, entry) {
- struct got_reflist_entry *new;
- struct got_reflist_object_id_map_entry *ent;
+ struct got_tag_object *tag = NULL;
err = got_ref_resolve(&id, repo, re->ref);
if (err)
goto done;
- ent = got_object_idset_get(idset, id);
- if (ent == NULL) {
- ent = malloc(sizeof(*ent));
- if (ent == NULL) {
- err = got_error_from_errno("malloc");
- goto done;
- }
- TAILQ_INIT(&ent->refs);
- err = got_object_idset_add(idset, id, ent);
- if (err)
+ err = add_object_id_map_entry(idset, id, re);
+ if (err)
+ goto done;
+
+ if (strstr(got_ref_get_name(re->ref), "/tags/") == NULL) {
+ free(id);
+ id = NULL;
+ continue;
+ }
+
+ err = got_object_open_as_tag(&tag, repo, id);
+ if (err) {
+ if (err->code != GOT_ERR_OBJ_TYPE)
goto done;
+ /* Ref points at something other than a tag. */
+ err = NULL;
+ tag = NULL;
+ free(id);
+ id = NULL;
+ continue;
}
- err = got_reflist_entry_dup(&new, re);
+ err = add_object_id_map_entry(idset,
+ got_object_tag_get_object_id(tag), re);
if (err)
goto done;
- TAILQ_INSERT_TAIL(&ent->refs, new, entry);
+
free(id);
id = NULL;
}