|
| 1 | +#ifndef ODB_SOURCE_H |
| 2 | +#define ODB_SOURCE_H |
| 3 | + |
| 4 | +/* |
| 5 | + * The source is the part of the object database that stores the actual |
| 6 | + * objects. It thus encapsulates the logic to read and write the specific |
| 7 | + * on-disk format. An object database can have multiple sources: |
| 8 | + * |
| 9 | + * - The primary source, which is typically located in "$GIT_DIR/objects". |
| 10 | + * This is where new objects are usually written to. |
| 11 | + * |
| 12 | + * - Alternate sources, which are configured via "objects/info/alternates" or |
| 13 | + * via the GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable. These |
| 14 | + * alternate sources are only used to read objects. |
| 15 | + */ |
| 16 | +struct odb_source { |
| 17 | + struct odb_source *next; |
| 18 | + |
| 19 | + /* Object database that owns this object source. */ |
| 20 | + struct object_database *odb; |
| 21 | + |
| 22 | + /* Private state for loose objects. */ |
| 23 | + struct odb_source_loose *loose; |
| 24 | + |
| 25 | + /* Should only be accessed directly by packfile.c and midx.c. */ |
| 26 | + struct packfile_store *packfiles; |
| 27 | + |
| 28 | + /* |
| 29 | + * Figure out whether this is the local source of the owning |
| 30 | + * repository, which would typically be its ".git/objects" directory. |
| 31 | + * This local object directory is usually where objects would be |
| 32 | + * written to. |
| 33 | + */ |
| 34 | + bool local; |
| 35 | + |
| 36 | + /* |
| 37 | + * This object store is ephemeral, so there is no need to fsync. |
| 38 | + */ |
| 39 | + int will_destroy; |
| 40 | + |
| 41 | + /* |
| 42 | + * Path to the source. If this is a relative path, it is relative to |
| 43 | + * the current working directory. |
| 44 | + */ |
| 45 | + char *path; |
| 46 | +}; |
| 47 | + |
| 48 | +/* |
| 49 | + * Allocate and initialize a new source for the given object database located |
| 50 | + * at `path`. `local` indicates whether or not the source is the local and thus |
| 51 | + * primary object source of the object database. |
| 52 | + */ |
| 53 | +struct odb_source *odb_source_new(struct object_database *odb, |
| 54 | + const char *path, |
| 55 | + bool local); |
| 56 | + |
| 57 | +/* Free the object database source, releasing all associated resources. */ |
| 58 | +void odb_source_free(struct odb_source *source); |
| 59 | + |
| 60 | +#endif |
0 commit comments