2018-03-24 08:44:57 +01:00
|
|
|
#include "test-tool.h"
|
2014-10-01 17:00:33 +02:00
|
|
|
#include "cache.h"
|
|
|
|
#include "sha1-array.h"
|
|
|
|
|
2017-03-31 03:39:59 +02:00
|
|
|
static int print_oid(const struct object_id *oid, void *data)
|
2014-10-01 17:00:33 +02:00
|
|
|
{
|
2017-03-31 03:39:59 +02:00
|
|
|
puts(oid_to_hex(oid));
|
2016-09-26 14:00:29 +02:00
|
|
|
return 0;
|
2014-10-01 17:00:33 +02:00
|
|
|
}
|
|
|
|
|
2018-03-24 08:44:57 +01:00
|
|
|
int cmd__sha1_array(int argc, const char **argv)
|
2014-10-01 17:00:33 +02:00
|
|
|
{
|
2017-03-31 03:40:00 +02:00
|
|
|
struct oid_array array = OID_ARRAY_INIT;
|
2014-10-01 17:00:33 +02:00
|
|
|
struct strbuf line = STRBUF_INIT;
|
|
|
|
|
2015-10-28 21:32:10 +01:00
|
|
|
while (strbuf_getline(&line, stdin) != EOF) {
|
2014-10-01 17:00:33 +02:00
|
|
|
const char *arg;
|
2017-03-26 18:01:32 +02:00
|
|
|
struct object_id oid;
|
2014-10-01 17:00:33 +02:00
|
|
|
|
|
|
|
if (skip_prefix(line.buf, "append ", &arg)) {
|
2017-03-26 18:01:32 +02:00
|
|
|
if (get_oid_hex(arg, &oid))
|
2014-10-01 17:00:33 +02:00
|
|
|
die("not a hexadecimal SHA1: %s", arg);
|
2017-03-31 03:40:00 +02:00
|
|
|
oid_array_append(&array, &oid);
|
2014-10-01 17:00:33 +02:00
|
|
|
} else if (skip_prefix(line.buf, "lookup ", &arg)) {
|
2017-03-26 18:01:32 +02:00
|
|
|
if (get_oid_hex(arg, &oid))
|
2014-10-01 17:00:33 +02:00
|
|
|
die("not a hexadecimal SHA1: %s", arg);
|
2017-03-31 03:40:00 +02:00
|
|
|
printf("%d\n", oid_array_lookup(&array, &oid));
|
2014-10-01 17:00:33 +02:00
|
|
|
} else if (!strcmp(line.buf, "clear"))
|
2017-03-31 03:40:00 +02:00
|
|
|
oid_array_clear(&array);
|
2014-10-01 17:00:33 +02:00
|
|
|
else if (!strcmp(line.buf, "for_each_unique"))
|
2017-03-31 03:40:00 +02:00
|
|
|
oid_array_for_each_unique(&array, print_oid, NULL);
|
2014-10-01 17:00:33 +02:00
|
|
|
else
|
|
|
|
die("unknown command: %s", line.buf);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|