commit d1f166363b86f21241be730505c1182508dc9d2c from: Stefan Sperling date: Wed Jan 15 22:05:49 2020 UTC move got_repo_cmp_tags() to got_ref_cmp_tags() commit - 2ddd470150cfe6f1d3d2d51858b13a0dc40ca601 commit + d1f166363b86f21241be730505c1182508dc9d2c blob - 393b9c5538c55d2e402794f0b94bcaed3c610c46 blob + c053c6171169b8e75845855b4a40ffb01a22a020 --- got/got.c +++ got/got.c @@ -3670,7 +3670,7 @@ list_tags(struct got_repository *repo, struct got_work SIMPLEQ_INIT(&refs); - err = got_ref_list(&refs, repo, "refs/tags", got_repo_cmp_tags, repo); + err = got_ref_list(&refs, repo, "refs/tags", got_ref_cmp_tags, repo); if (err) return err; blob - 50ff76771483d382370d47f5134048a4573e6788 blob + da0da7b7bf5a3d15f4fc771d125303ba08d29bbd --- include/got_reference.h +++ include/got_reference.h @@ -95,6 +95,10 @@ typedef const struct got_error *(*got_ref_cmp_cb)(void const struct got_error *got_ref_cmp_by_name(void *, int *, struct got_reference *, struct got_reference *); +/* An implementation of got_ref_cmp_cb which compares two tags. */ +const struct got_error *got_ref_cmp_tags(void *, int *, + struct got_reference *, struct got_reference *); + /* * Append all known references to a caller-provided ref list head. * Optionally limit references returned to those within a given blob - 041be7bcc40567f04948169c105e2b24fa136d55 blob + f54c896e78705e3833a92b32f7a8d1a89d804886 --- include/got_repository.h +++ include/got_repository.h @@ -116,7 +116,3 @@ typedef const struct got_error *(*got_repo_import_cb)( 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 - 439627eae44fd277d180de1edf1539b5e44f6c2c blob + 398dfd52fa18a9ca17559990b511e9b995dceffe --- lib/reference.c +++ lib/reference.c @@ -670,6 +670,70 @@ got_ref_cmp_by_name(void *arg, int *cmp, struct got_re *cmp = got_path_cmp(name1, name2, strlen(name1), strlen(name2)); return NULL; +} + +const struct got_error * +got_ref_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 * blob - bfb1d446d254892dca29c3284c4acdac660306a3 blob + 694024dff777495df250aba392c630bb04e3e65a --- lib/repository.c +++ lib/repository.c @@ -1683,69 +1683,5 @@ got_repo_import(struct got_object_id **new_commit_id, 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; }