commit - 71a276322e39e17baf5697b5daac8e8fe6ad2ae1
commit + 2ddd470150cfe6f1d3d2d51858b13a0dc40ca601
blob - 8557a12f9a89263a136978089113a713c63984a7
blob + 393b9c5538c55d2e402794f0b94bcaed3c610c46
--- got/got.c
+++ got/got.c
return err;
}
#endif
-
-static const struct got_error *
-cmp_tags(void *arg, int *cmp, struct got_reference *ref1,
- struct got_reference *ref2)
-{
- const struct got_error *err = NULL;
- struct got_repository *repo = arg;
- struct got_object_id *id1, *id2 = NULL;
- struct got_tag_object *tag1 = NULL, *tag2 = NULL;
- struct got_commit_object *commit1 = NULL, *commit2 = NULL;
- time_t time1, time2;
-
- *cmp = 0;
-
- err = got_ref_resolve(&id1, repo, ref1);
- if (err)
- return err;
- err = got_object_open_as_tag(&tag1, repo, id1);
- if (err) {
- if (err->code != GOT_ERR_OBJ_TYPE)
- goto done;
- /* "lightweight" tag */
- err = got_object_open_as_commit(&commit1, repo, id1);
- if (err)
- goto done;
- time1 = got_object_commit_get_committer_time(commit1);
- } else
- time1 = got_object_tag_get_tagger_time(tag1);
-
- err = got_ref_resolve(&id2, repo, ref2);
- if (err)
- goto done;
- err = got_object_open_as_tag(&tag2, repo, id2);
- if (err) {
- if (err->code != GOT_ERR_OBJ_TYPE)
- goto done;
- /* "lightweight" tag */
- err = got_object_open_as_commit(&commit2, repo, id2);
- if (err)
- goto done;
- time2 = got_object_commit_get_committer_time(commit2);
- } else
- time2 = got_object_tag_get_tagger_time(tag2);
-
- /* Put latest tags first. */
- if (time1 < time2)
- *cmp = 1;
- else if (time1 > time2)
- *cmp = -1;
- else
- err = got_ref_cmp_by_name(NULL, cmp, ref2, ref1);
-done:
- free(id1);
- free(id2);
- if (tag1)
- got_object_tag_close(tag1);
- if (tag2)
- got_object_tag_close(tag2);
- if (commit1)
- got_object_commit_close(commit1);
- if (commit2)
- got_object_commit_close(commit2);
- return err;
-}
static const struct got_error *
list_tags(struct got_repository *repo, struct got_worktree *worktree)
SIMPLEQ_INIT(&refs);
- err = got_ref_list(&refs, repo, "refs/tags", cmp_tags, repo);
+ err = got_ref_list(&refs, repo, "refs/tags", got_repo_cmp_tags, repo);
if (err)
return err;
blob - f54c896e78705e3833a92b32f7a8d1a89d804886
blob + 041be7bcc40567f04948169c105e2b24fa136d55
--- include/got_repository.h
+++ include/got_repository.h
const struct got_error *got_repo_import(struct got_object_id **, const char *,
const char *, const char *, struct got_pathlist_head *,
struct got_repository *, got_repo_import_cb, void *);
+
+/* Attempt to compare two reference tags */
+const struct got_error *got_repo_cmp_tags(void *, int *,
+ struct got_reference *, struct got_reference *);
blob - 694024dff777495df250aba392c630bb04e3e65a
blob + bfb1d446d254892dca29c3284c4acdac660306a3
--- lib/repository.c
+++ lib/repository.c
err = got_object_commit_create(new_commit_id, new_tree_id, NULL, 0,
author, time(NULL), author, time(NULL), logmsg, repo);
free(new_tree_id);
+ return err;
+}
+
+const struct got_error *
+got_repo_cmp_tags(void *arg, int *cmp, struct got_reference *ref1,
+ struct got_reference *ref2)
+{
+ const struct got_error *err = NULL;
+ struct got_repository *repo = arg;
+ struct got_object_id *id1, *id2 = NULL;
+ struct got_tag_object *tag1 = NULL, *tag2 = NULL;
+ struct got_commit_object *commit1 = NULL, *commit2 = NULL;
+ time_t time1, time2;
+
+ *cmp = 0;
+
+ err = got_ref_resolve(&id1, repo, ref1);
+ if (err)
+ return err;
+ err = got_object_open_as_tag(&tag1, repo, id1);
+ if (err) {
+ if (err->code != GOT_ERR_OBJ_TYPE)
+ goto done;
+ /* "lightweight" tag */
+ err = got_object_open_as_commit(&commit1, repo, id1);
+ if (err)
+ goto done;
+ time1 = got_object_commit_get_committer_time(commit1);
+ } else
+ time1 = got_object_tag_get_tagger_time(tag1);
+
+ err = got_ref_resolve(&id2, repo, ref2);
+ if (err)
+ goto done;
+ err = got_object_open_as_tag(&tag2, repo, id2);
+ if (err) {
+ if (err->code != GOT_ERR_OBJ_TYPE)
+ goto done;
+ /* "lightweight" tag */
+ err = got_object_open_as_commit(&commit2, repo, id2);
+ if (err)
+ goto done;
+ time2 = got_object_commit_get_committer_time(commit2);
+ } else
+ time2 = got_object_tag_get_tagger_time(tag2);
+
+ /* Put latest tags first. */
+ if (time1 < time2)
+ *cmp = 1;
+ else if (time1 > time2)
+ *cmp = -1;
+ else
+ err = got_ref_cmp_by_name(NULL, cmp, ref2, ref1);
+done:
+ free(id1);
+ free(id2);
+ if (tag1)
+ got_object_tag_close(tag1);
+ if (tag2)
+ got_object_tag_close(tag2);
+ if (commit1)
+ got_object_commit_close(commit1);
+ if (commit2)
+ got_object_commit_close(commit2);
return err;
}