diff options
Diffstat (limited to 'diagnose.c')
-rw-r--r-- | diagnose.c | 53 |
1 files changed, 11 insertions, 42 deletions
diff --git a/diagnose.c b/diagnose.c index 8f26569896..4d096c857f 100644 --- a/diagnose.c +++ b/diagnose.c @@ -1,12 +1,16 @@ -#include "cache.h" +#include "git-compat-util.h" #include "diagnose.h" #include "compat/disk.h" #include "archive.h" #include "dir.h" #include "help.h" +#include "gettext.h" +#include "hex.h" #include "strvec.h" -#include "object-store.h" +#include "object-store-ll.h" #include "packfile.h" +#include "parse-options.h" +#include "write-or-die.h" struct archive_dir { const char *path; @@ -43,7 +47,8 @@ int option_parse_diagnose(const struct option *opt, const char *arg, int unset) return error(_("invalid --%s value '%s'"), opt->long_name, arg); } -static void dir_file_stats_objects(const char *full_path, size_t full_path_len, +static void dir_file_stats_objects(const char *full_path, + size_t full_path_len UNUSED, const char *file_name, void *data) { struct strbuf *buf = data; @@ -66,42 +71,6 @@ static int dir_file_stats(struct object_directory *object_dir, void *data) return 0; } -/* - * Get the d_type of a dirent. If the d_type is unknown, derive it from - * stat.st_mode. - * - * Note that 'path' is assumed to have a trailing slash. It is also modified - * in-place during the execution of the function, but is then reverted to its - * original value before returning. - */ -static unsigned char get_dtype(struct dirent *e, struct strbuf *path) -{ - struct stat st; - unsigned char dtype = DTYPE(e); - size_t base_path_len; - - if (dtype != DT_UNKNOWN) - return dtype; - - /* d_type unknown in dirent, try to fall back on lstat results */ - base_path_len = path->len; - strbuf_addstr(path, e->d_name); - if (lstat(path->buf, &st)) - goto cleanup; - - /* determine d_type from st_mode */ - if (S_ISREG(st.st_mode)) - dtype = DT_REG; - else if (S_ISDIR(st.st_mode)) - dtype = DT_DIR; - else if (S_ISLNK(st.st_mode)) - dtype = DT_LNK; - -cleanup: - strbuf_setlen(path, base_path_len); - return dtype; -} - static int count_files(struct strbuf *path) { DIR *dir = opendir(path->buf); @@ -112,7 +81,7 @@ static int count_files(struct strbuf *path) return 0; while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) - if (get_dtype(e, path) == DT_REG) + if (get_dtype(e, path, 0) == DT_REG) count++; closedir(dir); @@ -141,7 +110,7 @@ static void loose_objs_stats(struct strbuf *buf, const char *path) base_path_len = count_path.len; while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) - if (get_dtype(e, &count_path) == DT_DIR && + if (get_dtype(e, &count_path, 0) == DT_DIR && strlen(e->d_name) == 2 && !hex_to_bytes(&c, e->d_name, 1)) { strbuf_setlen(&count_path, base_path_len); @@ -186,7 +155,7 @@ static int add_directory_to_archiver(struct strvec *archiver_args, strbuf_add_absolute_path(&abspath, at_root ? "." : path); strbuf_addch(&abspath, '/'); - dtype = get_dtype(e, &abspath); + dtype = get_dtype(e, &abspath, 0); strbuf_setlen(&buf, len); strbuf_addstr(&buf, e->d_name); |