MCPcopy Create free account
hub / github.com/git/git / odb_source_loose_count_objects

Function odb_source_loose_count_objects

odb/source-loose.c:525–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

523}
524
525static int odb_source_loose_count_objects(struct odb_source *source,
526 enum odb_count_objects_flags flags,
527 unsigned long *out)
528{
529 struct odb_source_loose *loose = odb_source_loose_downcast(source);
530 const unsigned hexsz = source->odb->repo->hash_algo->hexsz - 2;
531 char *path = NULL;
532 DIR *dir = NULL;
533 int ret;
534
535 if (flags & ODB_COUNT_OBJECTS_APPROXIMATE) {
536 unsigned long count = 0;
537 struct dirent *ent;
538
539 path = xstrfmt("%s/17", source->path);
540
541 dir = opendir(path);
542 if (!dir) {
543 if (errno == ENOENT) {
544 *out = 0;
545 ret = 0;
546 goto out;
547 }
548
549 ret = error_errno("cannot open object shard '%s'", path);
550 goto out;
551 }
552
553 while ((ent = readdir(dir)) != NULL) {
554 if (strspn(ent->d_name, "0123456789abcdef") != hexsz ||
555 ent->d_name[hexsz] != '\0')
556 continue;
557 count++;
558 }
559
560 *out = count * 256;
561 ret = 0;
562 } else {
563 struct odb_for_each_object_options opts = { 0 };
564 *out = 0;
565 ret = odb_source_for_each_object(&loose->base, NULL, count_loose_object,
566 out, &opts);
567 }
568
569out:
570 if (dir)
571 closedir(dir);
572 free(path);
573 return ret;
574}
575
576static int odb_source_loose_freshen_object(struct odb_source *source,
577 const struct object_id *oid)

Callers

nothing calls this directly

Calls 7

xstrfmtFunction · 0.85
opendirFunction · 0.85
error_errnoFunction · 0.85
readdirFunction · 0.85
closedirFunction · 0.85

Tested by

no test coverage detected