git/builtin/index-pack.c

#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "config.h"
#include "delta.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "pack.h"
#include "csum-file.h"
#include "blob.h"
#include "commit.h"
#include "tree.h"
#include "progress.h"
#include "fsck.h"
#include "strbuf.h"
#include "streaming.h"
#include "thread-utils.h"
#include "packfile.h"
#include "pack-revindex.h"
#include "object-file.h"
#include "object-store-ll.h"
#include "oid-array.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "setup.h"

static const char index_pack_usage[] =;

struct object_entry {};

struct object_stat {};

struct base_data {};

/*
 * Stack of struct base_data that have unprocessed children.
 * threaded_second_pass() uses this as a source of work (the other being the
 * objects array).
 *
 * Guarded by work_mutex.
 */
static LIST_HEAD(work_head);

/*
 * Stack of struct base_data that have children, all of whom have been
 * processed or are being processed, and at least one child is being processed.
 * These struct base_data must be kept around until the last child is
 * processed.
 *
 * Guarded by work_mutex.
 */
static LIST_HEAD(done_head);

/*
 * All threads share one delta base cache.
 *
 * base_cache_used is guarded by work_mutex, and base_cache_limit is read-only
 * in a thread.
 */
static size_t base_cache_used;
static size_t base_cache_limit;

struct thread_local {};

/* Remember to update object flag allocation in object.h */
#define FLAG_LINK
#define FLAG_CHECKED

struct ofs_delta_entry {};

struct ref_delta_entry {};

static struct object_entry *objects;
static struct object_stat *obj_stat;
static struct ofs_delta_entry *ofs_deltas;
static struct ref_delta_entry *ref_deltas;
static struct thread_local nothread_data;
static int nr_objects;
static int nr_ofs_deltas;
static int nr_ref_deltas;
static int ref_deltas_alloc;
static int nr_resolved_deltas;
static int nr_threads;

static int from_stdin;
static int strict;
static int do_fsck_object;
static struct fsck_options fsck_options =;
static int verbose;
static const char *progress_title;
static int show_resolving_progress;
static int show_stat;
static int check_self_contained_and_connected;

static struct progress *progress;

/* We always read in 4kB chunks. */
static unsigned char input_buffer[4096];
static unsigned int input_offset, input_len;
static off_t consumed_bytes;
static off_t max_input_size;
static unsigned deepest_delta;
static git_hash_ctx input_ctx;
static uint32_t input_crc32;
static int input_fd, output_fd;
static const char *curr_pack;

static struct thread_local *thread_data;
static int nr_dispatched;
static int threads_active;

static pthread_mutex_t read_mutex;
#define read_lock()
#define read_unlock()

static pthread_mutex_t counter_mutex;
#define counter_lock()
#define counter_unlock()

static pthread_mutex_t work_mutex;
#define work_lock()
#define work_unlock()

static pthread_mutex_t deepest_delta_mutex;
#define deepest_delta_lock()
#define deepest_delta_unlock()

static pthread_key_t key;

static inline void lock_mutex(pthread_mutex_t *mutex)
{}

static inline void unlock_mutex(pthread_mutex_t *mutex)
{}

/*
 * Mutex and conditional variable can't be statically-initialized on Windows.
 */
static void init_thread(void)
{}

static void cleanup_thread(void)
{}

static int mark_link(struct object *obj, enum object_type type,
		     void *data UNUSED,
		     struct fsck_options *options UNUSED)
{}

/* The content of each linked object must have been checked
   or it must be already present in the object database */
static unsigned check_object(struct object *obj)
{}

static unsigned check_objects(void)
{}


/* Discard current buffer used content. */
static void flush(void)
{}

/*
 * Make sure at least "min" bytes are available in the buffer, and
 * return the pointer to the buffer.
 */
static void *fill(int min)
{}

static void use(int bytes)
{}

static const char *open_pack_file(const char *pack_name)
{}

static void parse_pack_header(void)
{}

__attribute__((format (printf, 2, 3)))
static NORETURN void bad_object(off_t offset, const char *format, ...)
{}

static inline struct thread_local *get_thread_data(void)
{}

static void set_thread_data(struct thread_local *data)
{}

static void free_base_data(struct base_data *c)
{}

static void prune_base_data(struct base_data *retain)
{}

static int is_delta_type(enum object_type type)
{}

static void *unpack_entry_data(off_t offset, unsigned long size,
			       enum object_type type, struct object_id *oid)
{}

static void *unpack_raw_entry(struct object_entry *obj,
			      off_t *ofs_offset,
			      struct object_id *ref_oid,
			      struct object_id *oid)
{}

static void *unpack_data(struct object_entry *obj,
			 int (*consume)(const unsigned char *, unsigned long, void *),
			 void *cb_data)
{}

static void *get_data_from_pack(struct object_entry *obj)
{}

static int compare_ofs_delta_bases(off_t offset1, off_t offset2,
				   enum object_type type1,
				   enum object_type type2)
{}

static int find_ofs_delta(const off_t offset)
{}

static void find_ofs_delta_children(off_t offset,
				    int *first_index, int *last_index)
{}

static int compare_ref_delta_bases(const struct object_id *oid1,
				   const struct object_id *oid2,
				   enum object_type type1,
				   enum object_type type2)
{}

static int find_ref_delta(const struct object_id *oid)
{}

static void find_ref_delta_children(const struct object_id *oid,
				    int *first_index, int *last_index)
{}

struct compare_data {};

static int compare_objects(const unsigned char *buf, unsigned long size,
			   void *cb_data)
{}

static int check_collison(struct object_entry *entry)
{}

static void sha1_object(const void *data, struct object_entry *obj_entry,
			unsigned long size, enum object_type type,
			const struct object_id *oid)
{}

/*
 * Ensure that this node has been reconstructed and return its contents.
 *
 * In the typical and best case, this node would already be reconstructed
 * (through the invocation to resolve_delta() in threaded_second_pass()) and it
 * would not be pruned. However, if pruning of this node was necessary due to
 * reaching delta_base_cache_limit, this function will find the closest
 * ancestor with reconstructed data that has not been pruned (or if there is
 * none, the ultimate base object), and reconstruct each node in the delta
 * chain in order to generate the reconstructed data for this node.
 */
static void *get_base_data(struct base_data *c)
{}

static struct base_data *make_base(struct object_entry *obj,
				   struct base_data *parent)
{}

static struct base_data *resolve_delta(struct object_entry *delta_obj,
				       struct base_data *base)
{}

static int compare_ofs_delta_entry(const void *a, const void *b)
{}

static int compare_ref_delta_entry(const void *a, const void *b)
{}

static void *threaded_second_pass(void *data)
{}

/*
 * First pass:
 * - find locations of all objects;
 * - calculate SHA1 of all non-delta objects;
 * - remember base (SHA1 or offset) for all deltas.
 */
static void parse_pack_objects(unsigned char *hash)
{}

/*
 * Second pass:
 * - for all non-delta objects, look if it is used as a base for
 *   deltas;
 * - if used as a base, uncompress the object and apply all deltas,
 *   recursively checking if the resulting object is used as a base
 *   for some more deltas.
 */
static void resolve_deltas(void)
{}

/*
 * Third pass:
 * - append objects to convert thin pack to full pack if required
 * - write the final pack hash
 */
static void fix_unresolved_deltas(struct hashfile *f);
static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned char *pack_hash)
{}

static int write_compressed(struct hashfile *f, void *in, unsigned int size)
{}

static struct object_entry *append_obj_to_pack(struct hashfile *f,
			       const unsigned char *sha1, void *buf,
			       unsigned long size, enum object_type type)
{}

static int delta_pos_compare(const void *_a, const void *_b)
{}

static void fix_unresolved_deltas(struct hashfile *f)
{}

static const char *derive_filename(const char *pack_name, const char *strip,
				   const char *suffix, struct strbuf *buf)
{}

static void write_special_file(const char *suffix, const char *msg,
			       const char *pack_name, const unsigned char *hash,
			       const char **report)
{}

static void rename_tmp_packfile(const char **final_name,
				const char *curr_name,
				struct strbuf *name, unsigned char *hash,
				const char *ext, int make_read_only_if_same)
{}

static void final(const char *final_pack_name, const char *curr_pack_name,
		  const char *final_index_name, const char *curr_index_name,
		  const char *final_rev_index_name, const char *curr_rev_index_name,
		  const char *keep_msg, const char *promisor_msg,
		  unsigned char *hash)
{}

static int git_index_pack_config(const char *k, const char *v,
				 const struct config_context *ctx, void *cb)
{}

static int cmp_uint32(const void *a_, const void *b_)
{}

static void read_v2_anomalous_offsets(struct packed_git *p,
				      struct pack_idx_option *opts)
{}

static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
{}

static void show_pack_info(int stat_only)
{}

int cmd_index_pack(int argc,
		   const char **argv,
		   const char *prefix,
		   struct repository *repo UNUSED)
{}