Merge branch 'jh/memihash-opt'
authorJunio C Hamano <gitster@pobox.com>
Thu, 20 Apr 2017 04:37:25 +0000 (21:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Apr 2017 04:37:25 +0000 (21:37 -0700)
Hotfix for a topic that is already in 'master'.

* jh/memihash-opt:
p0004: make perf test executable
t3008: skip lazy-init test on a single-core box
test-online-cpus: helper to return cpu count
name-hash: fix buffer overrun

Makefile
name-hash.c
t/helper/.gitignore
t/helper/test-online-cpus.c [new file with mode: 0644]
t/perf/p0004-lazy-init-name-hash.sh [changed mode: 0644->0755]
t/t3008-ls-files-lazy-init-name-hash.sh [new file with mode: 0755]
index c6dbeccf5e2aaed990d9f9bb2c95c74f252d346c..eb1a1a7cffd5efc06ada671ca482eb638cd25d61 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -626,6 +626,7 @@ TEST_PROGRAMS_NEED_X += test-line-buffer
 TEST_PROGRAMS_NEED_X += test-match-trees
 TEST_PROGRAMS_NEED_X += test-mergesort
 TEST_PROGRAMS_NEED_X += test-mktemp
+TEST_PROGRAMS_NEED_X += test-online-cpus
 TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-path-utils
 TEST_PROGRAMS_NEED_X += test-prio-queue
index cac313c78d3fa7aba7a7ad6ea6cf5f6fd10a6445..39309efb7f9e21eb7a039b6b17cdb0d9f1859820 100644 (file)
@@ -342,7 +342,9 @@ static int handle_range_dir(
         * Scan forward in the index array for index entries having the same
         * path prefix (that are also in this directory).
         */
-       if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0)
+       if (k_start + 1 >= k_end)
+               k = k_end;
+       else if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0)
                k = k_start + 1;
        else if (strncmp(istate->cache[k_end - 1]->name, prefix->buf, prefix->len) == 0)
                k = k_end;
index d1fa751cf9e0a472ab00cc84435a09e79fd0053c..acd5db180f31f5b81877c75f8a695c3e4437e34d 100644 (file)
@@ -16,6 +16,7 @@
 /test-match-trees
 /test-mergesort
 /test-mktemp
+/test-online-cpus
 /test-parse-options
 /test-path-utils
 /test-prio-queue
diff --git a/t/helper/test-online-cpus.c b/t/helper/test-online-cpus.c
new file mode 100644 (file)
index 0000000..06c09c6
--- /dev/null
@@ -0,0 +1,8 @@
+#include "git-compat-util.h"
+#include "thread-utils.h"
+
+int cmd_main(int argc, const char **argv)
+{
+       printf("%d\n", online_cpus());
+       return 0;
+}
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/t/t3008-ls-files-lazy-init-name-hash.sh b/t/t3008-ls-files-lazy-init-name-hash.sh
new file mode 100755 (executable)
index 0000000..bdf5198
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+test_description='Test the lazy init name hash with various folder structures'
+
+. ./test-lib.sh
+
+if test 1 -eq $($GIT_BUILD_DIR/t/helper/test-online-cpus)
+then
+       skip_all='skipping lazy-init tests, single cpu'
+       test_done
+fi
+
+LAZY_THREAD_COST=2000
+
+test_expect_success 'no buffer overflow in lazy_init_name_hash' '
+       (
+           test_seq $LAZY_THREAD_COST | sed "s/^/a_/"
+           echo b/b/b
+           test_seq $LAZY_THREAD_COST | sed "s/^/c_/"
+           test_seq 50 | sed "s/^/d_/" | tr "\n" "/"; echo d
+       ) |
+       sed "s/^/100644 $EMPTY_BLOB     /" |
+       git update-index --index-info &&
+       test-lazy-init-name-hash -m
+'
+
+test_done