summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2017-05-22 16:17:47 +0200
committerJunio C Hamano <gitster@pobox.com>2017-05-23 14:29:55 +0900
commit8556f8d61330ec677dc48b0ef39e2017d6927708 (patch)
tree76b96a436fdfb04475ea7f2bbada2dc468fa4dee /refs.c
parenta552e50e5a82b9219c6b2911320931417a36af32 (diff)
downloadgit-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>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/refs.c b/refs.c
index 143936a9c3..d1c781d94e 100644
--- a/refs.c
+++ b/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;
}