diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2017-05-22 16:17:47 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-23 14:29:55 +0900 |
commit | 8556f8d61330ec677dc48b0ef39e2017d6927708 (patch) | |
tree | 76b96a436fdfb04475ea7f2bbada2dc468fa4dee | |
parent | a552e50e5a82b9219c6b2911320931417a36af32 (diff) | |
download | git-8556f8d61330ec677dc48b0ef39e2017d6927708.tar.gz |
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>
-rw-r--r-- | refs.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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; } |