]>
Commit | Line | Data |
---|---|---|
2834bc27 VM |
1 | #ifndef PACK_OBJECTS_H |
2 | #define PACK_OBJECTS_H | |
3 | ||
8d6ccce1 NTND |
4 | /* |
5 | * basic object info | |
6 | * ----------------- | |
7 | * idx.oid is filled up before delta searching starts. idx.crc32 is | |
8 | * only valid after the object is written out and will be used for | |
9 | * generating the index. idx.offset will be both gradually set and | |
10 | * used in writing phase (base objects get offset first, then deltas | |
11 | * refer to them) | |
12 | * | |
13 | * "size" is the uncompressed object size. Compressed size of the raw | |
14 | * data for an object in a pack is not stored anywhere but is computed | |
15 | * and made available when reverse .idx is made. | |
16 | * | |
17 | * "hash" contains a path name hash which is used for sorting the | |
18 | * delta list and also during delta searching. Once prepare_pack() | |
19 | * returns it's no longer needed. | |
20 | * | |
21 | * source pack info | |
22 | * ---------------- | |
23 | * The (in_pack, in_pack_offset) tuple contains the location of the | |
24 | * object in the source pack. in_pack_header_size allows quickly | |
25 | * skipping the header and going straight to the zlib stream. | |
26 | * | |
27 | * "type" and "in_pack_type" both describe object type. in_pack_type | |
28 | * may contain a delta type, while type is always the canonical type. | |
29 | * | |
30 | * deltas | |
31 | * ------ | |
32 | * Delta links (delta, delta_child and delta_sibling) are created to | |
33 | * reflect that delta graph from the source pack then updated or added | |
34 | * during delta searching phase when we find better deltas. | |
35 | * | |
36 | * delta_child and delta_sibling are last needed in | |
37 | * compute_write_order(). "delta" and "delta_size" must remain valid | |
38 | * at object writing phase in case the delta is not cached. | |
39 | * | |
40 | * If a delta is cached in memory and is compressed, delta_data points | |
41 | * to the data and z_delta_size contains the compressed size. If it's | |
42 | * uncompressed [1], z_delta_size must be zero. delta_size is always | |
43 | * the uncompressed size and must be valid even if the delta is not | |
44 | * cached. | |
45 | * | |
46 | * [1] during try_delta phase we don't bother with compressing because | |
47 | * the delta could be quickly replaced with a better one. | |
48 | */ | |
2834bc27 VM |
49 | struct object_entry { |
50 | struct pack_idx_entry idx; | |
51 | unsigned long size; /* uncompressed size */ | |
52 | struct packed_git *in_pack; /* already in pack */ | |
53 | off_t in_pack_offset; | |
54 | struct object_entry *delta; /* delta base object */ | |
55 | struct object_entry *delta_child; /* deltified objects who bases me */ | |
56 | struct object_entry *delta_sibling; /* other deltified objects who | |
57 | * uses the same base as me | |
58 | */ | |
59 | void *delta_data; /* cached delta (uncompressed) */ | |
60 | unsigned long delta_size; /* delta data size (uncompressed) */ | |
61 | unsigned long z_delta_size; /* delta data size (compressed) */ | |
62 | enum object_type type; | |
63 | enum object_type in_pack_type; /* could be delta */ | |
64 | uint32_t hash; /* name hint hash */ | |
7cc8f971 | 65 | unsigned int in_pack_pos; |
2834bc27 VM |
66 | unsigned char in_pack_header_size; |
67 | unsigned preferred_base:1; /* | |
68 | * we do not pack this, but is available | |
69 | * to be used as the base object to delta | |
70 | * objects against. | |
71 | */ | |
72 | unsigned no_try_delta:1; | |
73 | unsigned tagged:1; /* near the very tip of refs */ | |
74 | unsigned filled:1; /* assigned write-order */ | |
4cf2143e JK |
75 | |
76 | /* | |
77 | * State flags for depth-first search used for analyzing delta cycles. | |
7dbabbbe JK |
78 | * |
79 | * The depth is measured in delta-links to the base (so if A is a delta | |
80 | * against B, then A has a depth of 1, and B a depth of 0). | |
4cf2143e JK |
81 | */ |
82 | enum { | |
83 | DFS_NONE = 0, | |
84 | DFS_ACTIVE, | |
85 | DFS_DONE | |
86 | } dfs_state; | |
7dbabbbe | 87 | int depth; |
2834bc27 VM |
88 | }; |
89 | ||
90 | struct packing_data { | |
91 | struct object_entry *objects; | |
92 | uint32_t nr_objects, nr_alloc; | |
93 | ||
94 | int32_t *index; | |
95 | uint32_t index_size; | |
96 | }; | |
97 | ||
98 | struct object_entry *packlist_alloc(struct packing_data *pdata, | |
99 | const unsigned char *sha1, | |
100 | uint32_t index_pos); | |
101 | ||
102 | struct object_entry *packlist_find(struct packing_data *pdata, | |
103 | const unsigned char *sha1, | |
104 | uint32_t *index_pos); | |
105 | ||
68fb36eb VM |
106 | static inline uint32_t pack_name_hash(const char *name) |
107 | { | |
108 | uint32_t c, hash = 0; | |
109 | ||
110 | if (!name) | |
111 | return 0; | |
112 | ||
113 | /* | |
114 | * This effectively just creates a sortable number from the | |
115 | * last sixteen non-whitespace characters. Last characters | |
116 | * count "most", so things that end in ".c" sort together. | |
117 | */ | |
118 | while ((c = *name++) != 0) { | |
119 | if (isspace(c)) | |
120 | continue; | |
121 | hash = (hash >> 2) + (c << 24); | |
122 | } | |
123 | return hash; | |
124 | } | |
125 | ||
2834bc27 | 126 | #endif |