summaryrefslogtreecommitdiffstats
path: root/t/helper/test-pack-mtimes.c
blob: f7b79daf4c03843c5003100b63666f8dbdbfd1d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "git-compat-util.h"
#include "test-tool.h"
#include "strbuf.h"
#include "object-store.h"
#include "packfile.h"
#include "pack-mtimes.h"

static void dump_mtimes(struct packed_git *p)
{
	uint32_t i;
	if (load_pack_mtimes(p) < 0)
		die("could not load pack .mtimes");

	for (i = 0; i < p->num_objects; i++) {
		struct object_id oid;
		if (nth_packed_object_id(&oid, p, i) < 0)
			die("could not load object id at position %"PRIu32, i);

		printf("%s %"PRIu32"\n",
		       oid_to_hex(&oid), nth_packed_mtime(p, i));
	}
}

static const char *pack_mtimes_usage = "\n"
"  test-tool pack-mtimes <pack-name.mtimes>";

int cmd__pack_mtimes(int argc, const char **argv)
{
	struct strbuf buf = STRBUF_INIT;
	struct packed_git *p;

	setup_git_directory();

	if (argc != 2)
		usage(pack_mtimes_usage);

	for (p = get_all_packs(the_repository); p; p = p->next) {
		strbuf_addstr(&buf, basename(p->pack_name));
		strbuf_strip_suffix(&buf, ".pack");
		strbuf_addstr(&buf, ".mtimes");

		if (!strcmp(buf.buf, argv[1]))
			break;

		strbuf_reset(&buf);
	}

	strbuf_release(&buf);

	if (!p)
		die("could not find pack '%s'", argv[1]);

	dump_mtimes(p);

	return 0;
}