Raw
1 #define USE_THE_REPOSITORY_VARIABLE
2
3 #include "test-tool.h"
4 #include "hex.h"
5 #include "strbuf.h"
6 #include "odb.h"
7 #include "packfile.h"
8 #include "pack-mtimes.h"
9 #include "setup.h"
10
11 static void dump_mtimes(struct packed_git *p)
12 {
13 uint32_t i;
14 if (load_pack_mtimes(p) < 0)
15 die("could not load pack .mtimes");
16
17 for (i = 0; i < p->num_objects; i++) {
18 struct object_id oid;
19 if (nth_packed_object_id(&oid, p, i) < 0)
20 die("could not load object id at position %"PRIu32, i);
21
22 printf("%s %"PRIu32"\n",
23 oid_to_hex(&oid), nth_packed_mtime(p, i));
24 }
25 }
26
27 static const char *const pack_mtimes_usage = "\n"
28 " test-tool pack-mtimes <pack-name.mtimes>";
29
30 int cmd__pack_mtimes(int argc, const char **argv)
31 {
32 struct strbuf buf = STRBUF_INIT;
33 struct packed_git *p;
34
35 setup_git_directory(the_repository);
36
37 if (argc != 2)
38 usage(pack_mtimes_usage);
39
40 repo_for_each_pack(the_repository, p) {
41 strbuf_addstr(&buf, basename(p->pack_name));
42 strbuf_strip_suffix(&buf, ".pack");
43 strbuf_addstr(&buf, ".mtimes");
44
45 if (!strcmp(buf.buf, argv[1]))
46 break;
47
48 strbuf_reset(&buf);
49 }
50
51 strbuf_release(&buf);
52
53 if (!p)
54 die("could not find pack '%s'", argv[1]);
55
56 dump_mtimes(p);
57
58 return 0;
59 }