Coverage Report

Created: 2026-03-21 06:46

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 "odb/source.h"
7
#include "oidset.h"
8
#include "oidmap.h"
9
#include "string-list.h"
10
#include "thread-utils.h"
11
12
struct oidmap;
13
struct oidtree;
14
struct strbuf;
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
   * repo_approximate_object_count() instead.
114
   */
115
  unsigned long approximate_object_count;
116
  unsigned approximate_object_count_valid : 1;
117
118
  /*
119
   * Submodule source paths that will be added as additional sources to
120
   * allow lookup of submodule objects via the main object database.
121
   */
122
  struct string_list submodule_source_paths;
123
};
124
125
/*
126
 * Create a new object database for the given repository.
127
 *
128
 * If the primary source parameter is set it will override the usual primary
129
 * object directory derived from the repository's common directory. The
130
 * alternate sources are expected to be a PATH_SEP-separated list of secondary
131
 * sources. Note that these alternate sources will be added in addition to, not
132
 * instead of, the alternates identified by the primary source.
133
 *
134
 * Returns the newly created object database.
135
 */
136
struct object_database *odb_new(struct repository *repo,
137
        const char *primary_source,
138
        const char *alternate_sources);
139
140
/* Free the object database and release all resources. */
141
void odb_free(struct object_database *o);
142
143
/*
144
 * Close the object database and all of its sources so that any held resources
145
 * will be released. The database can still be used after closing it, in which
146
 * case these resources may be reallocated.
147
 */
148
void odb_close(struct object_database *o);
149
150
/*
151
 * Clear caches, reload alternates and then reload object sources so that new
152
 * objects may become accessible.
153
 */
154
void odb_reprepare(struct object_database *o);
155
156
/*
157
 * Starts an ODB transaction. Subsequent objects are written to the transaction
158
 * and not committed until odb_transaction_commit() is invoked on the
159
 * transaction. If the ODB already has a pending transaction, NULL is returned.
160
 */
161
struct odb_transaction *odb_transaction_begin(struct object_database *odb);
162
163
/*
164
 * Commits an ODB transaction making the written objects visible. If the
165
 * specified transaction is NULL, the function is a no-op.
166
 */
167
void odb_transaction_commit(struct odb_transaction *transaction);
168
169
/*
170
 * Find source by its object directory path. Returns a `NULL` pointer in case
171
 * the source could not be found.
172
 */
173
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
174
175
/* Same as `odb_find_source()`, but dies in case the source doesn't exist. */
176
struct odb_source *odb_find_source_or_die(struct object_database *odb, const char *obj_dir);
177
178
/*
179
 * Replace the current writable object directory with the specified temporary
180
 * object directory; returns the former primary source.
181
 */
182
struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
183
                const char *dir, int will_destroy);
184
185
/*
186
 * Restore the primary source that was previously replaced by
187
 * `odb_set_temporary_primary_source()`.
188
 */
189
void odb_restore_primary_source(struct object_database *odb,
190
        struct odb_source *restore_source,
191
        const char *old_path);
192
193
/*
194
 * Call odb_add_submodule_source_by_path() to add the submodule at the given
195
 * path to a list. The object stores of all submodules in that list will be
196
 * added as additional sources in the object store when looking up objects.
197
 */
198
void odb_add_submodule_source_by_path(struct object_database *odb,
199
              const char *path);
200
201
/*
202
 * Iterate through all alternates of the database and execute the provided
203
 * callback function for each of them. Stop iterating once the callback
204
 * function returns a non-zero value, in which case the value is bubbled up
205
 * from the callback.
206
 */
207
typedef int odb_for_each_alternate_fn(struct odb_source *, void *);
208
int odb_for_each_alternate(struct object_database *odb,
209
         odb_for_each_alternate_fn cb, void *payload);
210
211
/*
212
 * Iterate through all alternates of the database and yield their respective
213
 * references.
214
 */
215
typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
216
void odb_for_each_alternate_ref(struct object_database *odb,
217
        odb_for_each_alternate_ref_fn cb, void *payload);
218
219
/*
220
 * Create a temporary file rooted in the primary alternate's directory, or die
221
 * on failure. The filename is taken from "pattern", which should have the
222
 * usual "XXXXXX" trailer, and the resulting filename is written into the
223
 * "template" buffer. Returns the open descriptor.
224
 */
225
int odb_mkstemp(struct object_database *odb,
226
    struct strbuf *temp_filename, const char *pattern);
227
228
/*
229
 * Prepare alternate object sources for the given database by reading
230
 * "objects/info/alternates" and opening the respective sources.
231
 */
232
void odb_prepare_alternates(struct object_database *odb);
233
234
/*
235
 * Check whether the object database has any alternates. The primary object
236
 * source does not count as alternate.
237
 */
238
int odb_has_alternates(struct object_database *odb);
239
240
/*
241
 * Add the directory to the on-disk alternates file; the new entry will also
242
 * take effect in the current process.
243
 */
244
void odb_add_to_alternates_file(struct object_database *odb,
245
        const char *dir);
246
247
/*
248
 * Add the directory to the in-memory list of alternate sources (along with any
249
 * recursive alternates it points to), but do not modify the on-disk alternates
250
 * file.
251
 */
252
struct odb_source *odb_add_to_alternates_memory(struct object_database *odb,
253
            const char *dir);
254
255
/*
256
 * Read an object from the database. Returns the object data and assigns object
257
 * type and size to the `type` and `size` pointers, if these pointers are
258
 * non-NULL. Returns a `NULL` pointer in case the object does not exist.
259
 *
260
 * This function dies on corrupt objects; the callers who want to deal with
261
 * them should arrange to call odb_read_object_info_extended() and give error
262
 * messages themselves.
263
 */
264
void *odb_read_object(struct object_database *odb,
265
          const struct object_id *oid,
266
          enum object_type *type,
267
          unsigned long *size);
268
269
void *odb_read_object_peeled(struct object_database *odb,
270
           const struct object_id *oid,
271
           enum object_type required_type,
272
           unsigned long *size,
273
           struct object_id *oid_ret);
274
275
/*
276
 * Add an object file to the in-memory object store, without writing it
277
 * to disk.
278
 *
279
 * Callers are responsible for calling write_object_file to record the
280
 * object in persistent storage before writing any other new objects
281
 * that reference it.
282
 */
283
int odb_pretend_object(struct object_database *odb,
284
           void *buf, unsigned long len, enum object_type type,
285
           struct object_id *oid);
286
287
struct object_info {
288
  /* Request */
289
  enum object_type *typep;
290
  unsigned long *sizep;
291
  off_t *disk_sizep;
292
  struct object_id *delta_base_oid;
293
  void **contentp;
294
295
  /*
296
   * The time the given looked-up object has been last modified.
297
   *
298
   * Note: the mtime may be ambiguous in case the object exists multiple
299
   * times in the object database. It is thus _not_ recommended to use
300
   * this field outside of contexts where you would read every instance
301
   * of the object, like for example with `odb_for_each_object()`. As it
302
   * is impossible to say at the ODB level what the intent of the caller
303
   * is (e.g. whether to find the oldest or newest object), it is the
304
   * responsibility of the caller to disambiguate the mtimes.
305
   */
306
  time_t *mtimep;
307
308
  /* Response */
309
  enum {
310
    OI_CACHED,
311
    OI_LOOSE,
312
    OI_PACKED,
313
  } whence;
314
  union {
315
    /*
316
     * struct {
317
     *  ... Nothing to expose in this case
318
     * } cached;
319
     * struct {
320
     *  ... Nothing to expose in this case
321
     * } loose;
322
     */
323
    struct {
324
      struct packed_git *pack;
325
      off_t offset;
326
      enum packed_object_type {
327
        PACKED_OBJECT_TYPE_UNKNOWN,
328
        PACKED_OBJECT_TYPE_FULL,
329
        PACKED_OBJECT_TYPE_OFS_DELTA,
330
        PACKED_OBJECT_TYPE_REF_DELTA,
331
      } type;
332
    } packed;
333
  } u;
334
};
335
336
/*
337
 * Initializer for a "struct object_info" that wants no items. You may
338
 * also memset() the memory to all-zeroes.
339
 */
340
0
#define OBJECT_INFO_INIT { 0 }
341
342
/*
343
 * Read object info from the object database and populate the `object_info`
344
 * structure. Returns 0 on success, a negative error code otherwise.
345
 */
346
int odb_read_object_info_extended(struct object_database *odb,
347
          const struct object_id *oid,
348
          struct object_info *oi,
349
          enum object_info_flags flags);
350
351
/*
352
 * Read a subset of object info for the given object ID. Returns an `enum
353
 * object_type` on success, a negative error code otherwise. If successful and
354
 * `sizep` is non-NULL, then the size of the object will be written to the
355
 * pointer.
356
 */
357
int odb_read_object_info(struct object_database *odb,
358
       const struct object_id *oid,
359
       unsigned long *sizep);
360
361
enum has_object_flags {
362
  /* Retry packed storage after checking packed and loose storage */
363
  HAS_OBJECT_RECHECK_PACKED = (1 << 0),
364
  /* Allow fetching the object in case the repository has a promisor remote. */
365
  HAS_OBJECT_FETCH_PROMISOR = (1 << 1),
366
};
367
368
/*
369
 * Returns 1 if the object exists. This function will not lazily fetch objects
370
 * in a partial clone by default.
371
 */
372
int odb_has_object(struct object_database *odb,
373
       const struct object_id *oid,
374
       enum has_object_flags flags);
375
376
int odb_freshen_object(struct object_database *odb,
377
           const struct object_id *oid);
378
379
void odb_assert_oid_type(struct object_database *odb,
380
       const struct object_id *oid, enum object_type expect);
381
382
/*
383
 * Enabling the object read lock allows multiple threads to safely call the
384
 * following functions in parallel: odb_read_object(),
385
 * odb_read_object_peeled(), odb_read_object_info() and odb().
386
 *
387
 * obj_read_lock() and obj_read_unlock() may also be used to protect other
388
 * section which cannot execute in parallel with object reading. Since the used
389
 * lock is a recursive mutex, these sections can even contain calls to object
390
 * reading functions. However, beware that in these cases zlib inflation won't
391
 * be performed in parallel, losing performance.
392
 *
393
 * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If
394
 * any of its callees end up calling it, this recursive call won't benefit from
395
 * parallel inflation.
396
 */
397
void enable_obj_read_lock(void);
398
void disable_obj_read_lock(void);
399
400
extern int obj_read_use_lock;
401
extern pthread_mutex_t obj_read_mutex;
402
403
static inline void obj_read_lock(void)
404
0
{
405
0
  if(obj_read_use_lock)
406
0
    pthread_mutex_lock(&obj_read_mutex);
407
0
}
Unexecuted instantiation: fuzz-pack-idx.c:obj_read_lock
Unexecuted instantiation: packfile.c:obj_read_lock
Unexecuted instantiation: promisor-remote.c:obj_read_lock
Unexecuted instantiation: repo-settings.c:obj_read_lock
Unexecuted instantiation: repository.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: tree-walk.c:obj_read_lock
Unexecuted instantiation: tree.c:obj_read_lock
Unexecuted instantiation: cache-tree.c:obj_read_lock
Unexecuted instantiation: combine-diff.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: convert.c:obj_read_lock
Unexecuted instantiation: diff.c:obj_read_lock
Unexecuted instantiation: diffcore-rename.c:obj_read_lock
Unexecuted instantiation: dir.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: mailmap.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: 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-check.c:obj_read_lock
Unexecuted instantiation: pack-mtimes.c:obj_read_lock
Unexecuted instantiation: pack-revindex.c:obj_read_lock
Unexecuted instantiation: pack-write.c:obj_read_lock
Unexecuted instantiation: path.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: revision.c:obj_read_lock
Unexecuted instantiation: sequencer.c:obj_read_lock
Unexecuted instantiation: tmp-objdir.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: attr.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: commit-graph.c:obj_read_lock
Unexecuted instantiation: connected.c:obj_read_lock
Unexecuted instantiation: entry.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-filter.c:obj_read_lock
Unexecuted instantiation: match-trees.c:obj_read_lock
Unexecuted instantiation: rerere.c:obj_read_lock
Unexecuted instantiation: send-pack.c:obj_read_lock
Unexecuted instantiation: transport-helper.c:obj_read_lock
408
409
static inline void obj_read_unlock(void)
410
0
{
411
0
  if(obj_read_use_lock)
412
0
    pthread_mutex_unlock(&obj_read_mutex);
413
0
}
Unexecuted instantiation: fuzz-pack-idx.c:obj_read_unlock
Unexecuted instantiation: packfile.c:obj_read_unlock
Unexecuted instantiation: promisor-remote.c:obj_read_unlock
Unexecuted instantiation: repo-settings.c:obj_read_unlock
Unexecuted instantiation: repository.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: tree-walk.c:obj_read_unlock
Unexecuted instantiation: tree.c:obj_read_unlock
Unexecuted instantiation: cache-tree.c:obj_read_unlock
Unexecuted instantiation: combine-diff.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: convert.c:obj_read_unlock
Unexecuted instantiation: diff.c:obj_read_unlock
Unexecuted instantiation: diffcore-rename.c:obj_read_unlock
Unexecuted instantiation: dir.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: mailmap.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: 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-check.c:obj_read_unlock
Unexecuted instantiation: pack-mtimes.c:obj_read_unlock
Unexecuted instantiation: pack-revindex.c:obj_read_unlock
Unexecuted instantiation: pack-write.c:obj_read_unlock
Unexecuted instantiation: path.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: revision.c:obj_read_unlock
Unexecuted instantiation: sequencer.c:obj_read_unlock
Unexecuted instantiation: tmp-objdir.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: attr.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: commit-graph.c:obj_read_unlock
Unexecuted instantiation: connected.c:obj_read_unlock
Unexecuted instantiation: entry.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-filter.c:obj_read_unlock
Unexecuted instantiation: match-trees.c:obj_read_unlock
Unexecuted instantiation: rerere.c:obj_read_unlock
Unexecuted instantiation: send-pack.c:obj_read_unlock
Unexecuted instantiation: transport-helper.c:obj_read_unlock
414
415
/* Flags for for_each_*_object(). */
416
enum odb_for_each_object_flags {
417
  /* Iterate only over local objects, not alternates. */
418
  ODB_FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
419
420
  /* Only iterate over packs obtained from the promisor remote. */
421
  ODB_FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
422
423
  /*
424
   * Visit objects within a pack in packfile order rather than .idx order
425
   */
426
  ODB_FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
427
428
  /* Only iterate over packs that are not marked as kept in-core. */
429
  ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
430
431
  /* Only iterate over packs that do not have .keep files. */
432
  ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
433
};
434
435
/*
436
 * Iterate through all objects contained in the object database. Note that
437
 * objects may be iterated over multiple times in case they are either stored
438
 * in different backends or in case they are stored in multiple sources.
439
 * If an object info request is given, then the object info will be read and
440
 * passed to the callback as if `odb_read_object_info()` was called for the
441
 * object.
442
 *
443
 * Returning a non-zero error code from the callback function will cause
444
 * iteration to abort. The error code will be propagated.
445
 *
446
 * Returns 0 on success, a negative error code in case a failure occurred, or
447
 * an arbitrary non-zero error code returned by the callback itself.
448
 */
449
int odb_for_each_object(struct object_database *odb,
450
      const struct object_info *request,
451
      odb_for_each_object_cb cb,
452
      void *cb_data,
453
      unsigned flags);
454
455
enum {
456
  /*
457
   * By default, `odb_write_object()` does not actually write anything
458
   * into the object store, but only computes the object ID. This flag
459
   * changes that so that the object will be written as a loose object
460
   * and persisted.
461
   */
462
  WRITE_OBJECT_PERSIST = (1 << 0),
463
464
  /*
465
   * Do not print an error in case something goes wrong.
466
   */
467
  WRITE_OBJECT_SILENT = (1 << 1),
468
};
469
470
/*
471
 * Write an object into the object database. The object is being written into
472
 * the local alternate of the repository. If provided, the converted object ID
473
 * as well as the compatibility object ID are written to the respective
474
 * pointers.
475
 *
476
 * Returns 0 on success, a negative error code otherwise.
477
 */
478
int odb_write_object_ext(struct object_database *odb,
479
       const void *buf, unsigned long len,
480
       enum object_type type,
481
       struct object_id *oid,
482
       struct object_id *compat_oid,
483
       unsigned flags);
484
485
static inline int odb_write_object(struct object_database *odb,
486
           const void *buf, unsigned long len,
487
           enum object_type type,
488
           struct object_id *oid)
489
0
{
490
  return odb_write_object_ext(odb, buf, len, type, oid, NULL, 0);
491
0
}
Unexecuted instantiation: fuzz-pack-idx.c:odb_write_object
Unexecuted instantiation: packfile.c:odb_write_object
Unexecuted instantiation: promisor-remote.c:odb_write_object
Unexecuted instantiation: repo-settings.c:odb_write_object
Unexecuted instantiation: repository.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: tree-walk.c:odb_write_object
Unexecuted instantiation: tree.c:odb_write_object
Unexecuted instantiation: cache-tree.c:odb_write_object
Unexecuted instantiation: combine-diff.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: convert.c:odb_write_object
Unexecuted instantiation: diff.c:odb_write_object
Unexecuted instantiation: diffcore-rename.c:odb_write_object
Unexecuted instantiation: dir.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: mailmap.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: 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-check.c:odb_write_object
Unexecuted instantiation: pack-mtimes.c:odb_write_object
Unexecuted instantiation: pack-revindex.c:odb_write_object
Unexecuted instantiation: pack-write.c:odb_write_object
Unexecuted instantiation: path.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: revision.c:odb_write_object
Unexecuted instantiation: sequencer.c:odb_write_object
Unexecuted instantiation: tmp-objdir.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: attr.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: commit-graph.c:odb_write_object
Unexecuted instantiation: connected.c:odb_write_object
Unexecuted instantiation: entry.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-filter.c:odb_write_object
Unexecuted instantiation: match-trees.c:odb_write_object
Unexecuted instantiation: rerere.c:odb_write_object
Unexecuted instantiation: send-pack.c:odb_write_object
Unexecuted instantiation: transport-helper.c:odb_write_object
492
493
struct odb_write_stream {
494
  const void *(*read)(struct odb_write_stream *, unsigned long *len);
495
  void *data;
496
  int is_finished;
497
};
498
499
int odb_write_object_stream(struct object_database *odb,
500
          struct odb_write_stream *stream, size_t len,
501
          struct object_id *oid);
502
503
void parse_alternates(const char *string,
504
          int sep,
505
          const char *relative_base,
506
          struct strvec *out);
507
508
#endif /* ODB_H */