]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-sha1-array.c
Merge branch 'js/rebase-cleanup'
[thirdparty/git.git] / t / helper / test-sha1-array.c
CommitLineData
aa218dff 1#include "test-tool.h"
38d905bf
RS
2#include "cache.h"
3#include "sha1-array.h"
4
1b7ba794 5static int print_oid(const struct object_id *oid, void *data)
38d905bf 6{
1b7ba794 7 puts(oid_to_hex(oid));
16ddcd40 8 return 0;
38d905bf
RS
9}
10
aa218dff 11int cmd__sha1_array(int argc, const char **argv)
38d905bf 12{
910650d2 13 struct oid_array array = OID_ARRAY_INIT;
38d905bf
RS
14 struct strbuf line = STRBUF_INIT;
15
f06068c9 16 while (strbuf_getline(&line, stdin) != EOF) {
38d905bf 17 const char *arg;
57836f10 18 struct object_id oid;
38d905bf
RS
19
20 if (skip_prefix(line.buf, "append ", &arg)) {
57836f10 21 if (get_oid_hex(arg, &oid))
38d905bf 22 die("not a hexadecimal SHA1: %s", arg);
910650d2 23 oid_array_append(&array, &oid);
38d905bf 24 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
57836f10 25 if (get_oid_hex(arg, &oid))
38d905bf 26 die("not a hexadecimal SHA1: %s", arg);
910650d2 27 printf("%d\n", oid_array_lookup(&array, &oid));
38d905bf 28 } else if (!strcmp(line.buf, "clear"))
910650d2 29 oid_array_clear(&array);
38d905bf 30 else if (!strcmp(line.buf, "for_each_unique"))
910650d2 31 oid_array_for_each_unique(&array, print_oid, NULL);
38d905bf
RS
32 else
33 die("unknown command: %s", line.buf);
34 }
35 return 0;
36}