mirror of
https://github.com/git/git.git
synced 2026-06-30 19:58:12 +00:00
odb/source-loose: wire up count_objects() callback
Move `odb_source_loose_count_objects()` and its associated helpers from "object-file.c" into "odb/source-loose.c" and wire it up as the `count_objects()` callback of the loose source. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
8a6da81cc1
commit
2ade08ac29
@@ -1602,66 +1602,6 @@ int for_each_loose_file_in_source(struct odb_source *source,
|
||||
return r;
|
||||
}
|
||||
|
||||
static int count_loose_object(const struct object_id *oid UNUSED,
|
||||
struct object_info *oi UNUSED,
|
||||
void *payload)
|
||||
{
|
||||
unsigned long *count = payload;
|
||||
(*count)++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int odb_source_loose_count_objects(struct odb_source *source,
|
||||
enum odb_count_objects_flags flags,
|
||||
unsigned long *out)
|
||||
{
|
||||
struct odb_source_files *files = odb_source_files_downcast(source);
|
||||
const unsigned hexsz = source->odb->repo->hash_algo->hexsz - 2;
|
||||
char *path = NULL;
|
||||
DIR *dir = NULL;
|
||||
int ret;
|
||||
|
||||
if (flags & ODB_COUNT_OBJECTS_APPROXIMATE) {
|
||||
unsigned long count = 0;
|
||||
struct dirent *ent;
|
||||
|
||||
path = xstrfmt("%s/17", source->path);
|
||||
|
||||
dir = opendir(path);
|
||||
if (!dir) {
|
||||
if (errno == ENOENT) {
|
||||
*out = 0;
|
||||
ret = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = error_errno("cannot open object shard '%s'", path);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while ((ent = readdir(dir)) != NULL) {
|
||||
if (strspn(ent->d_name, "0123456789abcdef") != hexsz ||
|
||||
ent->d_name[hexsz] != '\0')
|
||||
continue;
|
||||
count++;
|
||||
}
|
||||
|
||||
*out = count * 256;
|
||||
ret = 0;
|
||||
} else {
|
||||
struct odb_for_each_object_options opts = { 0 };
|
||||
*out = 0;
|
||||
ret = odb_source_for_each_object(&files->loose->base, NULL, count_loose_object,
|
||||
out, &opts);
|
||||
}
|
||||
|
||||
out:
|
||||
if (dir)
|
||||
closedir(dir);
|
||||
free(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int check_stream_oid(git_zstream *stream,
|
||||
const char *hdr,
|
||||
unsigned long size,
|
||||
|
||||
Reference in New Issue
Block a user