From: Jonas Fonseca Date: Sat, 21 Feb 2009 01:34:56 +0000 (+0100) Subject: Add support for sorting branch entries by name, date and author X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=74f6f11e317f05e45a1950095f0e0e64ec7e6d36;p=tig.git Add support for sorting branch entries by name, date and author --- diff --git a/tig.c b/tig.c index a4eae7d..998c926 100644 --- a/tig.c +++ b/tig.c @@ -4721,6 +4721,30 @@ struct branch { struct ref *ref; /* Name and commit ID information. */ }; +static const enum sort_field branch_sort_fields[] = { + ORDERBY_NAME, ORDERBY_DATE, ORDERBY_AUTHOR +}; +static struct sort_state branch_sort_state = SORT_STATE(branch_sort_fields); + +static int +branch_compare(const void *l1, const void *l2) +{ + const struct branch *branch1 = ((const struct line *) l1)->data; + const struct branch *branch2 = ((const struct line *) l2)->data; + + switch (get_sort_field(branch_sort_state)) { + case ORDERBY_DATE: + return sort_order(branch_sort_state, branch1->time - branch2->time); + + case ORDERBY_AUTHOR: + return sort_order(branch_sort_state, strcmp(branch1->author, branch2->author)); + + case ORDERBY_NAME: + default: + return sort_order(branch_sort_state, strcmp(branch1->ref->name, branch2->ref->name)); + } +} + static bool branch_draw(struct view *view, struct line *line, unsigned int lineno) { @@ -4746,6 +4770,11 @@ branch_request(struct view *view, enum request request, struct line *line) open_view(view, REQ_VIEW_BRANCH, OPEN_REFRESH); return REQ_NONE; + case REQ_TOGGLE_SORT_FIELD: + case REQ_TOGGLE_SORT_ORDER: + sort_view(view, request, &branch_sort_state, branch_compare); + return REQ_NONE; + case REQ_ENTER: open_view(view, REQ_VIEW_MAIN, OPEN_SPLIT); return REQ_NONE;