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