mirror of
https://github.com/git/git.git
synced 2024-05-04 06:36:35 +02:00
fe299ec5ae
We renamed the actual data structure in910650d2f8
(Rename sha1_array to oid_array, 2017-03-31), but the file is still called sha1-array. Besides being slightly confusing, it makes it more annoying to grep for leftover occurrences of "sha1" in various files, because the header is included in so many places. Let's complete the transition by renaming the source and header files (and fixing up a few comment references). I kept the "-" in the name, as that seems to be our style; cf.fc1395f4a4
(sha1_file.c: rename to use dash in file name, 2018-04-10). We also have oidmap.h and oidset.h without any punctuation, but those are "struct oidmap" and "struct oidset" in the code. We _could_ make this "oidarray" to match, but somehow it looks uglier to me because of the length of "array" (plus it would be a very invasive patch for little gain). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
37 lines
964 B
C
37 lines
964 B
C
#include "test-tool.h"
|
|
#include "cache.h"
|
|
#include "oid-array.h"
|
|
|
|
static int print_oid(const struct object_id *oid, void *data)
|
|
{
|
|
puts(oid_to_hex(oid));
|
|
return 0;
|
|
}
|
|
|
|
int cmd__sha1_array(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;
|
|
}
|