packed_ref_store: move `packed_refs_path` here
[git.git] / t / helper / test-sha1-array.c
blobedfd52d82aeca0bb9ba2c5b2ce18bc39d27e5a34
1 #include "cache.h"
2 #include "sha1-array.h"
4 static int print_oid(const struct object_id *oid, void *data)
6 puts(oid_to_hex(oid));
7 return 0;
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) {
16 const char *arg;
17 struct object_id oid;
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);
34 return 0;