mirror of
https://github.com/git/git.git
synced 2024-12-04 07:24:41 +08:00
910650d2f8
Since this structure handles an array of object IDs, rename it to struct oid_array. Also rename the accessor functions and the initialization constant. This commit was produced mechanically by providing non-Documentation files to the following Perl one-liners: perl -pi -E 's/struct sha1_array/struct oid_array/g' perl -pi -E 's/\bsha1_array_/oid_array_/g' perl -pi -E 's/SHA1_ARRAY_INIT/OID_ARRAY_INIT/g' Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
36 lines
935 B
C
36 lines
935 B
C
#include "cache.h"
|
|
#include "sha1-array.h"
|
|
|
|
static int print_oid(const struct object_id *oid, void *data)
|
|
{
|
|
puts(oid_to_hex(oid));
|
|
return 0;
|
|
}
|
|
|
|
int cmd_main(int argc, const char **argv)
|
|
{
|
|
struct oid_array array = OID_ARRAY_INIT;
|
|
struct strbuf line = STRBUF_INIT;
|
|
|
|
while (strbuf_getline(&line, stdin) != EOF) {
|
|
const char *arg;
|
|
struct object_id oid;
|
|
|
|
if (skip_prefix(line.buf, "append ", &arg)) {
|
|
if (get_oid_hex(arg, &oid))
|
|
die("not a hexadecimal SHA1: %s", arg);
|
|
oid_array_append(&array, &oid);
|
|
} else if (skip_prefix(line.buf, "lookup ", &arg)) {
|
|
if (get_oid_hex(arg, &oid))
|
|
die("not a hexadecimal SHA1: %s", arg);
|
|
printf("%d\n", oid_array_lookup(&array, &oid));
|
|
} else if (!strcmp(line.buf, "clear"))
|
|
oid_array_clear(&array);
|
|
else if (!strcmp(line.buf, "for_each_unique"))
|
|
oid_array_for_each_unique(&array, print_oid, NULL);
|
|
else
|
|
die("unknown command: %s", line.buf);
|
|
}
|
|
return 0;
|
|
}
|