scalar: teach `diagnose` to gather packfile info
It's helpful to see if there are other crud files in the pack directory. Let's teach the `scalar diagnose` command to gather file size information about pack files. While at it, also enumerate the pack files in the alternate object directories, if any are registered. Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthew John Cheetham committed
May 28, 2022 at 16:11 UTC
93e804b2785e1f030737e31e7e18ddc997a368c7
2 files changed
+35
-1
contrib/scalar/scalar.c
+30
@@ -12,6 +12,7 @@
12
#include "packfile.h"
13
#include "help.h"
14
#include "archive.h"
15
+#include "object-store.h"
16
17
/*
18
* Remove the deepest subdirectory in the provided path string. Path must not
@@ -594,6 +595,29 @@ cleanup:
595
return res;
596
}
597
598
+static void dir_file_stats_objects(const char *full_path, size_t full_path_len,
599
+ const char *file_name, void *data)
600
+{
601
+ struct strbuf *buf = data;
602
+ struct stat st;
603
+
604
+ if (!stat(full_path, &st))
605
+ strbuf_addf(buf, "%-70s %16" PRIuMAX "\n", file_name,
606
+ (uintmax_t)st.st_size);
607
+}
608
+
609
+static int dir_file_stats(struct object_directory *object_dir, void *data)
610
+{
611
+ struct strbuf *buf = data;
612
+
613
+ strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
614
+
615
+ for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
616
+ data);
617
+
618
+ return 0;
619
+}
620
+
621
static int cmd_diagnose(int argc, const char **argv)
622
{
623
struct option options[] = {
@@ -656,6 +680,12 @@ static int cmd_diagnose(int argc, const char **argv)
680
"--add-virtual-file=diagnostics.log:%.*s",
681
(int)buf.len, buf.buf);
682
683
+ strbuf_reset(&buf);
684
+ strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
685
+ dir_file_stats(the_repository->objects->odb, &buf);
686
+ foreach_alt_odb(dir_file_stats, &buf);
687
+ strvec_push(&archiver_args, buf.buf);
688
+
689
if ((res = add_directory_to_archiver(&archiver_args, ".git", 0)) ||
690
(res = add_directory_to_archiver(&archiver_args, ".git/hooks", 0)) ||
691
(res = add_directory_to_archiver(&archiver_args, ".git/info", 0)) ||
contrib/scalar/t/t9099-scalar.sh
+5
-1
@@ -101,6 +101,8 @@ test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
101
SQ="'"
102
test_expect_success UNZIP 'scalar diagnose' '
103
scalar clone "file://$(pwd)" cloned --single-branch &&
104
+ git repack &&
105
+ echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
106
scalar diagnose cloned >out 2>err &&
107
grep "Available space" out &&
108
sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
@@ -110,7 +112,9 @@ test_expect_success UNZIP 'scalar diagnose' '
112
folder=${zip_path%.zip} &&
113
test_path_is_missing "$folder" &&
114
unzip -p "$zip_path" diagnostics.log >out &&
113
- test_file_not_empty out
115
+ test_file_not_empty out &&
116
+ unzip -p "$zip_path" packs-local.txt >out &&
117
+ grep "$(pwd)/.git/objects" out
118
'
119
120
test_done