]>
Commit | Line | Data |
---|---|---|
c7c9e183 | 1 | /* |
5e0de328 | 2 | * Copyright (C) 2009-2012 the libgit2 contributors |
c7c9e183 | 3 | * |
bb742ede VM |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
c7c9e183 CMN |
6 | */ |
7 | ||
8 | #ifndef INCLUDE_pack_h__ | |
9 | #define INCLUDE_pack_h__ | |
10 | ||
11 | #include "git2/oid.h" | |
12 | ||
13 | #include "common.h" | |
14 | #include "map.h" | |
15 | #include "mwindow.h" | |
7d0cdf82 | 16 | #include "odb.h" |
c7c9e183 | 17 | |
01ad7b3a BR |
18 | #define GIT_PACK_FILE_MODE 0444 |
19 | ||
c7c9e183 CMN |
20 | #define PACK_SIGNATURE 0x5041434b /* "PACK" */ |
21 | #define PACK_VERSION 2 | |
22 | #define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3)) | |
a070f152 | 23 | struct git_pack_header { |
c7c9e183 CMN |
24 | uint32_t hdr_signature; |
25 | uint32_t hdr_version; | |
26 | uint32_t hdr_entries; | |
27 | }; | |
28 | ||
29 | /* | |
30 | * The first four bytes of index formats later than version 1 should | |
31 | * start with this signature, as all older git binaries would find this | |
32 | * value illegal and abort reading the file. | |
33 | * | |
34 | * This is the case because the number of objects in a packfile | |
35 | * cannot exceed 1,431,660,000 as every object would need at least | |
36 | * 3 bytes of data and the overall packfile cannot exceed 4 GiB with | |
37 | * version 1 of the index file due to the offsets limited to 32 bits. | |
38 | * Clearly the signature exceeds this maximum. | |
39 | * | |
40 | * Very old git binaries will also compare the first 4 bytes to the | |
41 | * next 4 bytes in the index and abort with a "non-monotonic index" | |
42 | * error if the second 4 byte word is smaller than the first 4 | |
87d9869f | 43 | * byte word. This would be true in the proposed future index |
c7c9e183 CMN |
44 | * format as idx_signature would be greater than idx_version. |
45 | */ | |
46 | ||
47 | #define PACK_IDX_SIGNATURE 0xff744f63 /* "\377tOc" */ | |
48 | ||
a070f152 | 49 | struct git_pack_idx_header { |
c7c9e183 CMN |
50 | uint32_t idx_signature; |
51 | uint32_t idx_version; | |
52 | }; | |
53 | ||
a070f152 | 54 | struct git_pack_file { |
c7c9e183 | 55 | git_mwindow_file mwf; |
c7c9e183 CMN |
56 | git_map index_map; |
57 | ||
58 | uint32_t num_objects; | |
59 | uint32_t num_bad_objects; | |
60 | git_oid *bad_object_sha1; /* array of git_oid */ | |
61 | ||
62 | int index_version; | |
63 | git_time_t mtime; | |
c1af5a39 | 64 | unsigned pack_local:1, pack_keep:1, has_cache:1; |
c7c9e183 | 65 | git_oid sha1; |
c1af5a39 | 66 | git_vector cache; |
60ecdf59 | 67 | git_oid **oids; |
c7c9e183 CMN |
68 | |
69 | /* something like ".git/objects/pack/xxxxx.pack" */ | |
70 | char pack_name[GIT_FLEX_ARRAY]; /* more */ | |
71 | }; | |
72 | ||
a070f152 | 73 | struct git_pack_entry { |
e1de726c | 74 | git_off_t offset; |
c7c9e183 | 75 | git_oid sha1; |
a070f152 | 76 | struct git_pack_file *p; |
c7c9e183 CMN |
77 | }; |
78 | ||
7d0cdf82 CMN |
79 | int git_packfile_unpack_header( |
80 | size_t *size_p, | |
81 | git_otype *type_p, | |
82 | git_mwindow_file *mwf, | |
83 | git_mwindow **w_curs, | |
e1de726c | 84 | git_off_t *curpos); |
7d0cdf82 | 85 | |
e1de726c | 86 | int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, git_off_t *obj_offset); |
fa679339 CMN |
87 | int packfile_unpack_compressed( |
88 | git_rawobj *obj, | |
89 | struct git_pack_file *p, | |
90 | git_mwindow **w_curs, | |
91 | git_off_t *curpos, | |
92 | size_t size, | |
93 | git_otype type); | |
7d0cdf82 | 94 | |
e1de726c RB |
95 | git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs, |
96 | git_off_t *curpos, git_otype type, | |
97 | git_off_t delta_obj_offset); | |
7d0cdf82 | 98 | |
a070f152 CMN |
99 | void packfile_free(struct git_pack_file *p); |
100 | int git_packfile_check(struct git_pack_file **pack_out, const char *path); | |
101 | int git_pack_entry_find( | |
102 | struct git_pack_entry *e, | |
103 | struct git_pack_file *p, | |
104 | const git_oid *short_oid, | |
b8457baa | 105 | size_t len); |
521aedad CMN |
106 | int git_pack_foreach_entry( |
107 | struct git_pack_file *p, | |
108 | int (*cb)(git_oid *oid, void *data), | |
109 | void *data); | |
a070f152 | 110 | |
c7c9e183 | 111 | #endif |