2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
8 #ifndef INCLUDE_pack_h__
9 #define INCLUDE_pack_h__
22 #define GIT_PACK_FILE_MODE 0444
24 #define PACK_SIGNATURE 0x5041434b /* "PACK" */
25 #define PACK_VERSION 2
26 #define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
27 struct git_pack_header
{
28 uint32_t hdr_signature
;
34 * The first four bytes of index formats later than version 1 should
35 * start with this signature, as all older git binaries would find this
36 * value illegal and abort reading the file.
38 * This is the case because the number of objects in a packfile
39 * cannot exceed 1,431,660,000 as every object would need at least
40 * 3 bytes of data and the overall packfile cannot exceed 4 GiB with
41 * version 1 of the index file due to the offsets limited to 32 bits.
42 * Clearly the signature exceeds this maximum.
44 * Very old git binaries will also compare the first 4 bytes to the
45 * next 4 bytes in the index and abort with a "non-monotonic index"
46 * error if the second 4 byte word is smaller than the first 4
47 * byte word. This would be true in the proposed future index
48 * format as idx_signature would be greater than idx_version.
51 #define PACK_IDX_SIGNATURE 0xff744f63 /* "\377tOc" */
53 struct git_pack_idx_header
{
54 uint32_t idx_signature
;
58 typedef struct git_pack_cache_entry
{
59 size_t last_usage
; /* enough? */
62 } git_pack_cache_entry
;
64 struct pack_chain_elem
{
71 typedef git_array_t(struct pack_chain_elem
) git_dependency_chain
;
76 #define GIT_PACK_CACHE_MEMORY_LIMIT 16 * 1024 * 1024
77 #define GIT_PACK_CACHE_SIZE_LIMIT 1024 * 1024 /* don't bother caching anything over 1MB */
87 struct git_pack_file
{
90 git_mutex lock
; /* protect updates to mwf and index_map */
94 uint32_t num_bad_objects
;
95 git_oid
*bad_object_sha1
; /* array of git_oid */
99 unsigned pack_local
:1, pack_keep
:1, has_cache
:1;
100 git_oidmap
*idx_cache
;
103 git_pack_cache bases
; /* delta base cache */
105 /* something like ".git/objects/pack/xxxxx.pack" */
106 char pack_name
[GIT_FLEX_ARRAY
]; /* more */
109 struct git_pack_entry
{
112 struct git_pack_file
*p
;
115 typedef struct git_packfile_stream
{
119 struct git_pack_file
*p
;
121 } git_packfile_stream
;
123 size_t git_packfile__object_header(unsigned char *hdr
, size_t size
, git_otype type
);
125 int git_packfile__name(char **out
, const char *path
);
127 int git_packfile_unpack_header(
130 git_mwindow_file
*mwf
,
131 git_mwindow
**w_curs
,
134 int git_packfile_resolve_header(
137 struct git_pack_file
*p
,
140 int git_packfile_unpack(git_rawobj
*obj
, struct git_pack_file
*p
, git_off_t
*obj_offset
);
141 int packfile_unpack_compressed(
143 struct git_pack_file
*p
,
144 git_mwindow
**w_curs
,
149 int git_packfile_stream_open(git_packfile_stream
*obj
, struct git_pack_file
*p
, git_off_t curpos
);
150 ssize_t
git_packfile_stream_read(git_packfile_stream
*obj
, void *buffer
, size_t len
);
151 void git_packfile_stream_free(git_packfile_stream
*obj
);
153 git_off_t
get_delta_base(struct git_pack_file
*p
, git_mwindow
**w_curs
,
154 git_off_t
*curpos
, git_otype type
,
155 git_off_t delta_obj_offset
);
157 void git_packfile_free(struct git_pack_file
*p
);
158 int git_packfile_alloc(struct git_pack_file
**pack_out
, const char *path
);
160 int git_pack_entry_find(
161 struct git_pack_entry
*e
,
162 struct git_pack_file
*p
,
163 const git_oid
*short_oid
,
165 int git_pack_foreach_entry(
166 struct git_pack_file
*p
,
167 git_odb_foreach_cb cb
,