]>
Commit | Line | Data |
---|---|---|
aa218dff | 1 | #include "test-tool.h" |
41771fa4 | 2 | #include "hex.h" |
fe299ec5 | 3 | #include "oid-array.h" |
e38da487 | 4 | #include "setup.h" |
69a63fe6 | 5 | #include "strbuf.h" |
38d905bf | 6 | |
1e9cb348 | 7 | static int print_oid(const struct object_id *oid, void *data UNUSED) |
38d905bf | 8 | { |
1b7ba794 | 9 | puts(oid_to_hex(oid)); |
16ddcd40 | 10 | return 0; |
38d905bf RS |
11 | } |
12 | ||
126e3b3d | 13 | int cmd__oid_array(int argc UNUSED, const char **argv UNUSED) |
38d905bf | 14 | { |
910650d2 | 15 | struct oid_array array = OID_ARRAY_INIT; |
38d905bf | 16 | struct strbuf line = STRBUF_INIT; |
54cbbe4c | 17 | int nongit_ok; |
18 | ||
19 | setup_git_directory_gently(&nongit_ok); | |
38d905bf | 20 | |
f06068c9 | 21 | while (strbuf_getline(&line, stdin) != EOF) { |
38d905bf | 22 | const char *arg; |
57836f10 | 23 | struct object_id oid; |
38d905bf RS |
24 | |
25 | if (skip_prefix(line.buf, "append ", &arg)) { | |
57836f10 | 26 | if (get_oid_hex(arg, &oid)) |
ed4b804e | 27 | die("not a hexadecimal oid: %s", arg); |
910650d2 | 28 | oid_array_append(&array, &oid); |
38d905bf | 29 | } else if (skip_prefix(line.buf, "lookup ", &arg)) { |
57836f10 | 30 | if (get_oid_hex(arg, &oid)) |
ed4b804e | 31 | die("not a hexadecimal oid: %s", arg); |
910650d2 | 32 | printf("%d\n", oid_array_lookup(&array, &oid)); |
38d905bf | 33 | } else if (!strcmp(line.buf, "clear")) |
910650d2 | 34 | oid_array_clear(&array); |
38d905bf | 35 | else if (!strcmp(line.buf, "for_each_unique")) |
910650d2 | 36 | oid_array_for_each_unique(&array, print_oid, NULL); |
38d905bf RS |
37 | else |
38 | die("unknown command: %s", line.buf); | |
39 | } | |
6ad66ab4 ÆAB |
40 | |
41 | strbuf_release(&line); | |
42 | oid_array_clear(&array); | |
43 | ||
38d905bf RS |
44 | return 0; |
45 | } |