From 74f6f11e317f05e45a1950095f0e0e64ec7e6d36 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 21 Feb 2009 02:34:56 +0100 Subject: [PATCH] Add support for sorting branch entries by name, date and author --- tig.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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; -- 2.30.2