Coverage Report

Created: 2026-03-31 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/odb.h
Line
Count
Source
1
#ifndef ODB_H
2
#define ODB_H
3
4
#include "hashmap.h"
5
#include "object.h"
6
#include "oidset.h"
7
#include "oidmap.h"
8
#include "string-list.h"
9
#include "thread-utils.h"
10
11
struct oidmap;
12
struct oidtree;
13
struct strbuf;
14
struct strvec;
15
struct repository;
16
struct multi_pack_index;
17
18
/*
19
 * Set this to 0 to prevent odb_read_object_info_extended() from fetching missing
20
 * blobs. This has a difference only if extensions.partialClone is set.
21
 *
22
 * Its default value is 1.
23
 */
24
extern int fetch_if_missing;
25
26
/*
27
 * Compute the exact path an alternate is at and returns it. In case of
28
 * error NULL is returned and the human readable error is added to `err`
29
 * `path` may be relative and should point to $GIT_DIR.
30
 * `err` must not be null.
31
 */
32
char *compute_alternate_path(const char *path, struct strbuf *err);
33
34
struct packed_git;
35
struct packfile_store;
36
struct cached_object_entry;
37
38
/*
39
 * A transaction may be started for an object database prior to writing new
40
 * objects via odb_transaction_begin(). These objects are not committed until
41
 * odb_transaction_commit() is invoked. Only a single transaction may be pending
42
 * at a time.
43
 *
44
 * Each ODB source is expected to implement its own transaction handling.
45
 */
46
struct odb_transaction;
47
typedef void (*odb_transaction_commit_fn)(struct odb_transaction *transaction);
48
struct odb_transaction {
49
  /* The ODB source the transaction is opened against. */
50
  struct odb_source *source;
51
52
  /* The ODB source specific callback invoked to commit a transaction. */
53
  odb_transaction_commit_fn commit;
54
};
55
56
/*
57
 * The object database encapsulates access to objects in a repository. It
58
 * manages one or more sources that store the actual objects which are
59
 * configured via alternates.
60
 */
61
struct object_database {
62
  /* Repository that owns this database. */
63
  struct repository *repo;
64
65
  /*
66
   * State of current current object database transaction. Only one
67
   * transaction may be pending at a time. Is NULL when no transaction is
68
   * configured.
69
   */
70
  struct odb_transaction *transaction;
71
72
  /*
73
   * Set of all object directories; the main directory is first (and
74
   * cannot be NULL after initialization). Subsequent directories are
75
   * alternates.
76
   */
77
  struct odb_source *sources;
78
  struct odb_source **sources_tail;
79
  struct kh_odb_path_map *source_by_path;
80
81
  int loaded_alternates;
82
83
  /*
84
   * A list of alternate object directories loaded from the environment;
85
   * this should not generally need to be accessed directly, but will
86
   * populate the "sources" list when odb_prepare_alternates() is run.
87
   */
88
  char *alternate_db;
89
90
  /*
91
   * Objects that should be substituted by other objects
92
   * (see git-replace(1)).
93
   */
94
  struct oidmap replace_map;
95
  unsigned replace_map_initialized : 1;
96
  pthread_mutex_t replace_mutex; /* protect object replace functions */
97
98
  struct commit_graph *commit_graph;
99
  unsigned commit_graph_attempted : 1; /* if loading has been attempted */
100
101
  /*
102
   * This is meant to hold a *small* number of objects that you would
103
   * want odb_read_object() to be able to return, but yet you do not want
104
   * to write them into the object store (e.g. a browse-only
105
   * application).
106
   */
107
  struct cached_object_entry *cached_objects;
108
  size_t cached_object_nr, cached_object_alloc;
109
110
  /*
111
   * A fast, rough count of the number of objects in the repository.
112
   * These two fields are not meant for direct access. Use
113
   * odb_count_objects() instead.
114
   */
115
  unsigned long object_count;
116
  unsigned object_count_flags;
117
  unsigned object_count_valid : 1;
118
119
  /*
120
   * Submodule source paths that will be added as additional sources to
121
   * allow lookup of submodule objects via the main object database.
122
   */
123
  struct string_list submodule_source_paths;
124
};
125
126
/*
127
 * Create a new object database for the given repository.
128
 *
129
 * If the primary source parameter is set it will override the usual primary
130
 * object directory derived from the repository's common directory. The
131
 * alternate sources are expected to be a PATH_SEP-separated list of secondary
132
 * sources. Note that these alternate sources will be added in addition to, not
133
 * instead of, the alternates identified by the primary source.
134
 *
135
 * Returns the newly created object database.
136
 */
137
struct object_database *odb_new(struct repository *repo,
138
        const char *primary_source,
139
        const char *alternate_sources);
140
141
/* Free the object database and release all resources. */
142
void odb_free(struct object_database *o);
143
144
/*
145
 * Close the object database and all of its sources so that any held resources
146
 * will be released. The database can still be used after closing it, in which
147
 * case these resources may be reallocated.
148
 */
149
void odb_close(struct object_database *o);
150
151
/*
152
 * Clear caches, reload alternates and then reload object sources so that new
153
 * objects may become accessible.
154
 */
155
void odb_reprepare(struct object_database *o);
156
157
/*
158
 * Starts an ODB transaction. Subsequent objects are written to the transaction
159
 * and not committed until odb_transaction_commit() is invoked on the
160
 * transaction. If the ODB already has a pending transaction, NULL is returned.
161
 */
162
struct odb_transaction *odb_transaction_begin(struct object_database *odb);
163
164
/*
165
 * Commits an ODB transaction making the written objects visible. If the
166
 * specified transaction is NULL, the function is a no-op.
167
 */
168
void odb_transaction_commit(struct odb_transaction *transaction);
169
170
/*
171
 * Find source by its object directory path. Returns a `NULL` pointer in case
172
 * the source could not be found.
173
 */
174
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
175
176
/* Same as `odb_find_source()`, but dies in case the source doesn't exist. */
177
struct odb_source *odb_find_source_or_die(struct object_database *odb, const char *obj_dir);
178
179
/*
180
 * Replace the current writable object directory with the specified temporary
181
 * object directory; returns the former primary source.
182
 */
183
struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
184
                const char *dir, int will_destroy);
185
186
/*
187
 * Restore the primary source that was previously replaced by
188
 * `odb_set_temporary_primary_source()`.
189
 */
190
void odb_restore_primary_source(struct object_database *odb,
191
        struct odb_source *restore_source,
192
        const char *old_path);
193
194
/*
195
 * Call odb_add_submodule_source_by_path() to add the submodule at the given
196
 * path to a list. The object stores of all submodules in that list will be
197
 * added as additional sources in the object store when looking up objects.
198
 */
199
void odb_add_submodule_source_by_path(struct object_database *odb,
200
              const char *path);
201
202
/*
203
 * Iterate through all alternates of the database and execute the provided
204
 * callback function for each of them. Stop iterating once the callback
205
 * function returns a non-zero value, in which case the value is bubbled up
206
 * from the callback.
207
 */
208
typedef int odb_for_each_alternate_fn(struct odb_source *, void *);
209
int odb_for_each_alternate(struct object_database *odb,
210
         odb_for_each_alternate_fn cb, void *payload);
211
212
/*
213
 * Iterate through all alternates of the database and yield their respective
214
 * references.
215
 */
216
typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
217
void odb_for_each_alternate_ref(struct object_database *odb,
218
        odb_for_each_alternate_ref_fn cb, void *payload);
219
220
/*
221
 * Create a temporary file rooted in the primary alternate's directory, or die
222
 * on failure. The filename is taken from "pattern", which should have the
223
 * usual "XXXXXX" trailer, and the resulting filename is written into the
224
 * "template" buffer. Returns the open descriptor.
225
 */
226
int odb_mkstemp(struct object_database *odb,
227
    struct strbuf *temp_filename, const char *pattern);
228
229
/*
230
 * Prepare alternate object sources for the given database by reading
231
 * "objects/info/alternates" and opening the respective sources.
232
 */
233
void odb_prepare_alternates(struct object_database *odb);
234
235
/*
236
 * Check whether the object database has any alternates. The primary object
237
 * source does not count as alternate.
238
 */
239
int odb_has_alternates(struct object_database *odb);
240
241
/*
242
 * Add the directory to the on-disk alternates file; the new entry will also
243
 * take effect in the current process.
244
 */
245
void odb_add_to_alternates_file(struct object_database *odb,
246
        const char *dir);
247
248
/*
249
 * Add the directory to the in-memory list of alternate sources (along with any
250
 * recursive alternates it points to), but do not modify the on-disk alternates
251
 * file.
252
 */
253
struct odb_source *odb_add_to_alternates_memory(struct object_database *odb,
254
            const char *dir);
255
256
/*
257
 * Read an object from the database. Returns the object data and assigns object
258
 * type and size to the `type` and `size` pointers, if these pointers are
259
 * non-NULL. Returns a `NULL` pointer in case the object does not exist.
260
 *
261
 * This function dies on corrupt objects; the callers who want to deal with
262
 * them should arrange to call odb_read_object_info_extended() and give error
263
 * messages themselves.
264
 */
265
void *odb_read_object(struct object_database *odb,
266
          const struct object_id *oid,
267
          enum object_type *type,
268
          unsigned long *size);
269
270
void *odb_read_object_peeled(struct object_database *odb,
271
           const struct object_id *oid,
272
           enum object_type required_type,
273
           unsigned long *size,
274
           struct object_id *oid_ret);
275
276
/*
277
 * Add an object file to the in-memory object store, without writing it
278
 * to disk.
279
 *
280
 * Callers are responsible for calling write_object_file to record the
281
 * object in persistent storage before writing any other new objects
282
 * that reference it.
283
 */
284
int odb_pretend_object(struct object_database *odb,
285
           void *buf, unsigned long len, enum object_type type,
286
           struct object_id *oid);
287
288
struct object_info {
289
  /* Request */
290
  enum object_type *typep;
291
  unsigned long *sizep;
292
  off_t *disk_sizep;
293
  struct object_id *delta_base_oid;
294
  void **contentp;
295
296
  /*
297
   * The time the given looked-up object has been last modified.
298
   *
299
   * Note: the mtime may be ambiguous in case the object exists multiple
300
   * times in the object database. It is thus _not_ recommended to use
301
   * this field outside of contexts where you would read every instance
302
   * of the object, like for example with `odb_for_each_object()`. As it
303
   * is impossible to say at the ODB level what the intent of the caller
304
   * is (e.g. whether to find the oldest or newest object), it is the
305
   * responsibility of the caller to disambiguate the mtimes.
306
   */
307
  time_t *mtimep;
308
309
  /* Response */
310
  enum {
311
    OI_CACHED,
312
    OI_LOOSE,
313
    OI_PACKED,
314
  } whence;
315
  union {
316
    /*
317
     * struct {
318
     *  ... Nothing to expose in this case
319
     * } cached;
320
     * struct {
321
     *  ... Nothing to expose in this case
322
     * } loose;
323
     */
324
    struct {
325
      struct packed_git *pack;
326
      off_t offset;
327
      enum packed_object_type {
328
        PACKED_OBJECT_TYPE_UNKNOWN,
329
        PACKED_OBJECT_TYPE_FULL,
330
        PACKED_OBJECT_TYPE_OFS_DELTA,
331
        PACKED_OBJECT_TYPE_REF_DELTA,
332
      } type;
333
    } packed;
334
  } u;
335
};
336
337
/*
338
 * Initializer for a "struct object_info" that wants no items. You may
339
 * also memset() the memory to all-zeroes.
340
 */
341
0
#define OBJECT_INFO_INIT { 0 }
342
343
/* Flags that can be passed to `odb_read_object_info_extended()`. */
344
enum object_info_flags {
345
  /* Invoke lookup_replace_object() on the given hash. */
346
  OBJECT_INFO_LOOKUP_REPLACE = (1 << 0),
347
348
  /* Do not reprepare object sources when the first lookup has failed. */
349
  OBJECT_INFO_QUICK = (1 << 1),
350
351
  /*
352
   * Do not attempt to fetch the object if missing (even if fetch_is_missing is
353
   * nonzero).
354
   */
355
  OBJECT_INFO_SKIP_FETCH_OBJECT = (1 << 2),
356
357
  /* Die if object corruption (not just an object being missing) was detected. */
358
  OBJECT_INFO_DIE_IF_CORRUPT = (1 << 3),
359
360
  /*
361
   * We have already tried reading the object, but it couldn't be found
362
   * via any of the attached sources, and are now doing a second read.
363
   * This second read asks the individual sources to also evaluate
364
   * whether any on-disk state may have changed that may have caused the
365
   * object to appear.
366
   *
367
   * This flag is for internal use, only. The second read only occurs
368
   * when `OBJECT_INFO_QUICK` was not passed.
369
   */
370
  OBJECT_INFO_SECOND_READ = (1 << 4),
371
372
  /*
373
   * This is meant for bulk prefetching of missing blobs in a partial
374
   * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK.
375
   */
376
  OBJECT_INFO_FOR_PREFETCH = (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK),
377
};
378
379
/*
380
 * Read object info from the object database and populate the `object_info`
381
 * structure. Returns 0 on success, a negative error code otherwise.
382
 */
383
int odb_read_object_info_extended(struct object_database *odb,
384
          const struct object_id *oid,
385
          struct object_info *oi,
386
          enum object_info_flags flags);
387
388
/*
389
 * Read a subset of object info for the given object ID. Returns an `enum
390
 * object_type` on success, a negative error code otherwise. If successful and
391
 * `sizep` is non-NULL, then the size of the object will be written to the
392
 * pointer.
393
 */
394
int odb_read_object_info(struct object_database *odb,
395
       const struct object_id *oid,
396
       unsigned long *sizep);
397
398
enum has_object_flags {
399
  /* Retry packed storage after checking packed and loose storage */
400
  HAS_OBJECT_RECHECK_PACKED = (1 << 0),
401
  /* Allow fetching the object in case the repository has a promisor remote. */
402
  HAS_OBJECT_FETCH_PROMISOR = (1 << 1),
403
};
404
405
/*
406
 * Returns 1 if the object exists. This function will not lazily fetch objects
407
 * in a partial clone by default.
408
 */
409
int odb_has_object(struct object_database *odb,
410
       const struct object_id *oid,
411
       enum has_object_flags flags);
412
413
int odb_freshen_object(struct object_database *odb,
414
           const struct object_id *oid);
415
416
void odb_assert_oid_type(struct object_database *odb,
417
       const struct object_id *oid, enum object_type expect);
418
419
/*
420
 * Enabling the object read lock allows multiple threads to safely call the
421
 * following functions in parallel: odb_read_object(),
422
 * odb_read_object_peeled(), odb_read_object_info() and odb().
423
 *
424
 * obj_read_lock() and obj_read_unlock() may also be used to protect other
425
 * section which cannot execute in parallel with object reading. Since the used
426
 * lock is a recursive mutex, these sections can even contain calls to object
427
 * reading functions. However, beware that in these cases zlib inflation won't
428
 * be performed in parallel, losing performance.
429
 *
430
 * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If
431
 * any of its callees end up calling it, this recursive call won't benefit from
432
 * parallel inflation.
433
 */
434
void enable_obj_read_lock(void);
435
void disable_obj_read_lock(void);
436
437
extern int obj_read_use_lock;
438
extern pthread_mutex_t obj_read_mutex;
439
440
static inline void obj_read_lock(void)
441
0
{
442
0
  if(obj_read_use_lock)
443
0
    pthread_mutex_lock(&obj_read_mutex);
444
0
}
Unexecuted instantiation: attr.c:obj_read_lock
Unexecuted instantiation: dir.c:obj_read_lock
Unexecuted instantiation: mailmap.c:obj_read_lock
Unexecuted instantiation: object-file.c:obj_read_lock
Unexecuted instantiation: object-name.c:obj_read_lock
Unexecuted instantiation: object.c:obj_read_lock
Unexecuted instantiation: odb.c:obj_read_lock
Unexecuted instantiation: source.c:obj_read_lock
Unexecuted instantiation: source-files.c:obj_read_lock
Unexecuted instantiation: streaming.c:obj_read_lock
Unexecuted instantiation: pack-write.c:obj_read_lock
Unexecuted instantiation: packfile.c:obj_read_lock
Unexecuted instantiation: path.c:obj_read_lock
Unexecuted instantiation: promisor-remote.c:obj_read_lock
Unexecuted instantiation: read-cache.c:obj_read_lock
Unexecuted instantiation: refs.c:obj_read_lock
Unexecuted instantiation: remote.c:obj_read_lock
Unexecuted instantiation: replace-object.c:obj_read_lock
Unexecuted instantiation: repo-settings.c:obj_read_lock
Unexecuted instantiation: repository.c:obj_read_lock
Unexecuted instantiation: revision.c:obj_read_lock
Unexecuted instantiation: run-command.c:obj_read_lock
Unexecuted instantiation: setup.c:obj_read_lock
Unexecuted instantiation: shallow.c:obj_read_lock
Unexecuted instantiation: submodule-config.c:obj_read_lock
Unexecuted instantiation: submodule.c:obj_read_lock
Unexecuted instantiation: tag.c:obj_read_lock
Unexecuted instantiation: tmp-objdir.c:obj_read_lock
Unexecuted instantiation: tree-walk.c:obj_read_lock
Unexecuted instantiation: tree.c:obj_read_lock
Unexecuted instantiation: bisect.c:obj_read_lock
Unexecuted instantiation: bloom.c:obj_read_lock
Unexecuted instantiation: bundle-uri.c:obj_read_lock
Unexecuted instantiation: bundle.c:obj_read_lock
Unexecuted instantiation: cache-tree.c:obj_read_lock
Unexecuted instantiation: combine-diff.c:obj_read_lock
Unexecuted instantiation: commit-graph.c:obj_read_lock
Unexecuted instantiation: commit-reach.c:obj_read_lock
Unexecuted instantiation: commit.c:obj_read_lock
Unexecuted instantiation: config.c:obj_read_lock
Unexecuted instantiation: connected.c:obj_read_lock
Unexecuted instantiation: convert.c:obj_read_lock
Unexecuted instantiation: diff.c:obj_read_lock
Unexecuted instantiation: diffcore-rename.c:obj_read_lock
Unexecuted instantiation: fetch-pack.c:obj_read_lock
Unexecuted instantiation: fsck.c:obj_read_lock
Unexecuted instantiation: grep.c:obj_read_lock
Unexecuted instantiation: list-objects.c:obj_read_lock
Unexecuted instantiation: log-tree.c:obj_read_lock
Unexecuted instantiation: loose.c:obj_read_lock
Unexecuted instantiation: merge-ort.c:obj_read_lock
Unexecuted instantiation: midx.c:obj_read_lock
Unexecuted instantiation: notes-cache.c:obj_read_lock
Unexecuted instantiation: notes.c:obj_read_lock
Unexecuted instantiation: pack-check.c:obj_read_lock
Unexecuted instantiation: pack-mtimes.c:obj_read_lock
Unexecuted instantiation: pack-revindex.c:obj_read_lock
Unexecuted instantiation: send-pack.c:obj_read_lock
Unexecuted instantiation: sequencer.c:obj_read_lock
Unexecuted instantiation: transport-helper.c:obj_read_lock
Unexecuted instantiation: unpack-trees.c:obj_read_lock
Unexecuted instantiation: xdiff-interface.c:obj_read_lock
Unexecuted instantiation: apply.c:obj_read_lock
Unexecuted instantiation: entry.c:obj_read_lock
Unexecuted instantiation: list-objects-filter.c:obj_read_lock
Unexecuted instantiation: match-trees.c:obj_read_lock
Unexecuted instantiation: rerere.c:obj_read_lock
445
446
static inline void obj_read_unlock(void)
447
0
{
448
0
  if(obj_read_use_lock)
449
0
    pthread_mutex_unlock(&obj_read_mutex);
450
0
}
Unexecuted instantiation: attr.c:obj_read_unlock
Unexecuted instantiation: dir.c:obj_read_unlock
Unexecuted instantiation: mailmap.c:obj_read_unlock
Unexecuted instantiation: object-file.c:obj_read_unlock
Unexecuted instantiation: object-name.c:obj_read_unlock
Unexecuted instantiation: object.c:obj_read_unlock
Unexecuted instantiation: odb.c:obj_read_unlock
Unexecuted instantiation: source.c:obj_read_unlock
Unexecuted instantiation: source-files.c:obj_read_unlock
Unexecuted instantiation: streaming.c:obj_read_unlock
Unexecuted instantiation: pack-write.c:obj_read_unlock
Unexecuted instantiation: packfile.c:obj_read_unlock
Unexecuted instantiation: path.c:obj_read_unlock
Unexecuted instantiation: promisor-remote.c:obj_read_unlock
Unexecuted instantiation: read-cache.c:obj_read_unlock
Unexecuted instantiation: refs.c:obj_read_unlock
Unexecuted instantiation: remote.c:obj_read_unlock
Unexecuted instantiation: replace-object.c:obj_read_unlock
Unexecuted instantiation: repo-settings.c:obj_read_unlock
Unexecuted instantiation: repository.c:obj_read_unlock
Unexecuted instantiation: revision.c:obj_read_unlock
Unexecuted instantiation: run-command.c:obj_read_unlock
Unexecuted instantiation: setup.c:obj_read_unlock
Unexecuted instantiation: shallow.c:obj_read_unlock
Unexecuted instantiation: submodule-config.c:obj_read_unlock
Unexecuted instantiation: submodule.c:obj_read_unlock
Unexecuted instantiation: tag.c:obj_read_unlock
Unexecuted instantiation: tmp-objdir.c:obj_read_unlock
Unexecuted instantiation: tree-walk.c:obj_read_unlock
Unexecuted instantiation: tree.c:obj_read_unlock
Unexecuted instantiation: bisect.c:obj_read_unlock
Unexecuted instantiation: bloom.c:obj_read_unlock
Unexecuted instantiation: bundle-uri.c:obj_read_unlock
Unexecuted instantiation: bundle.c:obj_read_unlock
Unexecuted instantiation: cache-tree.c:obj_read_unlock
Unexecuted instantiation: combine-diff.c:obj_read_unlock
Unexecuted instantiation: commit-graph.c:obj_read_unlock
Unexecuted instantiation: commit-reach.c:obj_read_unlock
Unexecuted instantiation: commit.c:obj_read_unlock
Unexecuted instantiation: config.c:obj_read_unlock
Unexecuted instantiation: connected.c:obj_read_unlock
Unexecuted instantiation: convert.c:obj_read_unlock
Unexecuted instantiation: diff.c:obj_read_unlock
Unexecuted instantiation: diffcore-rename.c:obj_read_unlock
Unexecuted instantiation: fetch-pack.c:obj_read_unlock
Unexecuted instantiation: fsck.c:obj_read_unlock
Unexecuted instantiation: grep.c:obj_read_unlock
Unexecuted instantiation: list-objects.c:obj_read_unlock
Unexecuted instantiation: log-tree.c:obj_read_unlock
Unexecuted instantiation: loose.c:obj_read_unlock
Unexecuted instantiation: merge-ort.c:obj_read_unlock
Unexecuted instantiation: midx.c:obj_read_unlock
Unexecuted instantiation: notes-cache.c:obj_read_unlock
Unexecuted instantiation: notes.c:obj_read_unlock
Unexecuted instantiation: pack-check.c:obj_read_unlock
Unexecuted instantiation: pack-mtimes.c:obj_read_unlock
Unexecuted instantiation: pack-revindex.c:obj_read_unlock
Unexecuted instantiation: send-pack.c:obj_read_unlock
Unexecuted instantiation: sequencer.c:obj_read_unlock
Unexecuted instantiation: transport-helper.c:obj_read_unlock
Unexecuted instantiation: unpack-trees.c:obj_read_unlock
Unexecuted instantiation: xdiff-interface.c:obj_read_unlock
Unexecuted instantiation: apply.c:obj_read_unlock
Unexecuted instantiation: entry.c:obj_read_unlock
Unexecuted instantiation: list-objects-filter.c:obj_read_unlock
Unexecuted instantiation: match-trees.c:obj_read_unlock
Unexecuted instantiation: rerere.c:obj_read_unlock
451
452
/* Flags for for_each_*_object(). */
453
enum odb_for_each_object_flags {
454
  /* Iterate only over local objects, not alternates. */
455
  ODB_FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
456
457
  /* Only iterate over packs obtained from the promisor remote. */
458
  ODB_FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
459
460
  /*
461
   * Visit objects within a pack in packfile order rather than .idx order
462
   */
463
  ODB_FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
464
465
  /* Only iterate over packs that are not marked as kept in-core. */
466
  ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
467
468
  /* Only iterate over packs that do not have .keep files. */
469
  ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
470
};
471
472
/*
473
 * A callback function that can be used to iterate through objects. If given,
474
 * the optional `oi` parameter will be populated the same as if you would call
475
 * `odb_read_object_info()`.
476
 *
477
 * Returning a non-zero error code will cause iteration to abort. The error
478
 * code will be propagated.
479
 */
480
typedef int (*odb_for_each_object_cb)(const struct object_id *oid,
481
              struct object_info *oi,
482
              void *cb_data);
483
484
/*
485
 * Iterate through all objects contained in the object database. Note that
486
 * objects may be iterated over multiple times in case they are either stored
487
 * in different backends or in case they are stored in multiple sources.
488
 * If an object info request is given, then the object info will be read and
489
 * passed to the callback as if `odb_read_object_info()` was called for the
490
 * object.
491
 *
492
 * Returning a non-zero error code from the callback function will cause
493
 * iteration to abort. The error code will be propagated.
494
 *
495
 * Returns 0 on success, a negative error code in case a failure occurred, or
496
 * an arbitrary non-zero error code returned by the callback itself.
497
 */
498
int odb_for_each_object(struct object_database *odb,
499
      const struct object_info *request,
500
      odb_for_each_object_cb cb,
501
      void *cb_data,
502
      unsigned flags);
503
504
enum odb_count_objects_flags {
505
  /*
506
   * Instead of providing an accurate count, allow the number of objects
507
   * to be approximated. Details of how this approximation works are
508
   * subject to the specific source's implementation.
509
   */
510
  ODB_COUNT_OBJECTS_APPROXIMATE = (1 << 0),
511
};
512
513
/*
514
 * Count the number of objects in the given object database. This object count
515
 * may double-count objects that are stored in multiple backends, or which are
516
 * stored multiple times in a single backend.
517
 *
518
 * Returns 0 on success, a negative error code otherwise. The number of objects
519
 * will be assigned to the `out` pointer on success.
520
 */
521
int odb_count_objects(struct object_database *odb,
522
          enum odb_count_objects_flags flags,
523
          unsigned long *out);
524
525
enum {
526
  /*
527
   * By default, `odb_write_object()` does not actually write anything
528
   * into the object store, but only computes the object ID. This flag
529
   * changes that so that the object will be written as a loose object
530
   * and persisted.
531
   */
532
  WRITE_OBJECT_PERSIST = (1 << 0),
533
534
  /*
535
   * Do not print an error in case something goes wrong.
536
   */
537
  WRITE_OBJECT_SILENT = (1 << 1),
538
};
539
540
/*
541
 * Write an object into the object database. The object is being written into
542
 * the local alternate of the repository. If provided, the converted object ID
543
 * as well as the compatibility object ID are written to the respective
544
 * pointers.
545
 *
546
 * Returns 0 on success, a negative error code otherwise.
547
 */
548
int odb_write_object_ext(struct object_database *odb,
549
       const void *buf, unsigned long len,
550
       enum object_type type,
551
       struct object_id *oid,
552
       struct object_id *compat_oid,
553
       unsigned flags);
554
555
static inline int odb_write_object(struct object_database *odb,
556
           const void *buf, unsigned long len,
557
           enum object_type type,
558
           struct object_id *oid)
559
0
{
560
  return odb_write_object_ext(odb, buf, len, type, oid, NULL, 0);
561
0
}
Unexecuted instantiation: attr.c:odb_write_object
Unexecuted instantiation: dir.c:odb_write_object
Unexecuted instantiation: mailmap.c:odb_write_object
Unexecuted instantiation: object-file.c:odb_write_object
Unexecuted instantiation: object-name.c:odb_write_object
Unexecuted instantiation: object.c:odb_write_object
Unexecuted instantiation: odb.c:odb_write_object
Unexecuted instantiation: source.c:odb_write_object
Unexecuted instantiation: source-files.c:odb_write_object
Unexecuted instantiation: streaming.c:odb_write_object
Unexecuted instantiation: pack-write.c:odb_write_object
Unexecuted instantiation: packfile.c:odb_write_object
Unexecuted instantiation: path.c:odb_write_object
Unexecuted instantiation: promisor-remote.c:odb_write_object
Unexecuted instantiation: read-cache.c:odb_write_object
Unexecuted instantiation: refs.c:odb_write_object
Unexecuted instantiation: remote.c:odb_write_object
Unexecuted instantiation: replace-object.c:odb_write_object
Unexecuted instantiation: repo-settings.c:odb_write_object
Unexecuted instantiation: repository.c:odb_write_object
Unexecuted instantiation: revision.c:odb_write_object
Unexecuted instantiation: run-command.c:odb_write_object
Unexecuted instantiation: setup.c:odb_write_object
Unexecuted instantiation: shallow.c:odb_write_object
Unexecuted instantiation: submodule-config.c:odb_write_object
Unexecuted instantiation: submodule.c:odb_write_object
Unexecuted instantiation: tag.c:odb_write_object
Unexecuted instantiation: tmp-objdir.c:odb_write_object
Unexecuted instantiation: tree-walk.c:odb_write_object
Unexecuted instantiation: tree.c:odb_write_object
Unexecuted instantiation: bisect.c:odb_write_object
Unexecuted instantiation: bloom.c:odb_write_object
Unexecuted instantiation: bundle-uri.c:odb_write_object
Unexecuted instantiation: bundle.c:odb_write_object
Unexecuted instantiation: cache-tree.c:odb_write_object
Unexecuted instantiation: combine-diff.c:odb_write_object
Unexecuted instantiation: commit-graph.c:odb_write_object
Unexecuted instantiation: commit-reach.c:odb_write_object
Unexecuted instantiation: commit.c:odb_write_object
Unexecuted instantiation: config.c:odb_write_object
Unexecuted instantiation: connected.c:odb_write_object
Unexecuted instantiation: convert.c:odb_write_object
Unexecuted instantiation: diff.c:odb_write_object
Unexecuted instantiation: diffcore-rename.c:odb_write_object
Unexecuted instantiation: fetch-pack.c:odb_write_object
Unexecuted instantiation: fsck.c:odb_write_object
Unexecuted instantiation: grep.c:odb_write_object
Unexecuted instantiation: list-objects.c:odb_write_object
Unexecuted instantiation: log-tree.c:odb_write_object
Unexecuted instantiation: loose.c:odb_write_object
Unexecuted instantiation: merge-ort.c:odb_write_object
Unexecuted instantiation: midx.c:odb_write_object
Unexecuted instantiation: notes-cache.c:odb_write_object
Unexecuted instantiation: notes.c:odb_write_object
Unexecuted instantiation: pack-check.c:odb_write_object
Unexecuted instantiation: pack-mtimes.c:odb_write_object
Unexecuted instantiation: pack-revindex.c:odb_write_object
Unexecuted instantiation: send-pack.c:odb_write_object
Unexecuted instantiation: sequencer.c:odb_write_object
Unexecuted instantiation: transport-helper.c:odb_write_object
Unexecuted instantiation: unpack-trees.c:odb_write_object
Unexecuted instantiation: xdiff-interface.c:odb_write_object
Unexecuted instantiation: apply.c:odb_write_object
Unexecuted instantiation: entry.c:odb_write_object
Unexecuted instantiation: list-objects-filter.c:odb_write_object
Unexecuted instantiation: match-trees.c:odb_write_object
Unexecuted instantiation: rerere.c:odb_write_object
562
563
struct odb_write_stream {
564
  const void *(*read)(struct odb_write_stream *, unsigned long *len);
565
  void *data;
566
  int is_finished;
567
};
568
569
int odb_write_object_stream(struct object_database *odb,
570
          struct odb_write_stream *stream, size_t len,
571
          struct object_id *oid);
572
573
void parse_alternates(const char *string,
574
          int sep,
575
          const char *relative_base,
576
          struct strvec *out);
577
578
#endif /* ODB_H */