Skip to content

Commit 93e804b

Browse files
mjcheethamgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ed5b13 commit 93e804b

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

contrib/scalar/scalar.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "packfile.h"
1313
#include "help.h"
1414
#include "archive.h"
15+
#include "object-store.h"
1516

1617
/*
1718
* Remove the deepest subdirectory in the provided path string. Path must not
@@ -594,6 +595,29 @@ static int cmd_clone(int argc, const char **argv)
594595
return res;
595596
}
596597

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+
597621
static int cmd_diagnose(int argc, const char **argv)
598622
{
599623
struct option options[] = {
@@ -656,6 +680,12 @@ static int cmd_diagnose(int argc, const char **argv)
656680
"--add-virtual-file=diagnostics.log:%.*s",
657681
(int)buf.len, buf.buf);
658682

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+
659689
if ((res = add_directory_to_archiver(&archiver_args, ".git", 0)) ||
660690
(res = add_directory_to_archiver(&archiver_args, ".git/hooks", 0)) ||
661691
(res = add_directory_to_archiver(&archiver_args, ".git/info", 0)) ||

contrib/scalar/t/t9099-scalar.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
101101
SQ="'"
102102
test_expect_success UNZIP 'scalar diagnose' '
103103
scalar clone "file://$(pwd)" cloned --single-branch &&
104+
git repack &&
105+
echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
104106
scalar diagnose cloned >out 2>err &&
105107
grep "Available space" out &&
106108
sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
@@ -110,7 +112,9 @@ test_expect_success UNZIP 'scalar diagnose' '
110112
folder=${zip_path%.zip} &&
111113
test_path_is_missing "$folder" &&
112114
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
114118
'
115119

116120
test_done

0 commit comments

Comments
 (0)