Git 2.38
[alt-git.git] / t / helper / test-pack-mtimes.c
blobf7b79daf4c03843c5003100b63666f8dbdbfd1d5
1 #include "git-compat-util.h"
2 #include "test-tool.h"
3 #include "strbuf.h"
4 #include "object-store.h"
5 #include "packfile.h"
6 #include "pack-mtimes.h"
8 static void dump_mtimes(struct packed_git *p)
10 uint32_t i;
11 if (load_pack_mtimes(p) < 0)
12 die("could not load pack .mtimes");
14 for (i = 0; i < p->num_objects; i++) {
15 struct object_id oid;
16 if (nth_packed_object_id(&oid, p, i) < 0)
17 die("could not load object id at position %"PRIu32, i);
19 printf("%s %"PRIu32"\n",
20 oid_to_hex(&oid), nth_packed_mtime(p, i));
24 static const char *pack_mtimes_usage = "\n"
25 " test-tool pack-mtimes <pack-name.mtimes>";
27 int cmd__pack_mtimes(int argc, const char **argv)
29 struct strbuf buf = STRBUF_INIT;
30 struct packed_git *p;
32 setup_git_directory();
34 if (argc != 2)
35 usage(pack_mtimes_usage);
37 for (p = get_all_packs(the_repository); p; p = p->next) {
38 strbuf_addstr(&buf, basename(p->pack_name));
39 strbuf_strip_suffix(&buf, ".pack");
40 strbuf_addstr(&buf, ".mtimes");
42 if (!strcmp(buf.buf, argv[1]))
43 break;
45 strbuf_reset(&buf);
48 strbuf_release(&buf);
50 if (!p)
51 die("could not find pack '%s'", argv[1]);
53 dump_mtimes(p);
55 return 0;