Make sha1_array_append take a struct object_id *
[git/git.git] / t / helper / test-sha1-array.c
CommitLineData
38d905bf
RS
1#include "cache.h"
2#include "sha1-array.h"
3
16ddcd40 4static int print_sha1(const unsigned char sha1[20], void *data)
38d905bf
RS
5{
6 puts(sha1_to_hex(sha1));
16ddcd40 7 return 0;
38d905bf
RS
8}
9
3f2e2297 10int cmd_main(int argc, const char **argv)
38d905bf
RS
11{
12 struct sha1_array array = SHA1_ARRAY_INIT;
13 struct strbuf line = STRBUF_INIT;
14
f06068c9 15 while (strbuf_getline(&line, stdin) != EOF) {
38d905bf 16 const char *arg;
57836f10 17 struct object_id oid;
38d905bf
RS
18
19 if (skip_prefix(line.buf, "append ", &arg)) {
57836f10 20 if (get_oid_hex(arg, &oid))
38d905bf 21 die("not a hexadecimal SHA1: %s", arg);
98a72ddc 22 sha1_array_append(&array, &oid);
38d905bf 23 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
57836f10 24 if (get_oid_hex(arg, &oid))
38d905bf 25 die("not a hexadecimal SHA1: %s", arg);
57836f10 26 printf("%d\n", sha1_array_lookup(&array, oid.hash));
38d905bf
RS
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}