ref_update_reject_duplicates(): add a sanity check

It's pretty cheap to make sure that the caller didn't pass us an
unsorted list by accident, so do so.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty 2017-05-22 16:17:47 +02:00 коммит произвёл Junio C Hamano
Родитель a552e50e5a
Коммит 8556f8d613
1 изменённых файлов: 8 добавлений и 2 удалений

10
refs.c
Просмотреть файл

@ -1709,13 +1709,19 @@ int ref_update_reject_duplicates(struct string_list *refnames,
assert(err);
for (i = 1; i < n; i++)
if (!strcmp(refnames->items[i - 1].string, refnames->items[i].string)) {
for (i = 1; i < n; i++) {
int cmp = strcmp(refnames->items[i - 1].string,
refnames->items[i].string);
if (!cmp) {
strbuf_addf(err,
"multiple updates for ref '%s' not allowed.",
refnames->items[i].string);
return 1;
} else if (cmp > 0) {
die("BUG: ref_update_reject_duplicates() received unsorted list");
}
}
return 0;
}