Merge branch 'js/t0007-typofix'
[git] / t / helper / test-oid-array.c
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "oid-array.h"
4
5 static int print_oid(const struct object_id *oid, void *data)
6 {
7         puts(oid_to_hex(oid));
8         return 0;
9 }
10
11 int cmd__oid_array(int argc, const char **argv)
12 {
13         struct oid_array array = OID_ARRAY_INIT;
14         struct strbuf line = STRBUF_INIT;
15
16         while (strbuf_getline(&line, stdin) != EOF) {
17                 const char *arg;
18                 struct object_id oid;
19
20                 if (skip_prefix(line.buf, "append ", &arg)) {
21                         if (get_oid_hex(arg, &oid))
22                                 die("not a hexadecimal oid: %s", arg);
23                         oid_array_append(&array, &oid);
24                 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
25                         if (get_oid_hex(arg, &oid))
26                                 die("not a hexadecimal oid: %s", arg);
27                         printf("%d\n", oid_array_lookup(&array, &oid));
28                 } else if (!strcmp(line.buf, "clear"))
29                         oid_array_clear(&array);
30                 else if (!strcmp(line.buf, "for_each_unique"))
31                         oid_array_for_each_unique(&array, print_oid, NULL);
32                 else
33                         die("unknown command: %s", line.buf);
34         }
35         return 0;
36 }