]> git.proxmox.com Git - libgit2.git/blame - include/git2/indexer.h
New upstream version 1.1.0+dfsg.1
[libgit2.git] / include / git2 / indexer.h
CommitLineData
bb742ede 1/*
359fc2d2 2 * Copyright (C) the libgit2 contributors. All rights reserved.
bb742ede
VM
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 */
3412391d
CMN
7#ifndef _INCLUDE_git_indexer_h__
8#define _INCLUDE_git_indexer_h__
9
2cbca8b0 10#include "common.h"
83cc70d9 11#include "types.h"
2cbca8b0 12#include "oid.h"
f23c4a66 13
a6bbb8ca
LC
14GIT_BEGIN_DECL
15
22a2d3d5 16/** A git indexer object */
a6154f21 17typedef struct git_indexer git_indexer;
3f93e16c 18
22a2d3d5
UG
19/**
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.
23 */
24typedef struct git_indexer_progress {
25 /** number of objects in the packfile being indexed */
26 unsigned int total_objects;
27
28 /** received objects that have been hashed */
29 unsigned int indexed_objects;
30
31 /** received_objects: objects which have been downloaded */
32 unsigned int received_objects;
33
34 /**
35 * locally-available objects that have been injected in order
36 * to fix a thin pack
37 */
38 unsigned int local_objects;
39
40 /** number of deltas in the packfile being indexed */
41 unsigned int total_deltas;
42
43 /** received deltas that have been indexed */
44 unsigned int indexed_deltas;
45
46 /** size of the packfile received up to now */
47 size_t received_bytes;
48} git_indexer_progress;
49
50/**
51 * Type for progress callbacks during indexing. Return a value less
52 * than zero to cancel the indexing or download.
53 *
54 * @param stats Structure containing information about the state of the tran sfer
55 * @param payload Payload provided by caller
56 */
57typedef int GIT_CALLBACK(git_indexer_progress_cb)(const git_indexer_progress *stats, void *payload);
58
59/**
60 * Options for indexer configuration
61 */
ac3d33df
JK
62typedef struct git_indexer_options {
63 unsigned int version;
64
65 /** progress_cb function to call with progress information */
22a2d3d5 66 git_indexer_progress_cb progress_cb;
ac3d33df
JK
67 /** progress_cb_payload payload for the progress callback */
68 void *progress_cb_payload;
69
70 /** Do connectivity checks for the received pack */
71 unsigned char verify;
72} git_indexer_options;
73
74#define GIT_INDEXER_OPTIONS_VERSION 1
75#define GIT_INDEXER_OPTIONS_INIT { GIT_INDEXER_OPTIONS_VERSION }
76
77/**
78 * Initializes a `git_indexer_options` with default values. Equivalent to
79 * creating an instance with GIT_INDEXER_OPTIONS_INIT.
80 *
81 * @param opts the `git_indexer_options` struct to initialize.
82 * @param version Version of struct; pass `GIT_INDEXER_OPTIONS_VERSION`
83 * @return Zero on success; -1 on failure.
84 */
22a2d3d5 85GIT_EXTERN(int) git_indexer_options_init(
ac3d33df
JK
86 git_indexer_options *opts,
87 unsigned int version);
88
3f93e16c 89/**
a6154f21 90 * Create a new indexer instance
3f93e16c 91 *
d73c94b2 92 * @param out where to store the indexer instance
37159957 93 * @param path to the directory where the packfile should be stored
1e60e5f4 94 * @param mode permissions to use creating packfile or 0 for defaults
0b33fca0
CMN
95 * @param odb object database from which to read base objects when
96 * fixing thin packs. Pass NULL if no thin pack is expected (an error
97 * will be returned if there are bases missing)
ac3d33df
JK
98 * @param opts Optional structure containing additional options. See
99 * `git_indexer_options` above.
3f93e16c 100 */
a6154f21
CMN
101GIT_EXTERN(int) git_indexer_new(
102 git_indexer **out,
216863c4 103 const char *path,
1e60e5f4 104 unsigned int mode,
0b33fca0 105 git_odb *odb,
ac3d33df 106 git_indexer_options *opts);
3f93e16c
CMN
107
108/**
109 * Add data to the indexer
110 *
111 * @param idx the indexer
112 * @param data the data to add
839c5f57 113 * @param size the size of the data in bytes
3f93e16c
CMN
114 * @param stats stat storage
115 */
22a2d3d5 116GIT_EXTERN(int) git_indexer_append(git_indexer *idx, const void *data, size_t size, git_indexer_progress *stats);
3412391d 117
453ab98d
CMN
118/**
119 * Finalize the pack and index
120 *
121 * Resolve any pending deltas and write out the index file
122 *
123 * @param idx the indexer
124 */
22a2d3d5 125GIT_EXTERN(int) git_indexer_commit(git_indexer *idx, git_indexer_progress *stats);
453ab98d 126
1c9c081a
CMN
127/**
128 * Get the packfile's hash
129 *
130 * A packfile's name is derived from the sorted hashing of all object
131 * names. This is only correct after the index has been finalized.
132 *
133 * @param idx the indexer instance
134 */
a6154f21 135GIT_EXTERN(const git_oid *) git_indexer_hash(const git_indexer *idx);
1c9c081a
CMN
136
137/**
138 * Free the indexer and its resources
139 *
140 * @param idx the indexer to free
141 */
a6154f21 142GIT_EXTERN(void) git_indexer_free(git_indexer *idx);
1c9c081a 143
a6bbb8ca 144GIT_END_DECL
3412391d
CMN
145
146#endif