]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-oid-array.c
Merge branch 'bc/sha-256-part-2'
[thirdparty/git.git] / t / helper / test-oid-array.c
CommitLineData
aa218dff 1#include "test-tool.h"
38d905bf 2#include "cache.h"
fe299ec5 3#include "oid-array.h"
38d905bf 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
ed4b804e 11int cmd__oid_array(int argc, const char **argv)
38d905bf 12{
910650d2 13 struct oid_array array = OID_ARRAY_INIT;
38d905bf 14 struct strbuf line = STRBUF_INIT;
54cbbe4c 15 int nongit_ok;
16
17 setup_git_directory_gently(&nongit_ok);
38d905bf 18
f06068c9 19 while (strbuf_getline(&line, stdin) != EOF) {
38d905bf 20 const char *arg;
57836f10 21 struct object_id oid;
38d905bf
RS
22
23 if (skip_prefix(line.buf, "append ", &arg)) {
57836f10 24 if (get_oid_hex(arg, &oid))
ed4b804e 25 die("not a hexadecimal oid: %s", arg);
910650d2 26 oid_array_append(&array, &oid);
38d905bf 27 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
57836f10 28 if (get_oid_hex(arg, &oid))
ed4b804e 29 die("not a hexadecimal oid: %s", arg);
910650d2 30 printf("%d\n", oid_array_lookup(&array, &oid));
38d905bf 31 } else if (!strcmp(line.buf, "clear"))
910650d2 32 oid_array_clear(&array);
38d905bf 33 else if (!strcmp(line.buf, "for_each_unique"))
910650d2 34 oid_array_for_each_unique(&array, print_oid, NULL);
38d905bf
RS
35 else
36 die("unknown command: %s", line.buf);
37 }
38 return 0;
39}