/* * The branch and tag listings, shown as sections of the summary page and as * the whole of a repository's refs page. Every row is one ref beside * the commit or tag object it points at, ordered newest first, with branches * then reordered by name unless branch-sort asks for age. A section longer * than max-ref-count is cut short and ends in a link to a dedicated heads or * tags page, which walks the same list one offset at a time. */ #define USE_THE_REPOSITORY_VARIABLE #include "cgit.h" #include "filter.h" #include "html.h" #include "shared.h" #include "ui-refs.h" #include "ui-shared.h" // 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. struct ref_page { int size; int start; int end; }; /* * 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 * points at a commit reads past the end of the smaller struct. */ static timestamp_t ref_date(struct refinfo *ref) { if (!ref->object) return 0; switch (ref->object->type) { case OBJ_TAG: return ref->tag ? ref->tag->tagger_date : 0; case OBJ_COMMIT: return ref->commit ? ref->commit->committer_date : 0; } return 0; } static int cmp_date(const void *a, const void *b) { struct refinfo *ref1 = *(struct refinfo **)a; struct refinfo *ref2 = *(struct refinfo **)b; timestamp_t date1 = ref_date(ref1), date2 = ref_date(ref2); // Compared rather than subtracted, at the width the dates are stored // at. A commit may carry any timestamp, so a difference that does not // fit an int would leave qsort with a contradictory ordering. if (date1 < date2) return 1; if (date1 > date2) return -1; return 0; } static int cmp_name(const void *a, const void *b) { struct refinfo *ref1 = *(struct refinfo **)a; struct refinfo *ref2 = *(struct refinfo **)b; return strcmp(ref1->refname, ref2->refname); } 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); if (ctx.repo->enable_remote_branches) refs_for_each_remote_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); } static void print_branch_header(void) { html( "
\n" "