7 static int print_oid(const struct object_id
*oid
, void *data
)
13 int cmd__oid_array(int argc UNUSED
, const char **argv UNUSED
)
15 struct oid_array array
= OID_ARRAY_INIT
;
16 struct strbuf line
= STRBUF_INIT
;
19 setup_git_directory_gently(&nongit_ok
);
21 while (strbuf_getline(&line
, stdin
) != EOF
) {
25 if (skip_prefix(line
.buf
, "append ", &arg
)) {
26 if (get_oid_hex(arg
, &oid
))
27 die("not a hexadecimal oid: %s", arg
);
28 oid_array_append(&array
, &oid
);
29 } else if (skip_prefix(line
.buf
, "lookup ", &arg
)) {
30 if (get_oid_hex(arg
, &oid
))
31 die("not a hexadecimal oid: %s", arg
);
32 printf("%d\n", oid_array_lookup(&array
, &oid
));
33 } else if (!strcmp(line
.buf
, "clear"))
34 oid_array_clear(&array
);
35 else if (!strcmp(line
.buf
, "for_each_unique"))
36 oid_array_for_each_unique(&array
, print_oid
, NULL
);
38 die("unknown command: %s", line
.buf
);
41 strbuf_release(&line
);
42 oid_array_clear(&array
);