Coverage Report

Created: 2026-11-12 06:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/odb/source-files.h
Line
Count
Source
1
#ifndef ODB_SOURCE_FILES_H
2
#define ODB_SOURCE_FILES_H
3
4
#include "odb/source.h"
5
#include "statinfo.h"
6
#include "strmap.h"
7
8
struct odb_source_loose;
9
struct odb_source_packed;
10
11
/*
12
 * A single object directory that encapsulates access to both the loose and
13
 * packed backend. This can either be the primary or an alternate object
14
 * directory.
15
 */
16
struct odb_files_dir {
17
  /* Absolute path to the object directory. */
18
  char *abspath;
19
20
  /* List of alternate object directories. */
21
  struct odb_files_dir *next;
22
23
  /* The two sources derived from this object directory. */
24
  struct odb_source_loose *loose;
25
  struct odb_source_packed *packed;
26
27
  /*
28
   * Whether this is the local object directory of the owning
29
   * repository. Directories added via alternates are not local.
30
   */
31
  bool local;
32
};
33
34
struct odb_files_dir *odb_files_dir_new(struct object_database *odb,
35
          const char *path, bool local);
36
void odb_files_dir_free(struct odb_files_dir *dir);
37
38
/*
39
 * The files object database source uses a combination of loose objects and
40
 * packfiles. It is the default backend used by Git to store objects.
41
 */
42
struct odb_source_files {
43
  struct odb_source base;
44
45
  /*
46
   * List of all object directories; the main directory is first (and
47
   * cannot be NULL after initialization). Subsequent directories are
48
   * alternates.
49
   */
50
  struct odb_files_dir *dirs;
51
  struct odb_files_dir **dirs_tail;
52
53
  /*
54
   * Set of directory paths that have already been linked into this
55
   * source. This set is used to detect the case where the same directory
56
   * is registered multiple times.
57
   */
58
  struct strset dir_paths;
59
60
  /*
61
   * Whether directory paths shall be compared case-insensitively, as
62
   * determined by "core.ignoreCase".
63
   */
64
  int dir_paths_icase;
65
66
  /* Stat data of the "info/alternates" file. */
67
  struct stat_validity alternates_validity;
68
};
69
70
/* Allocate and initialize a new object source. */
71
struct odb_source_files *odb_source_files_new(struct object_database *odb,
72
                const char *payload,
73
                enum odb_new_flags flags);
74
75
/*
76
 * Optimize the files object database source by repacking loose objects and
77
 * packfiles as needed. Returns 0 on success, a negative error code otherwise.
78
 */
79
int odb_source_files_optimize(struct odb_source *source,
80
            const struct odb_optimize_options *opts);
81
82
/*
83
 * Check whether optimization of the files object database source is required
84
 * given the provided options. Returns true if optimization should be
85
 * performed, false otherwise.
86
 */
87
bool odb_source_files_optimize_required(struct odb_source *source,
88
          const struct odb_optimize_options *opts);
89
90
/*
91
 * Cast the given object database source to the files backend. This will cause
92
 * a BUG in case the source doesn't use this backend.
93
 */
94
static inline struct odb_source_files *odb_source_files_downcast(struct odb_source *source)
95
0
{
96
0
  if (source->type != ODB_SOURCE_FILES)
97
0
    BUG("trying to downcast source of type '%s' to '%s'",
98
0
        odb_source_type_to_name(source->type),
99
0
        odb_source_type_to_name(ODB_SOURCE_FILES));
100
0
  return container_of(source, struct odb_source_files, base);
101
0
}
Unexecuted instantiation: object-file.c:odb_source_files_downcast
Unexecuted instantiation: odb.c:odb_source_files_downcast
Unexecuted instantiation: source.c:odb_source_files_downcast
Unexecuted instantiation: source-files.c:odb_source_files_downcast
Unexecuted instantiation: source-loose.c:odb_source_files_downcast
Unexecuted instantiation: source-packed.c:odb_source_files_downcast
Unexecuted instantiation: pack-bitmap.c:odb_source_files_downcast
Unexecuted instantiation: pack-check.c:odb_source_files_downcast
Unexecuted instantiation: pack-objects.c:odb_source_files_downcast
Unexecuted instantiation: pack-revindex.c:odb_source_files_downcast
Unexecuted instantiation: pack-write.c:odb_source_files_downcast
Unexecuted instantiation: packfile.c:odb_source_files_downcast
Unexecuted instantiation: packfile-list.c:odb_source_files_downcast
Unexecuted instantiation: path.c:odb_source_files_downcast
Unexecuted instantiation: promisor-remote.c:odb_source_files_downcast
Unexecuted instantiation: pseudo-merge.c:odb_source_files_downcast
Unexecuted instantiation: repack.c:odb_source_files_downcast
Unexecuted instantiation: repack-geometry.c:odb_source_files_downcast
Unexecuted instantiation: repo-settings.c:odb_source_files_downcast
Unexecuted instantiation: revision.c:odb_source_files_downcast
Unexecuted instantiation: run-command.c:odb_source_files_downcast
Unexecuted instantiation: tag.c:odb_source_files_downcast
Unexecuted instantiation: tmp-objdir.c:odb_source_files_downcast
Unexecuted instantiation: commit-graph.c:odb_source_files_downcast
Unexecuted instantiation: connected.c:odb_source_files_downcast
Unexecuted instantiation: diff.c:odb_source_files_downcast
Unexecuted instantiation: fetch-pack.c:odb_source_files_downcast
Unexecuted instantiation: fsck.c:odb_source_files_downcast
Unexecuted instantiation: list-objects.c:odb_source_files_downcast
Unexecuted instantiation: loose.c:odb_source_files_downcast
Unexecuted instantiation: midx.c:odb_source_files_downcast
Unexecuted instantiation: pack-bitmap-write.c:odb_source_files_downcast
Unexecuted instantiation: pack-mtimes.c:odb_source_files_downcast
Unexecuted instantiation: transport-helper.c:odb_source_files_downcast
102
103
/*
104
 * Find "files" directory by its object directory path. Returns a `NULL`
105
 * pointer in case the object directory could not be found.
106
 */
107
struct odb_files_dir *odb_source_files_find_dir(struct object_database *odb, const char *obj_dir);
108
109
#endif