diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2022-07-14 17:43:49 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-14 20:24:11 +0200 |
commit | df534dcbaafa74be9e922418712bede75676588b (patch) | |
tree | e73dbdc8fcd9d8eeb94f56da5fb30caa792cff0a /builtin/shortlog.c | |
parent | Git 2.37.1 (diff) | |
download | git-df534dcbaafa74be9e922418712bede75676588b.tar.xz git-df534dcbaafa74be9e922418712bede75676588b.zip |
shortlog: use a stable sort
When sorting the output of `git shortlog` by count, a list of authors in
alphabetical order is then sorted by contribution count. Obviously, the
idea is to maintain the alphabetical order for items with identical
contribution count.
At the moment, this job is performed by `qsort()`. As that function is
not guaranteed to implement a stable sort algorithm, this can lead to
inconsistent and/or surprising behavior: items with identical
contribution count could lose their alphabetical sub-order.
The `qsort()` in MS Visual C's runtime does _not_ implement a stable
sort algorithm, and under certain circumstances this even causes a test
failure in t4201.21 "shortlog can match multiple groups", where two
authors both are listed with 2 contributions, and are listed in inverse
alphabetical order.
Let's instead use the stable sort provided by `git_stable_qsort()` to
avoid this inconsistency.
This is a companion to 2049b8dc65 (diffcore_rename(): use a stable sort,
2019-09-30).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rw-r--r-- | builtin/shortlog.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 35825f075e..086dfee45a 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -443,7 +443,7 @@ void shortlog_output(struct shortlog *log) struct strbuf sb = STRBUF_INIT; if (log->sort_by_number) - QSORT(log->list.items, log->list.nr, + STABLE_QSORT(log->list.items, log->list.nr, log->summary ? compare_by_counter : compare_by_list); for (i = 0; i < log->list.nr; i++) { const struct string_list_item *item = &log->list.items[i]; |