blob: 03f1191659dab55b2c4c440c347101a3cdbd4650 [file] [log] [blame]
Vicent Marti2834bc22013-10-24 14:01:06 -04001#ifndef PACK_OBJECTS_H
2#define PACK_OBJECTS_H
3
4struct object_entry {
5 struct pack_idx_entry idx;
6 unsigned long size; /* uncompressed size */
7 struct packed_git *in_pack; /* already in pack */
8 off_t in_pack_offset;
9 struct object_entry *delta; /* delta base object */
10 struct object_entry *delta_child; /* deltified objects who bases me */
11 struct object_entry *delta_sibling; /* other deltified objects who
12 * uses the same base as me
13 */
14 void *delta_data; /* cached delta (uncompressed) */
15 unsigned long delta_size; /* delta data size (uncompressed) */
16 unsigned long z_delta_size; /* delta data size (compressed) */
17 enum object_type type;
18 enum object_type in_pack_type; /* could be delta */
19 uint32_t hash; /* name hint hash */
Vicent Marti7cc8f972013-12-21 09:00:16 -050020 unsigned int in_pack_pos;
Vicent Marti2834bc22013-10-24 14:01:06 -040021 unsigned char in_pack_header_size;
22 unsigned preferred_base:1; /*
23 * we do not pack this, but is available
24 * to be used as the base object to delta
25 * objects against.
26 */
27 unsigned no_try_delta:1;
28 unsigned tagged:1; /* near the very tip of refs */
29 unsigned filled:1; /* assigned write-order */
Jeff King4cf21432016-08-11 05:26:36 -040030
31 /*
32 * State flags for depth-first search used for analyzing delta cycles.
Jeff King7dbabbb2017-01-27 19:09:59 -050033 *
34 * The depth is measured in delta-links to the base (so if A is a delta
35 * against B, then A has a depth of 1, and B a depth of 0).
Jeff King4cf21432016-08-11 05:26:36 -040036 */
37 enum {
38 DFS_NONE = 0,
39 DFS_ACTIVE,
40 DFS_DONE
41 } dfs_state;
Jeff King7dbabbb2017-01-27 19:09:59 -050042 int depth;
Vicent Marti2834bc22013-10-24 14:01:06 -040043};
44
45struct packing_data {
46 struct object_entry *objects;
47 uint32_t nr_objects, nr_alloc;
48
49 int32_t *index;
50 uint32_t index_size;
51};
52
53struct object_entry *packlist_alloc(struct packing_data *pdata,
54 const unsigned char *sha1,
55 uint32_t index_pos);
56
57struct object_entry *packlist_find(struct packing_data *pdata,
58 const unsigned char *sha1,
59 uint32_t *index_pos);
60
Vicent Marti68fb36e2013-10-24 14:01:29 -040061static inline uint32_t pack_name_hash(const char *name)
62{
63 uint32_t c, hash = 0;
64
65 if (!name)
66 return 0;
67
68 /*
69 * This effectively just creates a sortable number from the
70 * last sixteen non-whitespace characters. Last characters
71 * count "most", so things that end in ".c" sort together.
72 */
73 while ((c = *name++) != 0) {
74 if (isspace(c))
75 continue;
76 hash = (hash >> 2) + (c << 24);
77 }
78 return hash;
79}
80
Vicent Marti2834bc22013-10-24 14:01:06 -040081#endif