1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 
8 #ifndef INCLUDE_pack_objects_h__
9 #define INCLUDE_pack_objects_h__
10 
11 #include "common.h"
12 
13 #include "buffer.h"
14 #include "hash.h"
15 #include "oidmap.h"
16 #include "netops.h"
17 #include "zstream.h"
18 #include "pool.h"
19 #include "indexer.h"
20 
21 #include "git2/oid.h"
22 #include "git2/pack.h"
23 
24 #define GIT_PACK_WINDOW 10 /* number of objects to possibly delta against */
25 #define GIT_PACK_DEPTH 50 /* max delta depth */
26 #define GIT_PACK_DELTA_CACHE_SIZE (256 * 1024 * 1024)
27 #define GIT_PACK_DELTA_CACHE_LIMIT 1000
28 #define GIT_PACK_BIG_FILE_THRESHOLD (512 * 1024 * 1024)
29 
30 typedef struct git_pobject {
31 	git_oid id;
32 	git_object_t type;
33 	off64_t offset;
34 
35 	size_t size;
36 
37 	unsigned int hash; /* name hint hash */
38 
39 	struct git_pobject *delta; /* delta base object */
40 	struct git_pobject *delta_child; /* deltified objects who bases me */
41 	struct git_pobject *delta_sibling; /* other deltified objects
42 					    * who uses the same base as
43 					    * me */
44 
45 	void *delta_data;
46 	size_t delta_size;
47 	size_t z_delta_size;
48 
49 	int written:1,
50 	    recursing:1,
51 	    tagged:1,
52 	    filled:1;
53 } git_pobject;
54 
55 struct git_packbuilder {
56 	git_repository *repo; /* associated repository */
57 	git_odb *odb; /* associated object database */
58 
59 	git_hash_ctx ctx;
60 	git_zstream zstream;
61 
62 	uint32_t nr_objects,
63 		nr_deltified,
64 		nr_written,
65 		nr_remaining;
66 
67 	size_t nr_alloc;
68 
69 	git_pobject *object_list;
70 
71 	git_oidmap *object_ix;
72 
73 	git_oidmap *walk_objects;
74 	git_pool object_pool;
75 
76 	git_oid pack_oid; /* hash of written pack */
77 
78 	/* synchronization objects */
79 	git_mutex cache_mutex;
80 	git_mutex progress_mutex;
81 	git_cond progress_cond;
82 
83 	/* configs */
84 	size_t delta_cache_size;
85 	size_t max_delta_cache_size;
86 	size_t cache_max_small_delta_size;
87 	size_t big_file_threshold;
88 	size_t window_memory_limit;
89 
90 	unsigned int nr_threads; /* nr of threads to use */
91 
92 	git_packbuilder_progress progress_cb;
93 	void *progress_cb_payload;
94 	double last_progress_report_time; /* the time progress was last reported */
95 
96 	bool done;
97 };
98 
99 int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb);
100 
101 #endif
102