1#include "cache.h"
2#include "sha1-array.h"
3
4static int print_oid(const struct object_id *oid, void *data)
5{
6 puts(oid_to_hex(oid));
7 return 0;
8}
9
10int cmd_main(int argc, const char **argv)
11{
12 struct oid_array array = OID_ARRAY_INIT;
13 struct strbuf line = STRBUF_INIT;
14
15 while (strbuf_getline(&line, stdin) != EOF) {
16 const char *arg;
17 struct object_id oid;
18
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);
31 else
32 die("unknown command: %s", line.buf);
33 }
34 return 0;
35}