scalar diagnose: include disk space information
When analyzing problems with large worktrees/repositories, it is useful to know how close to a "full disk" situation Scalar/Git operates. Let's include this information. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
aa5c79a331
commit
0ed5b13f24
|
@ -302,6 +302,58 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int get_disk_info(struct strbuf *out)
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
char volume_name[MAX_PATH], fs_name[MAX_PATH];
|
||||||
|
DWORD serial_number, component_length, flags;
|
||||||
|
ULARGE_INTEGER avail2caller, total, avail;
|
||||||
|
|
||||||
|
strbuf_realpath(&buf, ".", 1);
|
||||||
|
if (!GetDiskFreeSpaceExA(buf.buf, &avail2caller, &total, &avail)) {
|
||||||
|
error(_("could not determine free disk size for '%s'"),
|
||||||
|
buf.buf);
|
||||||
|
strbuf_release(&buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
strbuf_setlen(&buf, offset_1st_component(buf.buf));
|
||||||
|
if (!GetVolumeInformationA(buf.buf, volume_name, sizeof(volume_name),
|
||||||
|
&serial_number, &component_length, &flags,
|
||||||
|
fs_name, sizeof(fs_name))) {
|
||||||
|
error(_("could not get info for '%s'"), buf.buf);
|
||||||
|
strbuf_release(&buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
strbuf_addf(out, "Available space on '%s': ", buf.buf);
|
||||||
|
strbuf_humanise_bytes(out, avail2caller.QuadPart);
|
||||||
|
strbuf_addch(out, '\n');
|
||||||
|
strbuf_release(&buf);
|
||||||
|
#else
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
struct statvfs stat;
|
||||||
|
|
||||||
|
strbuf_realpath(&buf, ".", 1);
|
||||||
|
if (statvfs(buf.buf, &stat) < 0) {
|
||||||
|
error_errno(_("could not determine free disk size for '%s'"),
|
||||||
|
buf.buf);
|
||||||
|
strbuf_release(&buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
strbuf_addf(out, "Available space on '%s': ", buf.buf);
|
||||||
|
strbuf_humanise_bytes(out, st_mult(stat.f_bsize, stat.f_bavail));
|
||||||
|
strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag);
|
||||||
|
strbuf_release(&buf);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* printf-style interface, expects `<key>=<value>` argument */
|
/* printf-style interface, expects `<key>=<value>` argument */
|
||||||
static int set_config(const char *fmt, ...)
|
static int set_config(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
@ -598,6 +650,7 @@ static int cmd_diagnose(int argc, const char **argv)
|
||||||
get_version_info(&buf, 1);
|
get_version_info(&buf, 1);
|
||||||
|
|
||||||
strbuf_addf(&buf, "Enlistment root: %s\n", the_repository->worktree);
|
strbuf_addf(&buf, "Enlistment root: %s\n", the_repository->worktree);
|
||||||
|
get_disk_info(&buf);
|
||||||
write_or_die(stdout_fd, buf.buf, buf.len);
|
write_or_die(stdout_fd, buf.buf, buf.len);
|
||||||
strvec_pushf(&archiver_args,
|
strvec_pushf(&archiver_args,
|
||||||
"--add-virtual-file=diagnostics.log:%.*s",
|
"--add-virtual-file=diagnostics.log:%.*s",
|
||||||
|
|
|
@ -102,6 +102,7 @@ SQ="'"
|
||||||
test_expect_success UNZIP 'scalar diagnose' '
|
test_expect_success UNZIP 'scalar diagnose' '
|
||||||
scalar clone "file://$(pwd)" cloned --single-branch &&
|
scalar clone "file://$(pwd)" cloned --single-branch &&
|
||||||
scalar diagnose cloned >out 2>err &&
|
scalar diagnose cloned >out 2>err &&
|
||||||
|
grep "Available space" out &&
|
||||||
sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
|
sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
|
||||||
zip_path=$(cat zip_path) &&
|
zip_path=$(cat zip_path) &&
|
||||||
test -n "$zip_path" &&
|
test -n "$zip_path" &&
|
||||||
|
|
Loading…
Reference in New Issue