|
| 1 | +#include "cache.h" |
| 2 | +#include "sha1-array.h" |
| 3 | + |
| 4 | +static void print_sha1(const unsigned char sha1[20], void *data) |
| 5 | +{ |
| 6 | + puts(sha1_to_hex(sha1)); |
| 7 | +} |
| 8 | + |
| 9 | +int main(int argc, char **argv) |
| 10 | +{ |
| 11 | + struct sha1_array array = SHA1_ARRAY_INIT; |
| 12 | + struct strbuf line = STRBUF_INIT; |
| 13 | + |
| 14 | + while (strbuf_getline(&line, stdin, '\n') != EOF) { |
| 15 | + const char *arg; |
| 16 | + unsigned char sha1[20]; |
| 17 | + |
| 18 | + if (skip_prefix(line.buf, "append ", &arg)) { |
| 19 | + if (get_sha1_hex(arg, sha1)) |
| 20 | + die("not a hexadecimal SHA1: %s", arg); |
| 21 | + sha1_array_append(&array, sha1); |
| 22 | + } else if (skip_prefix(line.buf, "lookup ", &arg)) { |
| 23 | + if (get_sha1_hex(arg, sha1)) |
| 24 | + die("not a hexadecimal SHA1: %s", arg); |
| 25 | + printf("%d\n", sha1_array_lookup(&array, sha1)); |
| 26 | + } else if (!strcmp(line.buf, "clear")) |
| 27 | + sha1_array_clear(&array); |
| 28 | + else if (!strcmp(line.buf, "for_each_unique")) |
| 29 | + sha1_array_for_each_unique(&array, print_sha1, NULL); |
| 30 | + else |
| 31 | + die("unknown command: %s", line.buf); |
| 32 | + } |
| 33 | + return 0; |
| 34 | +} |
0 commit comments