interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / odb / source-files.h

109 lines · 3322 bytes Raw Blame History
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
8struct odb_source_loose;
9struct 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 */
16struct 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
34struct odb_files_dir *odb_files_dir_new(struct object_database *odb,
35 const char *path, bool local);
36void 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 */
42struct 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. */
71struct 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 */
79int 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 */
87bool 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 */
94static inline struct odb_source_files *odb_source_files_downcast(struct odb_source *source)
95{
96 if (source->type != ODB_SOURCE_FILES)
97 BUG("trying to downcast source of type '%s' to '%s'",
98 odb_source_type_to_name(source->type),
99 odb_source_type_to_name(ODB_SOURCE_FILES));
100 return container_of(source, struct odb_source_files, base);
101}
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 */
107struct odb_files_dir *odb_source_files_find_dir(struct object_database *odb, const char *obj_dir);
108
109#endif