6 struct alternate_object_database
{
7 struct alternate_object_database
*next
;
9 /* see alt_scratch_buf() */
10 struct strbuf scratch
;
14 * Used to store the results of readdir(3) calls when searching
15 * for unique abbreviated hashes. This cache is never
16 * invalidated, thus it's racy and not necessarily accurate.
17 * That's fine for its purpose; don't use it for tasks requiring
20 char loose_objects_subdir_seen
[256];
21 struct oid_array loose_objects_cache
;
24 * Path to the alternative object store. If this is a relative path,
25 * it is relative to the current working directory.
27 char path
[FLEX_ARRAY
];
29 void prepare_alt_odb(struct repository
*r
);
30 char *compute_alternate_path(const char *path
, struct strbuf
*err
);
31 typedef int alt_odb_fn(struct alternate_object_database
*, void *);
32 int foreach_alt_odb(alt_odb_fn
, void*);
35 * Allocate a "struct alternate_object_database" but do _not_ actually
36 * add it to the list of alternates.
38 struct alternate_object_database
*alloc_alt_odb(const char *dir
);
41 * Add the directory to the on-disk alternates file; the new entry will also
42 * take effect in the current process.
44 void add_to_alternates_file(const char *dir
);
47 * Add the directory to the in-memory list of alternates (along with any
48 * recursive alternates it points to), but do not modify the on-disk alternates
51 void add_to_alternates_memory(const char *dir
);
54 * Returns a scratch strbuf pre-filled with the alternate object directory,
55 * including a trailing slash, which can be used to access paths in the
56 * alternate. Always use this over direct access to alt->scratch, as it
57 * cleans up any previous use of the scratch buffer.
59 struct strbuf
*alt_scratch_buf(struct alternate_object_database
*alt
);
62 struct packed_git
*next
;
64 struct pack_window
*windows
;
66 const void *index_data
;
69 uint32_t num_bad_objects
;
70 unsigned char *bad_object_sha1
;
74 int index
; /* for builtin/pack-objects.c */
75 unsigned pack_local
:1,
81 unsigned char sha1
[20];
82 struct revindex_entry
*revindex
;
83 /* something like ".git/objects/pack/xxxxx.pack" */
84 char pack_name
[FLEX_ARRAY
]; /* more */
87 struct raw_object_store
{
89 * Path to the repository's object store.
90 * Cannot be NULL after initialization.
94 /* Path to extra alternate object database if not NULL */
97 struct alternate_object_database
*alt_odb_list
;
98 struct alternate_object_database
**alt_odb_tail
;
101 * Objects that should be substituted by other objects
102 * (see git-replace(1)).
104 struct oidmap
*replace_map
;
109 * should only be accessed directly by packfile.c
112 struct packed_git
*packed_git
;
113 /* A most-recently-used ordered version of the packed_git list. */
114 struct list_head packed_git_mru
;
117 * A fast, rough count of the number of objects in the repository.
118 * These two fields are not meant for direct access. Use
119 * approximate_object_count() instead.
121 unsigned long approximate_object_count
;
122 unsigned approximate_object_count_valid
: 1;
125 * Whether packed_git has already been populated with this repository's
128 unsigned packed_git_initialized
: 1;
131 struct raw_object_store
*raw_object_store_new(void);
132 void raw_object_store_clear(struct raw_object_store
*o
);
135 * Put in `buf` the name of the file in the local object database that
136 * would be used to store a loose object with the specified sha1.
138 void sha1_file_name(struct repository
*r
, struct strbuf
*buf
, const unsigned char *sha1
);
140 void *map_sha1_file(struct repository
*r
, const unsigned char *sha1
, unsigned long *size
);
142 extern void *read_object_file_extended(const struct object_id
*oid
,
143 enum object_type
*type
,
144 unsigned long *size
, int lookup_replace
);
145 static inline void *read_object_file(const struct object_id
*oid
, enum object_type
*type
, unsigned long *size
)
147 return read_object_file_extended(oid
, type
, size
, 1);
150 /* Read and unpack an object file into memory, write memory to an object file */
151 int oid_object_info(struct repository
*r
, const struct object_id
*, unsigned long *);
153 extern int hash_object_file(const void *buf
, unsigned long len
,
154 const char *type
, struct object_id
*oid
);
156 extern int write_object_file(const void *buf
, unsigned long len
,
157 const char *type
, struct object_id
*oid
);
159 extern int hash_object_file_literally(const void *buf
, unsigned long len
,
160 const char *type
, struct object_id
*oid
,
163 extern int pretend_object_file(void *, unsigned long, enum object_type
,
164 struct object_id
*oid
);
166 extern int force_object_loose(const struct object_id
*oid
, time_t mtime
);
169 * Open the loose object at path, check its hash, and return the contents,
170 * type, and size. If the object is a blob, then "contents" may return NULL,
171 * to allow streaming of large blobs.
173 * Returns 0 on success, negative on error (details may be written to stderr).
175 int read_loose_object(const char *path
,
176 const struct object_id
*expected_oid
,
177 enum object_type
*type
,
182 * Convenience for sha1_object_info_extended() with a NULL struct
183 * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
184 * nonzero flags to also set other flags.
186 extern int has_sha1_file_with_flags(const unsigned char *sha1
, int flags
);
187 static inline int has_sha1_file(const unsigned char *sha1
)
189 return has_sha1_file_with_flags(sha1
, 0);
192 /* Same as the above, except for struct object_id. */
193 extern int has_object_file(const struct object_id
*oid
);
194 extern int has_object_file_with_flags(const struct object_id
*oid
, int flags
);
197 * Return true iff an alternate object database has a loose object
198 * with the specified name. This function does not respect replace
201 extern int has_loose_object_nonlocal(const struct object_id
*);
203 extern void assert_oid_type(const struct object_id
*oid
, enum object_type expect
);
207 enum object_type
*typep
;
208 unsigned long *sizep
;
210 unsigned char *delta_base_sha1
;
211 struct strbuf
*type_name
;
224 * ... Nothing to expose in this case
227 * ... Nothing to expose in this case
231 struct packed_git
*pack
;
233 unsigned int is_delta
;
239 * Initializer for a "struct object_info" that wants no items. You may
240 * also memset() the memory to all-zeroes.
242 #define OBJECT_INFO_INIT {NULL}
244 /* Invoke lookup_replace_object() on the given hash */
245 #define OBJECT_INFO_LOOKUP_REPLACE 1
246 /* Allow reading from a loose object file of unknown/bogus type */
247 #define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
248 /* Do not check cached storage */
249 #define OBJECT_INFO_SKIP_CACHED 4
250 /* Do not retry packed storage after checking packed and loose storage */
251 #define OBJECT_INFO_QUICK 8
252 /* Do not check loose object */
253 #define OBJECT_INFO_IGNORE_LOOSE 16
255 int oid_object_info_extended(struct repository
*r
,
256 const struct object_id
*,
257 struct object_info
*, unsigned flags
);
259 #endif /* OBJECT_STORE_H */