13 struct hashmap_entry packmap_ent
;
14 struct packed_git
*next
;
16 struct pack_window
*windows
;
18 const void *index_data
;
22 struct oidset bad_objects
;
26 int index
; /* for builtin/pack-objects.c */
27 unsigned pack_local
:1,
35 unsigned char hash
[GIT_MAX_RAWSZ
];
36 struct revindex_entry
*revindex
;
37 const uint32_t *revindex_data
;
38 const uint32_t *revindex_map
;
41 * mtimes_map points at the beginning of the memory mapped region of
42 * this pack's corresponding .mtimes file, and mtimes_size is the size
43 * of that .mtimes file
45 const uint32_t *mtimes_map
;
48 /* repo denotes the repository this packfile belongs to */
49 struct repository
*repo
;
51 /* something like ".git/objects/pack/xxxxx.pack" */
52 char pack_name
[FLEX_ARRAY
]; /* more */
55 static inline int pack_map_entry_cmp(const void *cmp_data UNUSED
,
56 const struct hashmap_entry
*entry
,
57 const struct hashmap_entry
*entry2
,
60 const char *key
= keydata
;
61 const struct packed_git
*pg1
, *pg2
;
63 pg1
= container_of(entry
, const struct packed_git
, packmap_ent
);
64 pg2
= container_of(entry2
, const struct packed_git
, packmap_ent
);
66 return strcmp(pg1
->pack_name
, key
? key
: pg2
->pack_name
);
70 struct pack_window
*next
;
74 unsigned int last_used
;
75 unsigned int inuse_cnt
;
84 * Generate the filename to be used for a pack file with checksum "sha1" and
85 * extension "ext". The result is written into the strbuf "buf", overwriting
86 * any existing contents. A pointer to buf->buf is returned as a convenience.
88 * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx"
90 char *odb_pack_name(struct repository
*r
, struct strbuf
*buf
,
91 const unsigned char *hash
, const char *ext
);
94 * Return the basename of the packfile, omitting any containing directory
95 * (e.g., "pack-1234abcd[...].pack").
97 const char *pack_basename(struct packed_git
*p
);
100 * Parse the pack idx file found at idx_path and create a packed_git struct
101 * which can be used with find_pack_entry_one().
103 * You probably don't want to use this function! It skips most of the normal
104 * sanity checks (including whether we even have the matching .pack file),
105 * and does not add the resulting packed_git struct to the internal list of
106 * packs. You probably want add_packed_git() instead.
108 struct packed_git
*parse_pack_index(struct repository
*r
, unsigned char *sha1
,
109 const char *idx_path
);
111 typedef void each_file_in_pack_dir_fn(const char *full_path
, size_t full_path_len
,
112 const char *file_name
, void *data
);
113 void for_each_file_in_pack_subdir(const char *objdir
,
115 each_file_in_pack_dir_fn fn
,
117 void for_each_file_in_pack_dir(const char *objdir
,
118 each_file_in_pack_dir_fn fn
,
122 * Iterate over all accessible packed objects without respect to reachability.
123 * By default, this includes both local and alternate packs.
125 * Note that some objects may appear twice if they are found in multiple packs.
126 * Each pack is visited in an unspecified order. By default, objects within a
127 * pack are visited in pack-idx order (i.e., sorted by oid).
129 typedef int each_packed_object_fn(const struct object_id
*oid
,
130 struct packed_git
*pack
,
133 int for_each_object_in_pack(struct packed_git
*p
,
134 each_packed_object_fn
, void *data
,
135 enum for_each_object_flags flags
);
136 int for_each_packed_object(struct repository
*repo
, each_packed_object_fn cb
,
137 void *data
, enum for_each_object_flags flags
);
139 /* A hook to report invalid files in pack directory */
140 #define PACKDIR_FILE_PACK 1
141 #define PACKDIR_FILE_IDX 2
142 #define PACKDIR_FILE_GARBAGE 4
143 extern void (*report_garbage
)(unsigned seen_bits
, const char *path
);
145 void reprepare_packed_git(struct repository
*r
);
146 void install_packed_git(struct repository
*r
, struct packed_git
*pack
);
148 struct packed_git
*get_packed_git(struct repository
*r
);
149 struct list_head
*get_packed_git_mru(struct repository
*r
);
150 struct multi_pack_index
*get_multi_pack_index(struct repository
*r
);
151 struct multi_pack_index
*get_local_multi_pack_index(struct repository
*r
);
152 struct packed_git
*get_all_packs(struct repository
*r
);
155 * Give a rough count of objects in the repository. This sacrifices accuracy
158 unsigned long repo_approximate_object_count(struct repository
*r
);
161 * Find the pack within the "packs" list whose index contains the object "oid".
162 * For general object lookups, you probably don't want this; use
163 * find_pack_entry() instead.
165 struct packed_git
*find_oid_pack(const struct object_id
*oid
,
166 struct packed_git
*packs
);
168 void pack_report(struct repository
*repo
);
171 * mmap the index file for the specified packfile (if it is not
172 * already mmapped). Return 0 on success.
174 int open_pack_index(struct packed_git
*);
177 * munmap the index file for the specified packfile (if it is
178 * currently mmapped).
180 void close_pack_index(struct packed_git
*);
182 int close_pack_fd(struct packed_git
*p
);
184 uint32_t get_pack_fanout(struct packed_git
*p
, uint32_t value
);
186 struct object_database
;
188 unsigned char *use_pack(struct packed_git
*, struct pack_window
**, off_t
, unsigned long *);
189 void close_pack_windows(struct packed_git
*);
190 void close_pack(struct packed_git
*);
191 void close_object_store(struct object_database
*o
);
192 void unuse_pack(struct pack_window
**);
193 void clear_delta_base_cache(void);
194 struct packed_git
*add_packed_git(struct repository
*r
, const char *path
,
195 size_t path_len
, int local
);
198 * Unlink the .pack and associated extension files.
199 * Does not unlink if 'force_delete' is false and the pack-file is
202 void unlink_pack_path(const char *pack_name
, int force_delete
);
205 * Make sure that a pointer access into an mmap'd index file is within bounds,
206 * and can provide at least 8 bytes of data.
208 * Note that this is only necessary for variable-length segments of the file
209 * (like the 64-bit extended offset table), as we compare the size to the
210 * fixed-length parts when we open the file.
212 void check_pack_index_ptr(const struct packed_git
*p
, const void *ptr
);
215 * Perform binary search on a pack-index for a given oid. Packfile is expected to
216 * have a valid pack-index.
218 * See 'bsearch_hash' for more information.
220 int bsearch_pack(const struct object_id
*oid
, const struct packed_git
*p
, uint32_t *result
);
223 * Write the oid of the nth object within the specified packfile into the first
224 * parameter. Open the index if it is not already open. Returns 0 on success,
225 * negative otherwise.
227 int nth_packed_object_id(struct object_id
*, struct packed_git
*, uint32_t n
);
230 * Return the offset of the nth object within the specified packfile.
231 * The index must already be opened.
233 off_t
nth_packed_object_offset(const struct packed_git
*, uint32_t n
);
236 * If the object named by oid is present in the specified packfile,
237 * return its offset within the packfile; otherwise, return 0.
239 off_t
find_pack_entry_one(const struct object_id
*oid
, struct packed_git
*);
241 int is_pack_valid(struct packed_git
*);
242 void *unpack_entry(struct repository
*r
, struct packed_git
*, off_t
, enum object_type
*, unsigned long *);
243 unsigned long unpack_object_header_buffer(const unsigned char *buf
, unsigned long len
, enum object_type
*type
, unsigned long *sizep
);
244 unsigned long get_size_from_delta(struct packed_git
*, struct pack_window
**, off_t
);
245 int unpack_object_header(struct packed_git
*, struct pack_window
**, off_t
*, unsigned long *);
246 off_t
get_delta_base(struct packed_git
*p
, struct pack_window
**w_curs
,
247 off_t
*curpos
, enum object_type type
,
248 off_t delta_obj_offset
);
250 void release_pack_memory(size_t);
252 /* global flag to enable extra checks when accessing packed objects */
253 extern int do_check_packed_object_crc
;
255 int packed_object_info(struct repository
*r
,
256 struct packed_git
*pack
,
257 off_t offset
, struct object_info
*);
259 void mark_bad_packed_object(struct packed_git
*, const struct object_id
*);
260 const struct packed_git
*has_packed_and_bad(struct repository
*, const struct object_id
*);
262 #define ON_DISK_KEEP_PACKS 1
263 #define IN_CORE_KEEP_PACKS 2
266 * Iff a pack file in the given repository contains the object named by sha1,
267 * return true and store its location to e.
269 int find_pack_entry(struct repository
*r
, const struct object_id
*oid
, struct pack_entry
*e
);
270 int find_kept_pack_entry(struct repository
*r
, const struct object_id
*oid
, unsigned flags
, struct pack_entry
*e
);
272 int has_object_pack(struct repository
*r
, const struct object_id
*oid
);
273 int has_object_kept_pack(struct repository
*r
, const struct object_id
*oid
,
276 struct packed_git
**kept_pack_cache(struct repository
*r
, unsigned flags
);
279 * Return 1 if an object in a promisor packfile is or refers to the given
280 * object, 0 otherwise.
282 int is_promisor_object(struct repository
*r
, const struct object_id
*oid
);
285 * Expose a function for fuzz testing.
287 * load_idx() parses a block of memory as a packfile index and puts the results
288 * into a struct packed_git.
290 * This function should not be used directly. It is exposed here only so that we
291 * have a convenient entry-point for fuzz testing. For real uses, you should
292 * probably use open_pack_index() instead.
294 int load_idx(const char *path
, const unsigned int hashsz
, void *idx_map
,
295 size_t idx_size
, struct packed_git
*p
);
298 * Parse a --pack_header option as accepted by index-pack and unpack-objects,
299 * turning it into the matching bytes we'd find in a pack.
301 int parse_pack_header_option(const char *in
, unsigned char *out
, unsigned int *len
);