]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-oid-array.c
Merge branch 'jk/mailinfo-oob-read-fix'
[thirdparty/git.git] / t / helper / test-oid-array.c
1 #include "test-tool.h"
2 #include "hex.h"
3 #include "oid-array.h"
4 #include "setup.h"
5 #include "strbuf.h"
6
7 static int print_oid(const struct object_id *oid, void *data UNUSED)
8 {
9 puts(oid_to_hex(oid));
10 return 0;
11 }
12
13 int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
14 {
15 struct oid_array array = OID_ARRAY_INIT;
16 struct strbuf line = STRBUF_INIT;
17 int nongit_ok;
18
19 setup_git_directory_gently(&nongit_ok);
20
21 while (strbuf_getline(&line, stdin) != EOF) {
22 const char *arg;
23 struct object_id oid;
24
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);
39 }
40
41 strbuf_release(&line);
42 oid_array_clear(&array);
43
44 return 0;
45 }