Make sha1_array_append take a struct object_id *
[git] / t / helper / test-sha1-array.c
1 #include "cache.h"
2 #include "sha1-array.h"
3
4 static int print_sha1(const unsigned char sha1[20], void *data)
5 {
6         puts(sha1_to_hex(sha1));
7         return 0;
8 }
9
10 int cmd_main(int argc, const char **argv)
11 {
12         struct sha1_array array = SHA1_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                         sha1_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", sha1_array_lookup(&array, oid.hash));
27                 } else if (!strcmp(line.buf, "clear"))
28                         sha1_array_clear(&array);
29                 else if (!strcmp(line.buf, "for_each_unique"))
30                         sha1_array_for_each_unique(&array, print_sha1, NULL);
31                 else
32                         die("unknown command: %s", line.buf);
33         }
34         return 0;
35 }