]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t/helper: add 'pack-mtimes' test-tool
authorTaylor Blau <me@ttaylorr.com>
Fri, 20 May 2022 23:17:46 +0000 (19:17 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 May 2022 22:48:26 +0000 (15:48 -0700)
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 <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
t/helper/test-pack-mtimes.c [new file with mode: 0644]
t/helper/test-tool.c
t/helper/test-tool.h

index e59328ab7d103255d3e9fefeed302d7e3c1afb60..85055de29f2ecf7ae54d9a96c55172f821082324 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -738,6 +738,7 @@ TEST_BUILTINS_OBJS += test-oid-array.o
 TEST_BUILTINS_OBJS += test-oidmap.o
 TEST_BUILTINS_OBJS += test-oidtree.o
 TEST_BUILTINS_OBJS += test-online-cpus.o
+TEST_BUILTINS_OBJS += test-pack-mtimes.o
 TEST_BUILTINS_OBJS += test-parse-options.o
 TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
 TEST_BUILTINS_OBJS += test-partial-clone.o
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
new file mode 100644 (file)
index 0000000..f7b79da
--- /dev/null
@@ -0,0 +1,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;
+}
index 0424f7adf5d69cc2596a58ee3ef33f1826dfc621..d2eacd302d60910f60cc538a17f9854691e299f2 100644 (file)
@@ -48,6 +48,7 @@ static struct test_cmd cmds[] = {
        { "oidmap", cmd__oidmap },
        { "oidtree", cmd__oidtree },
        { "online-cpus", cmd__online_cpus },
+       { "pack-mtimes", cmd__pack_mtimes },
        { "parse-options", cmd__parse_options },
        { "parse-pathspec-file", cmd__parse_pathspec_file },
        { "partial-clone", cmd__partial_clone },
index c876e8246fbdff9ddf43e5b4ec46944406f9d33d..960cc27ef7cfc4d7b73d9fcd672166066a2161d4 100644 (file)
@@ -38,6 +38,7 @@ int cmd__mktemp(int argc, const char **argv);
 int cmd__oidmap(int argc, const char **argv);
 int cmd__oidtree(int argc, const char **argv);
 int cmd__online_cpus(int argc, const char **argv);
+int cmd__pack_mtimes(int argc, const char **argv);
 int cmd__parse_options(int argc, const char **argv);
 int cmd__parse_pathspec_file(int argc, const char** argv);
 int cmd__partial_clone(int argc, const char **argv);