]>
Commit | Line | Data |
---|---|---|
38d905bf RS |
1 | #include "cache.h" |
2 | #include "sha1-array.h" | |
3 | ||
1b7ba794 | 4 | static int print_oid(const struct object_id *oid, void *data) |
38d905bf | 5 | { |
1b7ba794 | 6 | puts(oid_to_hex(oid)); |
16ddcd40 | 7 | return 0; |
38d905bf RS |
8 | } |
9 | ||
3f2e2297 | 10 | int cmd_main(int argc, const char **argv) |
38d905bf | 11 | { |
910650d2 | 12 | struct oid_array array = OID_ARRAY_INIT; |
38d905bf RS |
13 | struct strbuf line = STRBUF_INIT; |
14 | ||
f06068c9 | 15 | while (strbuf_getline(&line, stdin) != EOF) { |
38d905bf | 16 | const char *arg; |
57836f10 | 17 | struct object_id oid; |
38d905bf RS |
18 | |
19 | if (skip_prefix(line.buf, "append ", &arg)) { | |
57836f10 | 20 | if (get_oid_hex(arg, &oid)) |
38d905bf | 21 | die("not a hexadecimal SHA1: %s", arg); |
910650d2 | 22 | oid_array_append(&array, &oid); |
38d905bf | 23 | } else if (skip_prefix(line.buf, "lookup ", &arg)) { |
57836f10 | 24 | if (get_oid_hex(arg, &oid)) |
38d905bf | 25 | die("not a hexadecimal SHA1: %s", arg); |
910650d2 | 26 | printf("%d\n", oid_array_lookup(&array, &oid)); |
38d905bf | 27 | } else if (!strcmp(line.buf, "clear")) |
910650d2 | 28 | oid_array_clear(&array); |
38d905bf | 29 | else if (!strcmp(line.buf, "for_each_unique")) |
910650d2 | 30 | oid_array_for_each_unique(&array, print_oid, NULL); |
38d905bf RS |
31 | else |
32 | die("unknown command: %s", line.buf); | |
33 | } | |
34 | return 0; | |
35 | } |