t3700: fix broken test under !POSIXPERM
[git.git] / t / helper / test-sha1-array.c
blobf7a53c4ad64c18903f53c5bd1d4766f54bc22e49
1 #include "cache.h"
2 #include "sha1-array.h"
4 static int print_sha1(const unsigned char sha1[20], void *data)
6 puts(sha1_to_hex(sha1));
7 return 0;
10 int cmd_main(int argc, const char **argv)
12 struct sha1_array array = SHA1_ARRAY_INIT;
13 struct strbuf line = STRBUF_INIT;
15 while (strbuf_getline(&line, stdin) != EOF) {
16 const char *arg;
17 unsigned char sha1[20];
19 if (skip_prefix(line.buf, "append ", &arg)) {
20 if (get_sha1_hex(arg, sha1))
21 die("not a hexadecimal SHA1: %s", arg);
22 sha1_array_append(&array, sha1);
23 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
24 if (get_sha1_hex(arg, sha1))
25 die("not a hexadecimal SHA1: %s", arg);
26 printf("%d\n", sha1_array_lookup(&array, sha1));
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);
34 return 0;