Merge branch 'ob/messages-capitalize-exception'
[alt-git.git] / t / helper / test-oid-array.c
blobeef68833b7fb0607eebf336e1ee9627aed7390d8
1 #include "test-tool.h"
2 #include "hex.h"
3 #include "oid-array.h"
4 #include "setup.h"
5 #include "strbuf.h"
7 static int print_oid(const struct object_id *oid, void *data)
9 puts(oid_to_hex(oid));
10 return 0;
13 int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
15 struct oid_array array = OID_ARRAY_INIT;
16 struct strbuf line = STRBUF_INIT;
17 int nongit_ok;
19 setup_git_directory_gently(&nongit_ok);
21 while (strbuf_getline(&line, stdin) != EOF) {
22 const char *arg;
23 struct object_id oid;
25 if (skip_prefix(line.buf, "append ", &arg)) {
26 if (get_oid_hex(arg, &oid))
27 die("not a hexadecimal oid: %s", arg);
28 oid_array_append(&array, &oid);
29 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
30 if (get_oid_hex(arg, &oid))
31 die("not a hexadecimal oid: %s", arg);
32 printf("%d\n", oid_array_lookup(&array, &oid));
33 } else if (!strcmp(line.buf, "clear"))
34 oid_array_clear(&array);
35 else if (!strcmp(line.buf, "for_each_unique"))
36 oid_array_for_each_unique(&array, print_oid, NULL);
37 else
38 die("unknown command: %s", line.buf);
41 strbuf_release(&line);
42 oid_array_clear(&array);
44 return 0;