]> git.proxmox.com Git - libgit2.git/blob - src/pack.h
Merge pull request #1091 from carlosmn/stream-object
[libgit2.git] / src / pack.h
1 /*
2 * Copyright (C) 2009-2012 the libgit2 contributors
3 *
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.
6 */
7
8 #ifndef INCLUDE_pack_h__
9 #define INCLUDE_pack_h__
10
11 #include <zlib.h>
12
13 #include "git2/oid.h"
14
15 #include "common.h"
16 #include "map.h"
17 #include "mwindow.h"
18 #include "odb.h"
19
20 #define GIT_PACK_FILE_MODE 0444
21
22 #define PACK_SIGNATURE 0x5041434b /* "PACK" */
23 #define PACK_VERSION 2
24 #define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
25 struct git_pack_header {
26 uint32_t hdr_signature;
27 uint32_t hdr_version;
28 uint32_t hdr_entries;
29 };
30
31 /*
32 * The first four bytes of index formats later than version 1 should
33 * start with this signature, as all older git binaries would find this
34 * value illegal and abort reading the file.
35 *
36 * This is the case because the number of objects in a packfile
37 * cannot exceed 1,431,660,000 as every object would need at least
38 * 3 bytes of data and the overall packfile cannot exceed 4 GiB with
39 * version 1 of the index file due to the offsets limited to 32 bits.
40 * Clearly the signature exceeds this maximum.
41 *
42 * Very old git binaries will also compare the first 4 bytes to the
43 * next 4 bytes in the index and abort with a "non-monotonic index"
44 * error if the second 4 byte word is smaller than the first 4
45 * byte word. This would be true in the proposed future index
46 * format as idx_signature would be greater than idx_version.
47 */
48
49 #define PACK_IDX_SIGNATURE 0xff744f63 /* "\377tOc" */
50
51 struct git_pack_idx_header {
52 uint32_t idx_signature;
53 uint32_t idx_version;
54 };
55
56 struct git_pack_file {
57 git_mwindow_file mwf;
58 git_map index_map;
59
60 uint32_t num_objects;
61 uint32_t num_bad_objects;
62 git_oid *bad_object_sha1; /* array of git_oid */
63
64 int index_version;
65 git_time_t mtime;
66 unsigned pack_local:1, pack_keep:1, has_cache:1;
67 git_oid sha1;
68 git_vector cache;
69 git_oid **oids;
70
71 /* something like ".git/objects/pack/xxxxx.pack" */
72 char pack_name[GIT_FLEX_ARRAY]; /* more */
73 };
74
75 struct git_pack_entry {
76 git_off_t offset;
77 git_oid sha1;
78 struct git_pack_file *p;
79 };
80
81 typedef struct git_packfile_stream {
82 git_off_t curpos;
83 int done;
84 z_stream zstream;
85 struct git_pack_file *p;
86 git_mwindow *mw;
87 } git_packfile_stream;
88
89 int git_packfile_unpack_header(
90 size_t *size_p,
91 git_otype *type_p,
92 git_mwindow_file *mwf,
93 git_mwindow **w_curs,
94 git_off_t *curpos);
95
96 int git_packfile_resolve_header(
97 size_t *size_p,
98 git_otype *type_p,
99 struct git_pack_file *p,
100 git_off_t offset);
101
102 int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, git_off_t *obj_offset);
103 int packfile_unpack_compressed(
104 git_rawobj *obj,
105 struct git_pack_file *p,
106 git_mwindow **w_curs,
107 git_off_t *curpos,
108 size_t size,
109 git_otype type);
110
111 int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, git_off_t curpos);
112 ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len);
113 void git_packfile_stream_free(git_packfile_stream *obj);
114
115 git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
116 git_off_t *curpos, git_otype type,
117 git_off_t delta_obj_offset);
118
119 void packfile_free(struct git_pack_file *p);
120 int git_packfile_check(struct git_pack_file **pack_out, const char *path);
121 int git_pack_entry_find(
122 struct git_pack_entry *e,
123 struct git_pack_file *p,
124 const git_oid *short_oid,
125 size_t len);
126 int git_pack_foreach_entry(
127 struct git_pack_file *p,
128 git_odb_foreach_cb cb,
129 void *data);
130
131 #endif