move got_repo_cmp_tags() to got_ref_cmp_tags()
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
diff --git a/got/got.c b/got/got.c
index 393b9c5..c053c61 100644
--- a/got/got.c
+++ b/got/got.c
@@ -3670,7 +3670,7 @@ list_tags(struct got_repository *repo, struct got_worktree *worktree)
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;
diff --git a/include/got_reference.h b/include/got_reference.h
index 50ff767..da0da7b 100644
--- a/include/got_reference.h
+++ b/include/got_reference.h
@@ -95,6 +95,10 @@ typedef const struct got_error *(*got_ref_cmp_cb)(void *, int *,
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
diff --git a/include/got_repository.h b/include/got_repository.h
index 041be7b..f54c896 100644
--- a/include/got_repository.h
+++ b/include/got_repository.h
@@ -116,7 +116,3 @@ typedef const struct got_error *(*got_repo_import_cb)(void *, const char *);
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 *);
diff --git a/lib/reference.c b/lib/reference.c
index 439627e..398dfd5 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -672,6 +672,70 @@ got_ref_cmp_by_name(void *arg, int *cmp, struct got_reference *re1,
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 *
insert_ref(struct got_reflist_entry **newp, struct got_reflist_head *refs,
struct got_reference *ref, struct got_repository *repo,
diff --git a/lib/repository.c b/lib/repository.c
index bfb1d44..694024d 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -1685,67 +1685,3 @@ got_repo_import(struct got_object_id **new_commit_id, const char *path_dir,
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;
-}