Skip to content

Commit 2bd4427

Browse files
ttaylorrgitster
authored andcommitted
t/helper: add 'pack-mtimes' test-tool
In the next patch, we will implement and test support for writing a cruft pack via a special mode of `git pack-objects`. To make sure that objects are written with the correct timestamps, and a new test-tool that can dump the object names and corresponding timestamps from a given `.mtimes` file. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5dfaf49 commit 2bd4427

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ TEST_BUILTINS_OBJS += test-oid-array.o
738738
TEST_BUILTINS_OBJS += test-oidmap.o
739739
TEST_BUILTINS_OBJS += test-oidtree.o
740740
TEST_BUILTINS_OBJS += test-online-cpus.o
741+
TEST_BUILTINS_OBJS += test-pack-mtimes.o
741742
TEST_BUILTINS_OBJS += test-parse-options.o
742743
TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
743744
TEST_BUILTINS_OBJS += test-partial-clone.o

t/helper/test-pack-mtimes.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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"
7+
8+
static void dump_mtimes(struct packed_git *p)
9+
{
10+
uint32_t i;
11+
if (load_pack_mtimes(p) < 0)
12+
die("could not load pack .mtimes");
13+
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);
18+
19+
printf("%s %"PRIu32"\n",
20+
oid_to_hex(&oid), nth_packed_mtime(p, i));
21+
}
22+
}
23+
24+
static const char *pack_mtimes_usage = "\n"
25+
" test-tool pack-mtimes <pack-name.mtimes>";
26+
27+
int cmd__pack_mtimes(int argc, const char **argv)
28+
{
29+
struct strbuf buf = STRBUF_INIT;
30+
struct packed_git *p;
31+
32+
setup_git_directory();
33+
34+
if (argc != 2)
35+
usage(pack_mtimes_usage);
36+
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");
41+
42+
if (!strcmp(buf.buf, argv[1]))
43+
break;
44+
45+
strbuf_reset(&buf);
46+
}
47+
48+
strbuf_release(&buf);
49+
50+
if (!p)
51+
die("could not find pack '%s'", argv[1]);
52+
53+
dump_mtimes(p);
54+
55+
return 0;
56+
}

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static struct test_cmd cmds[] = {
4848
{ "oidmap", cmd__oidmap },
4949
{ "oidtree", cmd__oidtree },
5050
{ "online-cpus", cmd__online_cpus },
51+
{ "pack-mtimes", cmd__pack_mtimes },
5152
{ "parse-options", cmd__parse_options },
5253
{ "parse-pathspec-file", cmd__parse_pathspec_file },
5354
{ "partial-clone", cmd__partial_clone },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ int cmd__mktemp(int argc, const char **argv);
3838
int cmd__oidmap(int argc, const char **argv);
3939
int cmd__oidtree(int argc, const char **argv);
4040
int cmd__online_cpus(int argc, const char **argv);
41+
int cmd__pack_mtimes(int argc, const char **argv);
4142
int cmd__parse_options(int argc, const char **argv);
4243
int cmd__parse_pathspec_file(int argc, const char** argv);
4344
int cmd__partial_clone(int argc, const char **argv);

0 commit comments

Comments
 (0)