#define USE_THE_REPOSITORY_VARIABLE #define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "environment.h" #include "gettext.h" #include "hex.h" #include "config.h" #include "attr.h" #include "object.h" #include "commit.h" #include "tag.h" #include "delta.h" #include "pack.h" #include "pack-revindex.h" #include "csum-file.h" #include "tree-walk.h" #include "diff.h" #include "revision.h" #include "list-objects.h" #include "list-objects-filter-options.h" #include "pack-objects.h" #include "progress.h" #include "refs.h" #include "streaming.h" #include "thread-utils.h" #include "pack-bitmap.h" #include "delta-islands.h" #include "reachable.h" #include "oid-array.h" #include "strvec.h" #include "list.h" #include "packfile.h" #include "object-file.h" #include "odb.h" #include "replace-object.h" #include "dir.h" #include "midx.h" #include "trace2.h" #include "shallow.h" #include "promisor-remote.h" #include "pack-mtimes.h" #include "parse-options.h" #include "blob.h" #include "tree.h" #include "path-walk.h" #include "trace2.h" /* * Objects we are going to pack are collected in the `to_pack` structure. * It contains an array (dynamically expanded) of the object data, and a map * that can resolve SHA1s to their position in the array. */ static struct packing_data to_pack; static inline struct object_entry *oe_delta( const struct packing_data *pack, const struct object_entry *e) { if (!e->delta_idx) return NULL; if (e->ext_base) return &pack->ext_bases[e->delta_idx - 1]; else return &pack->objects[e->delta_idx - 1]; } static inline unsigned long oe_delta_size(struct packing_data *pack, const struct object_entry *e) { if (e->delta_size_valid) return e->delta_size_; /* * pack->delta_size[] can't be NULL because oe_set_delta_size() * must have been called when a new delta is saved with * oe_set_delta(). * If oe_delta() returns NULL (i.e. default state, which means * delta_size_valid is also false), then the caller must never * call oe_delta_size(). */ return pack->delta_size[e - pack->objects]; } unsigned long oe_get_size_slow(struct packing_data *pack, const struct object_entry *e); static inline unsigned long oe_size(struct packing_data *pack, const struct object_entry *e) { if (e->size_valid) return e->size_; return oe_get_size_slow(pack, e); } static inline void oe_set_delta(struct packing_data *pack, struct object_entry *e, struct object_entry *delta) { if (delta) e->delta_idx = (delta - pack->objects) + 1; else e->delta_idx = 0; } static inline struct object_entry *oe_delta_sibling( const struct packing_data *pack, const struct object_entry *e) { if (e->delta_sibling_idx) return &pack->objects[e->delta_sibling_idx - 1]; return NULL; } static inline struct object_entry *oe_delta_child( const struct packing_data *pack, const struct object_entry *e) { if (e->delta_child_idx) return &pack->objects[e->delta_child_idx - 1]; return NULL; } static inline void oe_set_delta_child(struct packing_data *pack, struct object_entry *e, struct object_entry *delta) { if (delta) e->delta_child_idx = (delta - pack->objects) + 1; else e->delta_child_idx = 0; } static inline void oe_set_delta_sibling(struct packing_data *pack, struct object_entry *e, struct object_entry *delta) { if (delta) e->delta_sibling_idx = (delta - pack->objects) + 1; else e->delta_sibling_idx = 0; } static inline void oe_set_size(struct packing_data *pack, struct object_entry *e, unsigned long size) { if (size < pack->oe_size_limit) { e->size_ = size; e->size_valid = 1; } else { e->size_valid = 0; if (oe_get_size_slow(pack, e) != size) BUG("'size' is supposed to be the object size!"); } } static inline void oe_set_delta_size(struct packing_data *pack, struct object_entry *e, unsigned long size) { if (size < pack->oe_delta_size_limit) { e->delta_size_ = size; e->delta_size_valid = 1; } else { packing_data_lock(pack); if (!pack->delta_size) ALLOC_ARRAY(pack->delta_size, pack->nr_alloc); packing_data_unlock(pack); pack->delta_size[e - pack->objects] = size; e->delta_size_valid = 0; } } #define IN_PACK(obj) oe_in_pack(&to_pack, obj) #define SIZE(obj) oe_size(&to_pack, obj) #define SET_SIZE(obj,size) oe_set_size(&to_pack, obj, size) #define DELTA_SIZE(obj) oe_delta_size(&to_pack, obj) #define DELTA(obj) oe_delta(&to_pack, obj) #define DELTA_CHILD(obj) oe_delta_child(&to_pack, obj) #define DELTA_SIBLING(obj) oe_delta_sibling(&to_pack, obj) #define SET_DELTA(obj, val) oe_set_delta(&to_pack, obj, val) #define SET_DELTA_EXT(obj, oid) oe_set_delta_ext(&to_pack, obj, oid) #define SET_DELTA_SIZE(obj, val) oe_set_delta_size(&to_pack, obj, val) #define SET_DELTA_CHILD(obj, val) oe_set_delta_child(&to_pack, obj, val) #define SET_DELTA_SIBLING(obj, val) oe_set_delta_sibling(&to_pack, obj, val) static const char *const pack_usage[] = { N_("git pack-objects [-q | --progress | --all-progress] [--all-progress-implied]\n" " [--no-reuse-delta] [--delta-base-offset] [--non-empty]\n" " [--local] [--incremental] [--window=] [--depth=]\n" " [--revs [--unpacked | --all]] [--keep-pack=]\n" " [--cruft] [--cruft-expiration=