]> git.ipfire.org Git - thirdparty/git.git/blame - packfile.h
The twentieth batch
[thirdparty/git.git] / packfile.h
CommitLineData
4f39cd82
JT
1#ifndef PACKFILE_H
2#define PACKFILE_H
3
a6dc3d36 4#include "object.h"
498f1f61
JT
5#include "oidset.h"
6
cbd53a21
SB
7/* in object-store.h */
8struct packed_git;
9struct object_info;
cbd53a21 10
0ff73d74
EN
11struct pack_window {
12 struct pack_window *next;
13 unsigned char *base;
14 off_t offset;
15 size_t len;
16 unsigned int last_used;
17 unsigned int inuse_cnt;
18};
19
20struct pack_entry {
21 off_t offset;
22 struct packed_git *p;
23};
24
4f39cd82
JT
25/*
26 * Generate the filename to be used for a pack file with checksum "sha1" and
27 * extension "ext". The result is written into the strbuf "buf", overwriting
28 * any existing contents. A pointer to buf->buf is returned as a convenience.
29 *
30 * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx"
31 */
336226c2 32char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);
4f39cd82
JT
33
34/*
35 * Return the name of the (local) packfile with the specified sha1 in
36 * its name. The return value is a pointer to memory that is
37 * overwritten each time this function is called.
38 */
336226c2 39char *sha1_pack_name(const unsigned char *sha1);
4f39cd82
JT
40
41/*
42 * Return the name of the (local) pack index file with the specified
43 * sha1 in its name. The return value is a pointer to memory that is
44 * overwritten each time this function is called.
45 */
336226c2 46char *sha1_pack_index_name(const unsigned char *sha1);
4f39cd82 47
fc789156
JK
48/*
49 * Return the basename of the packfile, omitting any containing directory
50 * (e.g., "pack-1234abcd[...].pack").
51 */
52const char *pack_basename(struct packed_git *p);
53
336226c2 54struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);
0317f455 55
9208e318 56typedef void each_file_in_pack_dir_fn(const char *full_path, size_t full_path_len,
50f1abcf 57 const char *file_name, void *data);
9208e318
DS
58void for_each_file_in_pack_dir(const char *objdir,
59 each_file_in_pack_dir_fn fn,
60 void *data);
61
0abe14f6
JT
62/* A hook to report invalid files in pack directory */
63#define PACKDIR_FILE_PACK 1
64#define PACKDIR_FILE_IDX 2
65#define PACKDIR_FILE_GARBAGE 4
66extern void (*report_garbage)(unsigned seen_bits, const char *path);
67
336226c2
JK
68void reprepare_packed_git(struct repository *r);
69void install_packed_git(struct repository *r, struct packed_git *pack);
e65f1862 70
a80d72db
SB
71struct packed_git *get_packed_git(struct repository *r);
72struct list_head *get_packed_git_mru(struct repository *r);
8aac67a1 73struct multi_pack_index *get_multi_pack_index(struct repository *r);
59552fb3 74struct multi_pack_index *get_local_multi_pack_index(struct repository *r);
0bff5269 75struct packed_git *get_all_packs(struct repository *r);
a80d72db 76
0abe14f6
JT
77/*
78 * Give a rough count of objects in the repository. This sacrifices accuracy
79 * for speed.
80 */
5038de19 81unsigned long repo_approximate_object_count(struct repository *r);
0abe14f6 82
336226c2
JK
83struct packed_git *find_sha1_pack(const unsigned char *sha1,
84 struct packed_git *packs);
d6fe0036 85
336226c2 86void pack_report(void);
8e21176c 87
0317f455
JT
88/*
89 * mmap the index file for the specified packfile (if it is not
90 * already mmapped). Return 0 on success.
91 */
336226c2 92int open_pack_index(struct packed_git *);
0317f455 93
3836d88a
JT
94/*
95 * munmap the index file for the specified packfile (if it is
96 * currently mmapped).
97 */
336226c2 98void close_pack_index(struct packed_git *);
3836d88a 99
5ae18df9
JH
100int close_pack_fd(struct packed_git *p);
101
336226c2 102uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
fe1ed56f 103
336226c2
JK
104unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
105void close_pack_windows(struct packed_git *);
106void close_pack(struct packed_git *);
5cb7c735 107void close_object_store(struct raw_object_store *o);
336226c2
JK
108void unuse_pack(struct pack_window **);
109void clear_delta_base_cache(void);
110struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
3836d88a 111
8434e85d
DS
112/*
113 * Unlink the .pack and associated extension files.
114 * Does not unlink if 'force_delete' is false and the pack-file is
115 * marked as ".keep".
116 */
415b770b 117void unlink_pack_path(const char *pack_name, int force_delete);
8434e85d 118
9e0f45f5
JT
119/*
120 * Make sure that a pointer access into an mmap'd index file is within bounds,
121 * and can provide at least 8 bytes of data.
122 *
123 * Note that this is only necessary for variable-length segments of the file
124 * (like the 64-bit extended offset table), as we compare the size to the
125 * fixed-length parts when we open the file.
126 */
336226c2 127void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
9e0f45f5 128
3d475f46
DS
129/*
130 * Perform binary search on a pack-index for a given oid. Packfile is expected to
131 * have a valid pack-index.
132 *
133 * See 'bsearch_hash' for more information.
134 */
135int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32_t *result);
136
d5a16761 137/*
2fecc48c
JK
138 * Write the oid of the nth object within the specified packfile into the first
139 * parameter. Open the index if it is not already open. Returns 0 on success,
140 * negative otherwise.
d5a16761 141 */
0763671b 142int nth_packed_object_id(struct object_id *, struct packed_git *, uint32_t n);
d5a16761 143
9e0f45f5
JT
144/*
145 * Return the offset of the nth object within the specified packfile.
146 * The index must already be opened.
147 */
336226c2 148off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);
d5a16761 149
a2551953
JT
150/*
151 * If the object named sha1 is present in the specified packfile,
152 * return its offset within the packfile; otherwise, return 0.
153 */
336226c2 154off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *);
a2551953 155
336226c2
JK
156int is_pack_valid(struct packed_git *);
157void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *);
158unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
159unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
160int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
56d9cbe6
JK
161off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs,
162 off_t *curpos, enum object_type type,
163 off_t delta_obj_offset);
32b42e15 164
336226c2 165void release_pack_memory(size_t);
f0e17e86 166
f1d8130b
JT
167/* global flag to enable extra checks when accessing packed objects */
168extern int do_check_packed_object_crc;
169
336226c2
JK
170int packed_object_info(struct repository *r,
171 struct packed_git *pack,
172 off_t offset, struct object_info *);
f1d8130b 173
751530de 174void mark_bad_packed_object(struct packed_git *, const struct object_id *);
7407d733 175const struct packed_git *has_packed_and_bad(struct repository *, const struct object_id *);
9e0f45f5 176
f62312e0
TB
177#define ON_DISK_KEEP_PACKS 1
178#define IN_CORE_KEEP_PACKS 2
179
613b42f2
SB
180/*
181 * Iff a pack file in the given repository contains the object named by sha1,
182 * return true and store its location to e.
183 */
336226c2 184int find_pack_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e);
f62312e0 185int find_kept_pack_entry(struct repository *r, const struct object_id *oid, unsigned flags, struct pack_entry *e);
1a1e5d4f 186
336226c2 187int has_object_pack(const struct object_id *oid);
f62312e0 188int has_object_kept_pack(const struct object_id *oid, unsigned flags);
150e3001 189
336226c2 190int has_pack_index(const unsigned char *sha1);
f9a8672a 191
498f1f61
JT
192/*
193 * Return 1 if an object in a promisor packfile is or refers to the given
194 * object, 0 otherwise.
195 */
336226c2 196int is_promisor_object(const struct object_id *oid);
498f1f61 197
1127a98c
JS
198/*
199 * Expose a function for fuzz testing.
200 *
201 * load_idx() parses a block of memory as a packfile index and puts the results
202 * into a struct packed_git.
203 *
204 * This function should not be used directly. It is exposed here only so that we
205 * have a convenient entry-point for fuzz testing. For real uses, you should
206 * probably use open_pack_index() or parse_pack_index() instead.
207 */
336226c2
JK
208int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
209 size_t idx_size, struct packed_git *p);
1127a98c 210
4f39cd82 211#endif