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