Coverage Report

Created: 2026-02-14 06:27

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