2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef _INCLUDE_git_indexer_h__
8 #define _INCLUDE_git_indexer_h__
16 /** A git indexer object */
17 typedef struct git_indexer git_indexer
;
20 * This structure is used to provide callers information about the
21 * progress of indexing a packfile, either directly or part of a
22 * fetch or clone that downloads a packfile.
24 typedef struct git_indexer_progress
{
25 /** number of objects in the packfile being indexed */
26 unsigned int total_objects
;
28 /** received objects that have been hashed */
29 unsigned int indexed_objects
;
31 /** received_objects: objects which have been downloaded */
32 unsigned int received_objects
;
35 * locally-available objects that have been injected in order
38 unsigned int local_objects
;
40 /** number of deltas in the packfile being indexed */
41 unsigned int total_deltas
;
43 /** received deltas that have been indexed */
44 unsigned int indexed_deltas
;
46 /** size of the packfile received up to now */
47 size_t received_bytes
;
48 } git_indexer_progress
;
51 * Type for progress callbacks during indexing. Return a value less
52 * than zero to cancel the indexing or download.
54 * @param stats Structure containing information about the state of the transfer
55 * @param payload Payload provided by caller
57 typedef int GIT_CALLBACK(git_indexer_progress_cb
)(const git_indexer_progress
*stats
, void *payload
);
60 * Options for indexer configuration
62 typedef struct git_indexer_options
{
65 /** progress_cb function to call with progress information */
66 git_indexer_progress_cb progress_cb
;
68 /** progress_cb_payload payload for the progress callback */
69 void *progress_cb_payload
;
71 /** Do connectivity checks for the received pack */
73 } git_indexer_options
;
75 #define GIT_INDEXER_OPTIONS_VERSION 1
76 #define GIT_INDEXER_OPTIONS_INIT { GIT_INDEXER_OPTIONS_VERSION }
79 * Initializes a `git_indexer_options` with default values. Equivalent to
80 * creating an instance with GIT_INDEXER_OPTIONS_INIT.
82 * @param opts the `git_indexer_options` struct to initialize.
83 * @param version Version of struct; pass `GIT_INDEXER_OPTIONS_VERSION`
84 * @return Zero on success; -1 on failure.
86 GIT_EXTERN(int) git_indexer_options_init(
87 git_indexer_options
*opts
,
88 unsigned int version
);
91 * Create a new indexer instance
93 * @param out where to store the indexer instance
94 * @param path to the directory where the packfile should be stored
95 * @param mode permissions to use creating packfile or 0 for defaults
96 * @param odb object database from which to read base objects when
97 * fixing thin packs. Pass NULL if no thin pack is expected (an error
98 * will be returned if there are bases missing)
99 * @param opts Optional structure containing additional options. See
100 * `git_indexer_options` above.
102 GIT_EXTERN(int) git_indexer_new(
107 git_indexer_options
*opts
);
110 * Add data to the indexer
112 * @param idx the indexer
113 * @param data the data to add
114 * @param size the size of the data in bytes
115 * @param stats stat storage
117 GIT_EXTERN(int) git_indexer_append(git_indexer
*idx
, const void *data
, size_t size
, git_indexer_progress
*stats
);
120 * Finalize the pack and index
122 * Resolve any pending deltas and write out the index file
124 * @param idx the indexer
126 GIT_EXTERN(int) git_indexer_commit(git_indexer
*idx
, git_indexer_progress
*stats
);
129 * Get the packfile's hash
131 * A packfile's name is derived from the sorted hashing of all object
132 * names. This is only correct after the index has been finalized.
134 * @param idx the indexer instance
136 GIT_EXTERN(const git_oid
*) git_indexer_hash(const git_indexer
*idx
);
139 * Free the indexer and its resources
141 * @param idx the indexer to free
143 GIT_EXTERN(void) git_indexer_free(git_indexer
*idx
);