]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-oidtree.c
packfile: delete .idx files before .pack files
[thirdparty/git.git] / t / helper / test-oidtree.c
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "oidtree.h"
4
5 static enum cb_next print_oid(const struct object_id *oid, void *data)
6 {
7 puts(oid_to_hex(oid));
8 return CB_CONTINUE;
9 }
10
11 int cmd__oidtree(int argc, const char **argv)
12 {
13 struct oidtree ot;
14 struct strbuf line = STRBUF_INIT;
15 int nongit_ok;
16 int algo = GIT_HASH_UNKNOWN;
17
18 oidtree_init(&ot);
19 setup_git_directory_gently(&nongit_ok);
20
21 while (strbuf_getline(&line, stdin) != EOF) {
22 const char *arg;
23 struct object_id oid;
24
25 if (skip_prefix(line.buf, "insert ", &arg)) {
26 if (get_oid_hex_any(arg, &oid) == GIT_HASH_UNKNOWN)
27 die("insert not a hexadecimal oid: %s", arg);
28 algo = oid.algo;
29 oidtree_insert(&ot, &oid);
30 } else if (skip_prefix(line.buf, "contains ", &arg)) {
31 if (get_oid_hex(arg, &oid))
32 die("contains not a hexadecimal oid: %s", arg);
33 printf("%d\n", oidtree_contains(&ot, &oid));
34 } else if (skip_prefix(line.buf, "each ", &arg)) {
35 char buf[GIT_MAX_HEXSZ + 1] = { '0' };
36 memset(&oid, 0, sizeof(oid));
37 memcpy(buf, arg, strlen(arg));
38 buf[hash_algos[algo].hexsz] = '\0';
39 get_oid_hex_any(buf, &oid);
40 oid.algo = algo;
41 oidtree_each(&ot, &oid, strlen(arg), print_oid, NULL);
42 } else if (!strcmp(line.buf, "clear")) {
43 oidtree_clear(&ot);
44 } else {
45 die("unknown command: %s", line.buf);
46 }
47 }
48
49 strbuf_release(&line);
50
51 return 0;
52 }