]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/helper/test-path-utils.c
ci: parallelize testing on Windows
[thirdparty/git.git] / t / helper / test-path-utils.c
index 6efde6f5ba5b7203a73335c51114c2d47156231d..5d543ad21f89c76534e8efe32d6ead512dc7d0c3 100644 (file)
@@ -177,6 +177,14 @@ static int is_dotgitmodules(const char *path)
        return is_hfs_dotgitmodules(path) || is_ntfs_dotgitmodules(path);
 }
 
+static int cmp_by_st_size(const void *a, const void *b)
+{
+       intptr_t x = (intptr_t)((struct string_list_item *)a)->util;
+       intptr_t y = (intptr_t)((struct string_list_item *)b)->util;
+
+       return x > y ? -1 : (x < y ? +1 : 0);
+}
+
 int cmd__path_utils(int argc, const char **argv)
 {
        if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
@@ -324,6 +332,29 @@ int cmd__path_utils(int argc, const char **argv)
                return 0;
        }
 
+       if (argc > 5 && !strcmp(argv[1], "slice-tests")) {
+               int res = 0;
+               long offset, stride, i;
+               struct string_list list = STRING_LIST_INIT_NODUP;
+               struct stat st;
+
+               offset = strtol(argv[2], NULL, 10);
+               stride = strtol(argv[3], NULL, 10);
+               if (stride < 1)
+                       stride = 1;
+               for (i = 4; i < argc; i++)
+                       if (stat(argv[i], &st))
+                               res = error_errno("Cannot stat '%s'", argv[i]);
+                       else
+                               string_list_append(&list, argv[i])->util =
+                                       (void *)(intptr_t)st.st_size;
+               QSORT(list.items, list.nr, cmp_by_st_size);
+               for (i = offset; i < list.nr; i+= stride)
+                       printf("%s\n", list.items[i].string);
+
+               return !!res;
+       }
+
        fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
                argv[1] ? argv[1] : "(there was none)");
        return 1;