pack-objects.h 2.38 KB
Newer Older
Michael Schubert committed
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
Michael Schubert committed
3 4 5 6 7 8 9 10 11 12
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */

#ifndef INCLUDE_pack_objects_h__
#define INCLUDE_pack_objects_h__

#include "common.h"

13
#include "str.h"
Michael Schubert committed
14
#include "hash.h"
15
#include "oidmap.h"
16
#include "netops.h"
17
#include "zstream.h"
18
#include "pool.h"
19
#include "indexer.h"
Michael Schubert committed
20 21

#include "git2/oid.h"
22
#include "git2/pack.h"
Michael Schubert committed
23 24 25 26 27 28 29 30 31

#define GIT_PACK_WINDOW 10 /* number of objects to possibly delta against */
#define GIT_PACK_DEPTH 50 /* max delta depth */
#define GIT_PACK_DELTA_CACHE_SIZE (256 * 1024 * 1024)
#define GIT_PACK_DELTA_CACHE_LIMIT 1000
#define GIT_PACK_BIG_FILE_THRESHOLD (512 * 1024 * 1024)

typedef struct git_pobject {
	git_oid id;
32
	git_object_t type;
33
	off64_t offset;
Michael Schubert committed
34 35 36 37 38 39 40 41 42 43 44 45

	size_t size;

	unsigned int hash; /* name hint hash */

	struct git_pobject *delta; /* delta base object */
	struct git_pobject *delta_child; /* deltified objects who bases me */
	struct git_pobject *delta_sibling; /* other deltified objects
					    * who uses the same base as
					    * me */

	void *delta_data;
46 47
	size_t delta_size;
	size_t z_delta_size;
Michael Schubert committed
48

49 50 51 52
	unsigned int written:1,
	             recursing:1,
	             tagged:1,
	             filled:1;
Michael Schubert committed
53 54 55 56 57 58
} git_pobject;

struct git_packbuilder {
	git_repository *repo; /* associated repository */
	git_odb *odb; /* associated object database */

59 60
	git_oid_t oid_type;

61
	git_hash_ctx ctx;
62
	git_zstream zstream;
Michael Schubert committed
63 64

	uint32_t nr_objects,
65 66 67 68 69
		nr_deltified,
		nr_written,
		nr_remaining;

	size_t nr_alloc;
Michael Schubert committed
70 71 72

	git_pobject *object_list;

73
	git_oidmap *object_ix;
Michael Schubert committed
74

75 76 77
	git_oidmap *walk_objects;
	git_pool object_pool;

78
#ifndef GIT_DEPRECATE_HARD
Michael Schubert committed
79
	git_oid pack_oid; /* hash of written pack */
80 81
#endif
	char *pack_name; /* name of written pack */
Michael Schubert committed
82

83 84 85 86 87
	/* synchronization objects */
	git_mutex cache_mutex;
	git_mutex progress_mutex;
	git_cond progress_cond;

Michael Schubert committed
88
	/* configs */
89 90 91 92 93
	size_t delta_cache_size;
	size_t max_delta_cache_size;
	size_t cache_max_small_delta_size;
	size_t big_file_threshold;
	size_t window_memory_limit;
Michael Schubert committed
94

95
	unsigned int nr_threads; /* nr of threads to use */
Michael Schubert committed
96

97 98 99 100
	git_packbuilder_progress progress_cb;
	void *progress_cb_payload;
	double last_progress_report_time; /* the time progress was last reported */

Michael Schubert committed
101 102 103
	bool done;
};

104
int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb);
105
int git_packbuilder__prepare(git_packbuilder *pb);
106

Michael Schubert committed
107

108
#endif