Interested in helping open source friends on HP-UX?
[git/mjg.git] / test-sha1-array.c
blobddc491eff9ca52c4aeeced77c901e5907d215f16
1 #include "cache.h"
2 #include "sha1-array.h"
4 static void print_sha1(const unsigned char sha1[20], void *data)
6 puts(sha1_to_hex(sha1));
9 int main(int argc, char **argv)
11 struct sha1_array array = SHA1_ARRAY_INIT;
12 struct strbuf line = STRBUF_INIT;
14 while (strbuf_getline(&line, stdin, '\n') != EOF) {
15 const char *arg;
16 unsigned char sha1[20];
18 if (skip_prefix(line.buf, "append ", &arg)) {
19 if (get_sha1_hex(arg, sha1))
20 die("not a hexadecimal SHA1: %s", arg);
21 sha1_array_append(&array, sha1);
22 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
23 if (get_sha1_hex(arg, sha1))
24 die("not a hexadecimal SHA1: %s", arg);
25 printf("%d\n", sha1_array_lookup(&array, sha1));
26 } else if (!strcmp(line.buf, "clear"))
27 sha1_array_clear(&array);
28 else if (!strcmp(line.buf, "for_each_unique"))
29 sha1_array_for_each_unique(&array, print_sha1, NULL);
30 else
31 die("unknown command: %s", line.buf);
33 return 0;