Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/builtin/pack-objects.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / builtin / pack-objects.c` 5533 lines ยท 153598 bytes Raw Blame History 1 #define USE_THE_REPOSITORY_VARIABLE 2 #define DISABLE_SIGN_COMPARE_WARNINGS 3 4 #include "builtin.h" 5 #include "environment.h" 6 #include "gettext.h" 7 #include "hex.h" 8 #include "config.h" 9 #include "attr.h" 10 #include "object.h" 11 #include "commit.h" 12 #include "tag.h" 13 #include "delta.h" 14 #include "pack.h" 15 #include "pack-revindex.h" 16 #include "csum-file.h" 17 #include "tree-walk.h" 18 #include "diff.h" 19 #include "revision.h" 20 #include "list-objects.h" 21 #include "list-objects-filter-options.h" 22 #include "pack-objects.h" 23 #include "progress.h" 24 #include "refs.h" 25 #include "thread-utils.h" 26 #include "pack-bitmap.h" 27 #include "delta-islands.h" 28 #include "reachable.h" 29 #include "oid-array.h" 30 #include "strvec.h" 31 #include "strmap.h" 32 #include "list.h" 33 #include "packfile.h" 34 #include "object-file.h" 35 #include "object-file-convert.h" 36 #include "odb.h" 37 #include "odb/streaming.h" 38 #include "replace-object.h" 39 #include "dir.h" 40 #include "midx.h" 41 #include "trace2.h" 42 #include "shallow.h" 43 #include "promisor-remote.h" 44 #include "pack-mtimes.h" 45 #include "parse-options.h" 46 #include "pkt-line.h" 47 #include "blob.h" 48 #include "tree.h" 49 #include "path-walk.h" 50 51 /* 52 * Objects we are going to pack are collected in the `to_pack` structure. 53 * It contains an array (dynamically expanded) of the object data, and a map 54 * that can resolve SHA1s to their position in the array. 55 */ 56 static struct packing_data to_pack; 57 58 static inline struct object_entry *oe_delta( 59 const struct packing_data *pack, 60 const struct object_entry *e) 61 { 62 if (!e->delta_idx) 63 return NULL; 64 if (e->ext_base) 65 return &pack->ext_bases[e->delta_idx - 1]; 66 else 67 return &pack->objects[e->delta_idx - 1]; 68 } 69 70 static inline size_t oe_delta_size(struct packing_data *pack, 71 const struct object_entry *e) 72 { 73 if (e->delta_size_valid) 74 return e->delta_size_; 75 76 /* 77 * pack->delta_size[] can't be NULL because oe_set_delta_size() 78 * must have been called when a new delta is saved with 79 * oe_set_delta(). 80 * If oe_delta() returns NULL (i.e. default state, which means 81 * delta_size_valid is also false), then the caller must never 82 * call oe_delta_size(). 83 */ 84 return pack->delta_size[e - pack->objects]; 85 } 86 87 size_t oe_get_size_slow(struct packing_data *pack, 88 const struct object_entry *e); 89 90 static inline size_t oe_size(struct packing_data *pack, 91 const struct object_entry *e) 92 { 93 if (e->size_valid) 94 return e->size_; 95 96 return oe_get_size_slow(pack, e); 97 } 98 99 static inline void oe_set_delta(struct packing_data *pack, 100 struct object_entry *e, 101 struct object_entry *delta) 102 { 103 if (delta) 104 e->delta_idx = (delta - pack->objects) + 1; 105 else 106 e->delta_idx = 0; 107 } 108 109 static inline struct object_entry *oe_delta_sibling( 110 const struct packing_data *pack, 111 const struct object_entry *e) 112 { 113 if (e->delta_sibling_idx) 114 return &pack->objects[e->delta_sibling_idx - 1]; 115 return NULL; 116 } 117 118 static inline struct object_entry *oe_delta_child( 119 const struct packing_data *pack, 120 const struct object_entry *e) 121 { 122 if (e->delta_child_idx) 123 return &pack->objects[e->delta_child_idx - 1]; 124 return NULL; 125 } 126 127 static inline void oe_set_delta_child(struct packing_data *pack, 128 struct object_entry *e, 129 struct object_entry *delta) 130 { 131 if (delta) 132 e->delta_child_idx = (delta - pack->objects) + 1; 133 else 134 e->delta_child_idx = 0; 135 } 136 137 static inline void oe_set_delta_sibling(struct packing_data *pack, 138 struct object_entry *e, 139 struct object_entry *delta) 140 { 141 if (delta) 142 e->delta_sibling_idx = (delta - pack->objects) + 1; 143 else 144 e->delta_sibling_idx = 0; 145 } 146 147 static inline void oe_set_size(struct packing_data *pack, 148 struct object_entry *e, 149 size_t size) 150 { 151 if (size < pack->oe_size_limit) { 152 e->size_ = size; 153 e->size_valid = 1; 154 } else { 155 e->size_valid = 0; 156 if (oe_get_size_slow(pack, e) != size) 157 BUG("'size' is supposed to be the object size!"); 158 } 159 } 160 161 static inline void oe_set_delta_size(struct packing_data *pack, 162 struct object_entry *e, 163 size_t size) 164 { 165 if (size < pack->oe_delta_size_limit) { 166 e->delta_size_ = size; 167 e->delta_size_valid = 1; 168 } else { 169 packing_data_lock(pack); 170 if (!pack->delta_size) 171 ALLOC_ARRAY(pack->delta_size, pack->nr_alloc); 172 packing_data_unlock(pack); 173 174 pack->delta_size[e - pack->objects] = size; 175 e->delta_size_valid = 0; 176 } 177 } 178 179 #define IN_PACK(obj) oe_in_pack(&to_pack, obj) 180 #define SIZE(obj) oe_size(&to_pack, obj) 181 #define SET_SIZE(obj,size) oe_set_size(&to_pack, obj, size) 182 #define DELTA_SIZE(obj) oe_delta_size(&to_pack, obj) 183 #define DELTA(obj) oe_delta(&to_pack, obj) 184 #define DELTA_CHILD(obj) oe_delta_child(&to_pack, obj) 185 #define DELTA_SIBLING(obj) oe_delta_sibling(&to_pack, obj) 186 #define SET_DELTA(obj, val) oe_set_delta(&to_pack, obj, val) 187 #define SET_DELTA_EXT(obj, oid) oe_set_delta_ext(&to_pack, obj, oid) 188 #define SET_DELTA_SIZE(obj, val) oe_set_delta_size(&to_pack, obj, val) 189 #define SET_DELTA_CHILD(obj, val) oe_set_delta_child(&to_pack, obj, val) 190 #define SET_DELTA_SIBLING(obj, val) oe_set_delta_sibling(&to_pack, obj, val) 191 192 static const char *const pack_usage[] = { 193 N_("git pack-objects [-q | --progress | --all-progress] [--all-progress-implied]\n" 194 " [--no-reuse-delta] [--delta-base-offset] [--non-empty]\n" 195 " [--local] [--incremental] [--window=] [--depth=]\n" 196 " [--revs [--unpacked | --all]] [--keep-pack=]\n" 197 " [--cruft] [--cruft-expiration=