commit 48cae60d0ae734495d85aa8a8d9409e71cfe7d76 from: Stefan Sperling date: Tue Sep 22 00:03:02 2020 UTC make dangling symbolic references show up in 'got ref -l' Storing a resolved ID for each reference list item was a bad idea. This ID cannot be resolved if a symbolic references points to a reference which does not exist. Such symrefs were skipped by got ref -l as a result. Just let users of reference lists resolve the IDs as needed. commit - 2a104ff6e79d3ac7369f542553c609d2b15f1a55 commit + 48cae60d0ae734495d85aa8a8d9409e71cfe7d76 blob - e8c441e13d1229c15786b463059253b440bad107 blob + 2abb63153d40d88e1af8f211eb545027c1061b0a --- got/got.c +++ got/got.c @@ -3202,6 +3202,7 @@ print_commit(struct got_commit_object *commit, struct char *s; const char *name; struct got_tag_object *tag = NULL; + struct got_object_id *ref_id; int cmp; name = got_ref_get_name(re->ref); @@ -3219,18 +3220,24 @@ print_commit(struct got_commit_object *commit, struct if (s != NULL && s[strlen(s)] == '\0') continue; } + err = got_ref_resolve(&ref_id, repo, re->ref); + if (err) + return err; if (strncmp(name, "tags/", 5) == 0) { - err = got_object_open_as_tag(&tag, repo, re->id); + err = got_object_open_as_tag(&tag, repo, ref_id); if (err) { - if (err->code != GOT_ERR_OBJ_TYPE) + if (err->code != GOT_ERR_OBJ_TYPE) { + free(ref_id); return err; + } /* Ref points at something other than a tag. */ err = NULL; tag = NULL; } } cmp = got_object_id_cmp(tag ? - got_object_tag_get_object_id(tag) : re->id, id); + got_object_tag_get_object_id(tag) : ref_id, id); + free(ref_id); if (tag) got_object_tag_close(tag); if (cmp != 0) blob - 5286f89210b64f38fc36e7dde5d75328f4e4834f blob + 5f2594f5af806ea9b99c358f35fa4e7ce16f7efb --- include/got_reference.h +++ include/got_reference.h @@ -75,11 +75,10 @@ const struct got_error *got_ref_resolve(struct got_obj */ char *got_ref_to_str(struct got_reference *); -/* A list of references and the object ID which they resolve to. */ +/* List of references. */ struct got_reflist_entry { SIMPLEQ_ENTRY(got_reflist_entry) entry; struct got_reference *ref; - struct got_object_id *id; }; SIMPLEQ_HEAD(got_reflist_head, got_reflist_entry); blob - 1e9c2329c7868b58ee5e319672ef807b8c84c77e blob + 0106f4d117b8902efa3b6b09159dc97bf18a70d6 --- lib/reference.c +++ lib/reference.c @@ -561,15 +561,7 @@ got_reflist_entry_dup(struct got_reflist_entry **newp, new->ref = got_ref_dup(re->ref); if (new->ref == NULL) { - err = got_error_from_errno("got_ref_dup"); - free(new); - return err; - } - - new->id = got_object_id_dup(re->id); - if (new->id == NULL) { err = got_error_from_errno("got_ref_dup"); - free(new->id); free(new); return err; } @@ -752,23 +744,15 @@ insert_ref(struct got_reflist_entry **newp, struct got got_ref_cmp_cb cmp_cb, void *cmp_arg) { const struct got_error *err; - struct got_object_id *id; struct got_reflist_entry *new, *re, *prev = NULL; int cmp; *newp = NULL; - - err = got_ref_resolve(&id, repo, ref); - if (err) - return err; new = malloc(sizeof(*new)); - if (new == NULL) { - free(id); + if (new == NULL) return got_error_from_errno("malloc"); - } new->ref = ref; - new->id = id; *newp = new; /* @@ -784,7 +768,6 @@ insert_ref(struct got_reflist_entry **newp, struct got return err; if (cmp == 0) { /* duplicate */ - free(new->id); free(new); *newp = NULL; return NULL; @@ -1031,7 +1014,6 @@ got_ref_list_free(struct got_reflist_head *refs) re = SIMPLEQ_FIRST(refs); SIMPLEQ_REMOVE_HEAD(refs, entry); got_ref_close(re->ref); - free(re->id); free(re); } blob - 5a2b0f63e102cbd3386aaf8e158af7b55f76e5f9 blob + e3bb018f3eacad94323e5fb2868f589bcc778b52 --- regress/cmdline/ref.sh +++ regress/cmdline/ref.sh @@ -266,7 +266,8 @@ test_ref_delete() { got ref -r $testroot/repo -d master got ref -l -r $testroot/repo > $testroot/stdout - echo "refs/heads/ref1: $commit_id" > $testroot/stdout.expected + echo "HEAD: refs/heads/master" > $testroot/stdout.expected + echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected cmp -s $testroot/stdout $testroot/stdout.expected ret="$?" blob - d46c6ecd59b56ea667bc10d635dff590823e90d5 blob + c85b72cb7d79be804da3d376cc54c65fee5d8dfd --- tog/tog.c +++ tog/tog.c @@ -1163,6 +1163,7 @@ build_refs_str(char **refs_str, struct got_reflist_hea SIMPLEQ_FOREACH(re, refs, entry) { struct got_tag_object *tag = NULL; + struct got_object_id *ref_id; int cmp; name = got_ref_get_name(re->ref); @@ -1180,18 +1181,24 @@ build_refs_str(char **refs_str, struct got_reflist_hea if (s != NULL && s[strlen(s)] == '\0') continue; } + err = got_ref_resolve(&ref_id, repo, re->ref); + if (err) + break; if (strncmp(name, "tags/", 5) == 0) { - err = got_object_open_as_tag(&tag, repo, re->id); + err = got_object_open_as_tag(&tag, repo, ref_id); if (err) { - if (err->code != GOT_ERR_OBJ_TYPE) + if (err->code != GOT_ERR_OBJ_TYPE) { + free(ref_id); break; + } /* Ref points at something other than a tag. */ err = NULL; tag = NULL; } } cmp = got_object_id_cmp(tag ? - got_object_tag_get_object_id(tag) : re->id, id); + got_object_tag_get_object_id(tag) : ref_id, id); + free(ref_id); if (tag) got_object_tag_close(tag); if (cmp != 0)