]>
Commit | Line | Data |
---|---|---|
92d8ed8a | 1 | #include "test-tool.h" |
41771fa4 | 2 | #include "hex.h" |
92d8ed8a | 3 | #include "oidtree.h" |
e38da487 | 4 | #include "setup.h" |
69a63fe6 | 5 | #include "strbuf.h" |
92d8ed8a | 6 | |
126e3b3d | 7 | static enum cb_next print_oid(const struct object_id *oid, void *data UNUSED) |
92d8ed8a EW |
8 | { |
9 | puts(oid_to_hex(oid)); | |
10 | return CB_CONTINUE; | |
11 | } | |
12 | ||
126e3b3d | 13 | int cmd__oidtree(int argc UNUSED, const char **argv UNUSED) |
92d8ed8a EW |
14 | { |
15 | struct oidtree ot; | |
16 | struct strbuf line = STRBUF_INIT; | |
17 | int nongit_ok; | |
18 | int algo = GIT_HASH_UNKNOWN; | |
19 | ||
20 | oidtree_init(&ot); | |
21 | setup_git_directory_gently(&nongit_ok); | |
22 | ||
23 | while (strbuf_getline(&line, stdin) != EOF) { | |
24 | const char *arg; | |
25 | struct object_id oid; | |
26 | ||
27 | if (skip_prefix(line.buf, "insert ", &arg)) { | |
28 | if (get_oid_hex_any(arg, &oid) == GIT_HASH_UNKNOWN) | |
29 | die("insert not a hexadecimal oid: %s", arg); | |
30 | algo = oid.algo; | |
31 | oidtree_insert(&ot, &oid); | |
32 | } else if (skip_prefix(line.buf, "contains ", &arg)) { | |
33 | if (get_oid_hex(arg, &oid)) | |
34 | die("contains not a hexadecimal oid: %s", arg); | |
35 | printf("%d\n", oidtree_contains(&ot, &oid)); | |
36 | } else if (skip_prefix(line.buf, "each ", &arg)) { | |
37 | char buf[GIT_MAX_HEXSZ + 1] = { '0' }; | |
38 | memset(&oid, 0, sizeof(oid)); | |
39 | memcpy(buf, arg, strlen(arg)); | |
40 | buf[hash_algos[algo].hexsz] = '\0'; | |
41 | get_oid_hex_any(buf, &oid); | |
42 | oid.algo = algo; | |
43 | oidtree_each(&ot, &oid, strlen(arg), print_oid, NULL); | |
44 | } else if (!strcmp(line.buf, "clear")) { | |
45 | oidtree_clear(&ot); | |
46 | } else { | |
47 | die("unknown command: %s", line.buf); | |
48 | } | |
49 | } | |
926d2330 ÆAB |
50 | |
51 | strbuf_release(&line); | |
52 | ||
92d8ed8a EW |
53 | return 0; |
54 | } |