Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Move the ref list code into ui-refs.c
Diffstat (limited to 'source')
| -rw-r--r-- | source/cgit.h | 15 | |
| -rw-r--r-- | source/shared.c | 58 | |
| -rw-r--r-- | source/shared.h | 8 | |
| -rw-r--r-- | source/ui-refs.c | 92 |
4 files changed, 85 insertions, 88 deletions
diff --git a/source/cgit.h b/source/cgit.h index 00258fd..ff6af4a 100644 --- a/source/cgit.h +++ b/source/cgit.h @@ -145,21 +145,6 @@ struct taginfo { char *msg; }; -struct refinfo { - const char *refname; - struct object *object; - union { - struct taginfo *tag; - struct commitinfo *commit; - }; -}; - -struct reflist { - struct refinfo **refs; - int alloc; - int count; -}; - struct cgit_query { int has_oid; int has_difftype; diff --git a/source/shared.c b/source/shared.c index c881fac..c3867f6 100644 --- a/source/shared.c +++ b/source/shared.c @@ -20,43 +20,6 @@ struct cgit_repolist cgit_repolist; struct cgit_context ctx; char cgit_default_repo_desc[] = "[no description]"; -static void free_refinfo(struct refinfo *ref) -{ - free((char *)ref->refname); - switch (ref->object->type) { - case OBJ_TAG: - cgit_free_taginfo(ref->tag); - break; - case OBJ_COMMIT: - cgit_free_commitinfo(ref->commit); - break; - } - free(ref); -} - -static struct refinfo *make_refinfo(const char *refname, const struct object_id *oid) -{ - struct refinfo *ref; - - ref = xcalloc(1, sizeof(struct refinfo)); - ref->refname = xstrdup(refname); - ref->object = parse_object(the_repository, oid); - if (!ref->object) { - free((char *)ref->refname); - free(ref); - return NULL; - } - switch (ref->object->type) { - case OBJ_TAG: - ref->tag = cgit_parse_tag((struct tag *)ref->object); - break; - case OBJ_COMMIT: - ref->commit = cgit_parse_commit((struct commit *)ref->object); - break; - } - return ref; -} - /* * Git's wider syntax is refused, since :/pattern and rev^{/pattern} walk the * whole history for a match, and a leading dash reads as an option further @@ -267,27 +230,6 @@ void cgit_free_taginfo(struct taginfo *info) free(info); } -void cgit_free_reflist_inner(struct reflist *list) -{ - int i; - - for (i = 0; i < list->count; i++) - free_refinfo(list->refs[i]); - free(list->refs); -} - -int cgit_refs_cb(const struct reference *ref, void *cb_data) -{ - struct reflist *list = (struct reflist *)cb_data; - struct refinfo *info = make_refinfo(ref->name, ref->oid); - - if (info) { - ALLOC_GROW(list->refs, list->count + 1, list->alloc); - list->refs[list->count++] = info; - } - return 0; -} - void cgit_diff_tree_cb(struct diff_queue_struct *q, struct diff_options *options UNUSED, void *data) { filepair_fn fn = *(filepair_fn *)data; diff --git a/source/shared.h b/source/shared.h index 2397f67..590198a 100644 --- a/source/shared.h +++ b/source/shared.h @@ -29,14 +29,6 @@ extern struct cgit_repo *cgit_get_repoinfo(const char *url); */ extern void cgit_prepare_repo_env(struct cgit_repo *repo); -extern void cgit_free_reflist_inner(struct reflist *list); - -/* - * Matches git's reference iteration callback, and appends each ref it is given - * to the struct reflist passed as cb_data. - */ -extern int cgit_refs_cb(const struct reference *ref, void *cb_data); - extern void cgit_free_commitinfo(struct commitinfo *info); extern void cgit_free_taginfo(struct taginfo *info); diff --git a/source/ui-refs.c b/source/ui-refs.c index 4099225..a99ba65 100644 --- a/source/ui-refs.c +++ b/source/ui-refs.c @@ -12,10 +12,26 @@ #include "cgit.h" #include "filter.h" #include "html.h" +#include "parsing.h" #include "shared.h" #include "ui-refs.h" #include "ui-shared.h" +struct refinfo { + const char *refname; + struct object *object; + union { + struct taginfo *tag; + struct commitinfo *commit; + }; +}; + +struct reflist { + struct refinfo **refs; + int alloc; + int count; +}; + // The slice of a sorted ref list that one page shows, with end one past the // last row. size is what a full page holds, so it also decides whether the // list needs a pager. @@ -25,6 +41,68 @@ struct ref_page { int end; }; +static void free_refinfo(struct refinfo *ref) +{ + free((char *)ref->refname); + switch (ref->object->type) { + case OBJ_TAG: + cgit_free_taginfo(ref->tag); + break; + case OBJ_COMMIT: + cgit_free_commitinfo(ref->commit); + break; + } + free(ref); +} + +static struct refinfo *make_refinfo(const char *refname, const struct object_id *oid) +{ + struct refinfo *ref; + + ref = xcalloc(1, sizeof(struct refinfo)); + ref->refname = xstrdup(refname); + ref->object = parse_object(the_repository, oid); + if (!ref->object) { + free((char *)ref->refname); + free(ref); + return NULL; + } + switch (ref->object->type) { + case OBJ_TAG: + ref->tag = cgit_parse_tag((struct tag *)ref->object); + break; + case OBJ_COMMIT: + ref->commit = cgit_parse_commit((struct commit *)ref->object); + break; + } + return ref; +} + +static void free_reflist_inner(struct reflist *list) +{ + int i; + + for (i = 0; i < list->count; i++) + free_refinfo(list->refs[i]); + free(list->refs); +} + +/* + * Matches git's reference iteration callback, and appends each ref it is given + * to the struct reflist passed as cb_data. + */ +static int refs_cb(const struct reference *ref, void *cb_data) +{ + struct reflist *list = (struct reflist *)cb_data; + struct refinfo *info = make_refinfo(ref->name, ref->oid); + + if (info) { + ALLOC_GROW(list->refs, list->count + 1, list->alloc); + list->refs[list->count++] = info; + } + return 0; +} + /* * The tagger date and the committer date live in a union in struct refinfo and * only the member matching the object type is ever filled, so assuming a ref @@ -69,9 +147,9 @@ static void collect_branches(struct reflist *list) { list->refs = NULL; list->alloc = list->count = 0; - refs_for_each_branch_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); + refs_for_each_branch_ref(get_main_ref_store(the_repository), refs_cb, list); if (ctx.repo->enable_remote_branches) - refs_for_each_remote_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); + refs_for_each_remote_ref(get_main_ref_store(the_repository), refs_cb, list); } /* @@ -132,7 +210,7 @@ static void collect_tags(struct reflist *list) { list->refs = NULL; list->alloc = list->count = 0; - refs_for_each_tag_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); + refs_for_each_tag_ref(get_main_ref_store(the_repository), refs_cb, list); } static void print_tag_header(int columns) @@ -266,7 +344,7 @@ static void print_branches_page(int pagesize) print_ref_pager(page.start, page.size, list.count, "heads"); html("</tbody>\n"); - cgit_free_reflist_inner(&list); + free_reflist_inner(&list); } static void print_tags_page(int pagesize) @@ -290,7 +368,7 @@ static void print_tags_page(int pagesize) print_ref_pager(page.start, page.size, list.count, "tags"); html("</tbody>\n"); - cgit_free_reflist_inner(&list); + free_reflist_inner(&list); } void cgit_print_branches(int maxcount, int columns) @@ -318,7 +396,7 @@ void cgit_print_branches(int maxcount, int columns) print_refs_link("heads", columns); html("</tbody>\n"); - cgit_free_reflist_inner(&list); + free_reflist_inner(&list); } void cgit_print_tags(int maxcount, int columns) @@ -340,7 +418,7 @@ void cgit_print_tags(int maxcount, int columns) print_refs_link("tags", columns); html("</tbody>\n"); - cgit_free_reflist_inner(&list); + free_reflist_inner(&list); } void cgit_print_refs(void) |
