2 #include "sha1-array.h"
4 static int print_oid(const struct object_id *oid, void *data)
10 int cmd_main(int argc, const char **argv)
12 struct oid_array array = OID_ARRAY_INIT;
13 struct strbuf line = STRBUF_INIT;
15 while (strbuf_getline(&line, stdin) != EOF) {
19 if (skip_prefix(line.buf, "append ", &arg)) {
20 if (get_oid_hex(arg, &oid))
21 die("not a hexadecimal SHA1: %s", arg);
22 oid_array_append(&array, &oid);
23 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
24 if (get_oid_hex(arg, &oid))
25 die("not a hexadecimal SHA1: %s", arg);
26 printf("%d\n", oid_array_lookup(&array, &oid));
27 } else if (!strcmp(line.buf, "clear"))
28 oid_array_clear(&array);
29 else if (!strcmp(line.buf, "for_each_unique"))
30 oid_array_for_each_unique(&array, print_oid, NULL);
32 die("unknown command: %s", line.buf);