2 #include "sha1-array.h"
4 static int print_sha1(const unsigned char sha1
[20], void *data
)
6 puts(sha1_to_hex(sha1
));
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
) {
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
);
32 die("unknown command: %s", line
.buf
);