]> git.proxmox.com Git - libgit2.git/blob - src/pack.h
Merge branch 'cmn/zlib-128' into cmn/zlib-update
[libgit2.git] / src / pack.h
1 /*
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
5 *
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
14 *
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25
26 #ifndef INCLUDE_pack_h__
27 #define INCLUDE_pack_h__
28
29 #include "git2/oid.h"
30
31 #include "common.h"
32 #include "map.h"
33 #include "mwindow.h"
34 #include "odb.h"
35
36 #define PACK_SIGNATURE 0x5041434b /* "PACK" */
37 #define PACK_VERSION 2
38 #define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
39 struct git_pack_header {
40 uint32_t hdr_signature;
41 uint32_t hdr_version;
42 uint32_t hdr_entries;
43 };
44
45 /*
46 * The first four bytes of index formats later than version 1 should
47 * start with this signature, as all older git binaries would find this
48 * value illegal and abort reading the file.
49 *
50 * This is the case because the number of objects in a packfile
51 * cannot exceed 1,431,660,000 as every object would need at least
52 * 3 bytes of data and the overall packfile cannot exceed 4 GiB with
53 * version 1 of the index file due to the offsets limited to 32 bits.
54 * Clearly the signature exceeds this maximum.
55 *
56 * Very old git binaries will also compare the first 4 bytes to the
57 * next 4 bytes in the index and abort with a "non-monotonic index"
58 * error if the second 4 byte word is smaller than the first 4
59 * byte word. This would be true in the proposed future index
60 * format as idx_signature would be greater than idx_version.
61 */
62
63 #define PACK_IDX_SIGNATURE 0xff744f63 /* "\377tOc" */
64
65 struct git_pack_idx_header {
66 uint32_t idx_signature;
67 uint32_t idx_version;
68 };
69
70 struct git_pack_file {
71 git_mwindow_file mwf;
72 git_map index_map;
73
74 uint32_t num_objects;
75 uint32_t num_bad_objects;
76 git_oid *bad_object_sha1; /* array of git_oid */
77
78 int index_version;
79 git_time_t mtime;
80 unsigned pack_local:1, pack_keep:1;
81 git_oid sha1;
82
83 /* something like ".git/objects/pack/xxxxx.pack" */
84 char pack_name[GIT_FLEX_ARRAY]; /* more */
85 };
86
87 struct git_pack_entry {
88 off_t offset;
89 git_oid sha1;
90 struct git_pack_file *p;
91 };
92
93 int git_packfile_unpack_header(
94 size_t *size_p,
95 git_otype *type_p,
96 git_mwindow_file *mwf,
97 git_mwindow **w_curs,
98 off_t *curpos);
99
100 int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, off_t *obj_offset);
101
102 off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
103 off_t *curpos, git_otype type,
104 off_t delta_obj_offset);
105
106 void packfile_free(struct git_pack_file *p);
107 int git_packfile_check(struct git_pack_file **pack_out, const char *path);
108 int git_pack_entry_find(
109 struct git_pack_entry *e,
110 struct git_pack_file *p,
111 const git_oid *short_oid,
112 unsigned int len);
113
114 #endif