Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictoria Dye <vdye@github.com>2022-08-12 23:10:12 +0300
committerJunio C Hamano <gitster@pobox.com>2022-08-12 23:20:02 +0300
commit435a2535b72aa0e3a2e152841fe79c5b65a6e8c0 (patch)
tree7acc88bfd6e015d30cb68cd68e12b17a96039558
parentba307a50467aa0bc588f24a95a786014b42e3054 (diff)
scalar-diagnose: move 'get_disk_info()' to 'compat/'
Move 'get_disk_info()' function into 'compat/'. Although Scalar-specific code is generally not part of the main Git tree, 'get_disk_info()' will be used in subsequent patches by additional callers beyond 'scalar diagnose'. This patch prepares for that change, at which point this platform-specific code should be part of 'compat/' as a matter of convention. The function is copied *mostly* verbatim, with two exceptions: * '#ifdef WIN32' is replaced with '#ifdef GIT_WINDOWS_NATIVE' to allow 'statvfs' to be used with Cygwin. * the 'struct strbuf buf' and 'int res' (as well as their corresponding cleanup & return) are moved outside of the '#ifdef' block. Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--compat/disk.h56
-rw-r--r--contrib/scalar/scalar.c53
-rw-r--r--git-compat-util.h1
3 files changed, 58 insertions, 52 deletions
diff --git a/compat/disk.h b/compat/disk.h
new file mode 100644
index 0000000000..50a32e3d8a
--- /dev/null
+++ b/compat/disk.h
@@ -0,0 +1,56 @@
+#ifndef COMPAT_DISK_H
+#define COMPAT_DISK_H
+
+#include "git-compat-util.h"
+
+static int get_disk_info(struct strbuf *out)
+{
+ struct strbuf buf = STRBUF_INIT;
+ int res = 0;
+
+#ifdef GIT_WINDOWS_NATIVE
+ 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);
+ res = -1;
+ goto cleanup;
+ }
+
+ 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);
+ res = -1;
+ goto cleanup;
+ }
+ strbuf_addf(out, "Available space on '%s': ", buf.buf);
+ strbuf_humanise_bytes(out, avail2caller.QuadPart);
+ strbuf_addch(out, '\n');
+#else
+ 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);
+ res = -1;
+ goto cleanup;
+ }
+
+ strbuf_addf(out, "Available space on '%s': ", buf.buf);
+ strbuf_humanise_bytes(out, (off_t)stat.f_bsize * (off_t)stat.f_bavail);
+ strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag);
+#endif
+
+cleanup:
+ strbuf_release(&buf);
+ return res;
+}
+
+#endif /* COMPAT_DISK_H */
diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c
index b9092f0b61..607fedefd8 100644
--- a/contrib/scalar/scalar.c
+++ b/contrib/scalar/scalar.c
@@ -13,6 +13,7 @@
#include "help.h"
#include "archive.h"
#include "object-store.h"
+#include "compat/disk.h"
/*
* Remove the deepest subdirectory in the provided path string. Path must not
@@ -309,58 +310,6 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
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, (off_t)stat.f_bsize * (off_t)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 */
static int set_config(const char *fmt, ...)
{
diff --git a/git-compat-util.h b/git-compat-util.h
index 58d7708296..9a62e3a0d2 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -258,6 +258,7 @@ static inline int is_xplatform_dir_sep(int c)
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <sys/statvfs.h>
#include <termios.h>
#ifndef NO_SYS_SELECT_H
#include <sys/select.h>