Blob


2 /*
3 * Copyright (c) 2017 Stefan Sperling <stsp@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 /* See Documentation/technical/pack-format.txt in Git. */
20 struct got_pack_obj_id {
21 u_int8_t sha1[SHA1_DIGEST_LENGTH];
22 } __attribute__((__packed__));
24 struct got_pack_idx_trailer {
25 u_int8_t pack_file_sha1[SHA1_DIGEST_LENGTH];
26 u_int8_t pack_idx_sha1[SHA1_DIGEST_LENGTH];
27 } __attribute__((__packed__));
29 /* Ignore pack index version 1 which is no longer written by Git. */
30 #define GOT_PACKIDX_VERSION 2
32 struct got_packidx_v2_hdr {
33 uint32_t magic; /* big endian */
34 #define GOT_PACKIDX_V2_MAGIC 0xff744f63 /* "\377t0c" */
35 uint32_t version;
37 /*
38 * Each entry N in the fanout table contains the number of objects in
39 * the packfile whose SHA1 begins with a byte less than or equal to N.
40 * The last entry (index 255) contains the number of objects in the
41 * pack file whose first SHA1 byte is <= 0xff, and thus records the
42 * total number of objects in the pack file. All pointer variables
43 * below point to tables with a corresponding number of entries.
44 */
45 uint32_t fanout_table[0xff]; /* values are big endian */
47 /* Sorted SHA1 checksums for each object in the pack file. */
48 struct got_pack_obj_id *sorted_ids;
50 /* Offset into the pack file for each object. */
51 uint32_t *offsets; /* values are big endian */
52 #define GOT_PACKIDX_OFFSET_VAL_MASK 0x7fffffff
53 #define GOT_PACKIDX_OFFSET_VAL_IS_LARGE_IDX 0x80000000
55 /* CRC32 of the packed representation of each object. */
56 uint32_t *crc32;
58 /* Large offsets table is empty for pack files < 2 GB. */
59 uint64_t *large_offsets; /* values are big endian */
61 struct got_pack_idx_trailer trailer;
62 };
64 struct got_packfile_hdr {
65 uint32_t signature;
66 #define GOT_PACKFILE_SIGNATURE 0x4041434b /* 'P' 'A' 'C' 'K' */
67 uint32_t version; /* big endian */
68 #define GOT_PACKFILE_VERSION 2
69 uint32_t nobjects; /* big endian */
70 };
72 struct got_packfile_obj_hdr {
73 /*
74 * The object size field uses a variable length encoding:
75 * size0...sizeN form a 4+7+7+...+7 bit integer, where size0 is the
76 * least significant part and sizeN is the most significant part.
77 * If the MSB of a size byte is set, an additional size byte follows.
78 * Of the 7 remaining bits of size0, the first 3 bits indicate the
79 * object's type, and the remaining 4 bits contribute to the size.
80 */
81 uint8_t *size; /* variable length */
82 #define GOT_PACK_OBJ_SIZE_MORE 0x80
83 #define GOT_PACK_OBJ_SIZE0_TYPE_MASK 0x70 /* See struct got_object->type */
84 #define GOT_PACK_OBJ_SIZE0_VAL_MASK 0x0f
85 #define GOT_PACK_OBJ_SIZEN_VAL_MASK 0x7f
86 };
88 /* If object is not a DELTA type. */
89 struct got_packfile_object_data {
90 uint8_t *data; /* compressed */
91 };
93 /* If object is of type GOT_OBJ_TYPE_REF_DELTA. */
94 struct got_packfile_object_data_ref_delta {
95 struct got_pack_obj_id id;
96 uint8_t *delta_data; /* compressed */
97 };
99 /* If object is of type GOT_OBJ_TYPE_OFFSET_DELTA. */
100 struct got_packfile_object_data_offset_delta {
101 /*
102 * This offset is interpreted as a negative offset from
103 * the got_packfile_obj_hdr corresponding to this object.
104 * The size provided in the header specifies the amount
105 * of compressed delta data that follows.
107 * This field uses a variable length encoding of N bytes,
108 * where the MSB is always set except for the last byte.
109 * The value is encoded as a series of N 7 bit integers,
110 * which are concatenated, and if N > 1 the value 2^7 +
111 * 2^14 + ... + 2^(7 * (n-1)) is added to the result.
112 */
113 uint8_t *offset; /* variable length */
114 };
116 struct got_packfile_obj_data {
117 union {
118 struct got_packfile_object_data;
119 struct got_packfile_object_data_ref_delta;
120 struct got_packfile_object_data_offset_delta;
121 } __attribute__((__packed__));
122 } __attribute__((__packed__));