|
||||
File indexing completed on 2025-01-18 09:59:38
0001 /* 0002 * Copyright (C) the libgit2 contributors. All rights reserved. 0003 * 0004 * This file is part of libgit2, distributed under the GNU GPL v2 with 0005 * a Linking Exception. For full terms see the included COPYING file. 0006 */ 0007 #ifndef INCLUDE_git_pack_h__ 0008 #define INCLUDE_git_pack_h__ 0009 0010 #include "common.h" 0011 #include "oid.h" 0012 #include "indexer.h" 0013 0014 /** 0015 * @file git2/pack.h 0016 * @brief Git pack management routines 0017 * 0018 * Packing objects 0019 * --------------- 0020 * 0021 * Creation of packfiles requires two steps: 0022 * 0023 * - First, insert all the objects you want to put into the packfile 0024 * using `git_packbuilder_insert` and `git_packbuilder_insert_tree`. 0025 * It's important to add the objects in recency order ("in the order 0026 * that they are 'reachable' from head"). 0027 * 0028 * "ANY order will give you a working pack, ... [but it is] the thing 0029 * that gives packs good locality. It keeps the objects close to the 0030 * head (whether they are old or new, but they are _reachable_ from the 0031 * head) at the head of the pack. So packs actually have absolutely 0032 * _wonderful_ IO patterns." - Linus Torvalds 0033 * git.git/Documentation/technical/pack-heuristics.txt 0034 * 0035 * - Second, use `git_packbuilder_write` or `git_packbuilder_foreach` to 0036 * write the resulting packfile. 0037 * 0038 * libgit2 will take care of the delta ordering and generation. 0039 * `git_packbuilder_set_threads` can be used to adjust the number of 0040 * threads used for the process. 0041 * 0042 * See tests/pack/packbuilder.c for an example. 0043 * 0044 * @ingroup Git 0045 * @{ 0046 */ 0047 GIT_BEGIN_DECL 0048 0049 /** 0050 * Stages that are reported by the packbuilder progress callback. 0051 */ 0052 typedef enum { 0053 GIT_PACKBUILDER_ADDING_OBJECTS = 0, 0054 GIT_PACKBUILDER_DELTAFICATION = 1 0055 } git_packbuilder_stage_t; 0056 0057 /** 0058 * Initialize a new packbuilder 0059 * 0060 * @param out The new packbuilder object 0061 * @param repo The repository 0062 * 0063 * @return 0 or an error code 0064 */ 0065 GIT_EXTERN(int) git_packbuilder_new(git_packbuilder **out, git_repository *repo); 0066 0067 /** 0068 * Set number of threads to spawn 0069 * 0070 * By default, libgit2 won't spawn any threads at all; 0071 * when set to 0, libgit2 will autodetect the number of 0072 * CPUs. 0073 * 0074 * @param pb The packbuilder 0075 * @param n Number of threads to spawn 0076 * @return number of actual threads to be used 0077 */ 0078 GIT_EXTERN(unsigned int) git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n); 0079 0080 /** 0081 * Insert a single object 0082 * 0083 * For an optimal pack it's mandatory to insert objects in recency order, 0084 * commits followed by trees and blobs. 0085 * 0086 * @param pb The packbuilder 0087 * @param id The oid of the commit 0088 * @param name The name; might be NULL 0089 * 0090 * @return 0 or an error code 0091 */ 0092 GIT_EXTERN(int) git_packbuilder_insert(git_packbuilder *pb, const git_oid *id, const char *name); 0093 0094 /** 0095 * Insert a root tree object 0096 * 0097 * This will add the tree as well as all referenced trees and blobs. 0098 * 0099 * @param pb The packbuilder 0100 * @param id The oid of the root tree 0101 * 0102 * @return 0 or an error code 0103 */ 0104 GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *id); 0105 0106 /** 0107 * Insert a commit object 0108 * 0109 * This will add a commit as well as the completed referenced tree. 0110 * 0111 * @param pb The packbuilder 0112 * @param id The oid of the commit 0113 * 0114 * @return 0 or an error code 0115 */ 0116 GIT_EXTERN(int) git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *id); 0117 0118 /** 0119 * Insert objects as given by the walk 0120 * 0121 * Those commits and all objects they reference will be inserted into 0122 * the packbuilder. 0123 * 0124 * @param pb the packbuilder 0125 * @param walk the revwalk to use to fill the packbuilder 0126 * 0127 * @return 0 or an error code 0128 */ 0129 GIT_EXTERN(int) git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk); 0130 0131 /** 0132 * Recursively insert an object and its referenced objects 0133 * 0134 * Insert the object as well as any object it references. 0135 * 0136 * @param pb the packbuilder 0137 * @param id the id of the root object to insert 0138 * @param name optional name for the object 0139 * @return 0 or an error code 0140 */ 0141 GIT_EXTERN(int) git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name); 0142 0143 /** 0144 * Write the contents of the packfile to an in-memory buffer 0145 * 0146 * The contents of the buffer will become a valid packfile, even though there 0147 * will be no attached index 0148 * 0149 * @param buf Buffer where to write the packfile 0150 * @param pb The packbuilder 0151 * @return 0 or an error code 0152 */ 0153 GIT_EXTERN(int) git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb); 0154 0155 /** 0156 * Write the new pack and corresponding index file to path. 0157 * 0158 * @param pb The packbuilder 0159 * @param path Path to the directory where the packfile and index should be stored, or NULL for default location 0160 * @param mode permissions to use creating a packfile or 0 for defaults 0161 * @param progress_cb function to call with progress information from the indexer (optional) 0162 * @param progress_cb_payload payload for the progress callback (optional) 0163 * 0164 * @return 0 or an error code 0165 */ 0166 GIT_EXTERN(int) git_packbuilder_write( 0167 git_packbuilder *pb, 0168 const char *path, 0169 unsigned int mode, 0170 git_indexer_progress_cb progress_cb, 0171 void *progress_cb_payload); 0172 0173 #ifndef GIT_DEPRECATE_HARD 0174 /** 0175 * Get the packfile's hash 0176 * 0177 * A packfile's name is derived from the sorted hashing of all object 0178 * names. This is only correct after the packfile has been written. 0179 * 0180 * @deprecated use git_packbuilder_name 0181 * @param pb The packbuilder object 0182 * @return 0 or an error code 0183 */ 0184 GIT_EXTERN(const git_oid *) git_packbuilder_hash(git_packbuilder *pb); 0185 #endif 0186 0187 /** 0188 * Get the unique name for the resulting packfile. 0189 * 0190 * The packfile's name is derived from the packfile's content. 0191 * This is only correct after the packfile has been written. 0192 * 0193 * @param pb the packbuilder instance 0194 * @return a NUL terminated string for the packfile name 0195 */ 0196 GIT_EXTERN(const char *) git_packbuilder_name(git_packbuilder *pb); 0197 0198 /** 0199 * Callback used to iterate over packed objects 0200 * 0201 * @see git_packbuilder_foreach 0202 * 0203 * @param buf A pointer to the object's data 0204 * @param size The size of the underlying object 0205 * @param payload Payload passed to git_packbuilder_foreach 0206 * @return non-zero to terminate the iteration 0207 */ 0208 typedef int GIT_CALLBACK(git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload); 0209 0210 /** 0211 * Create the new pack and pass each object to the callback 0212 * 0213 * @param pb the packbuilder 0214 * @param cb the callback to call with each packed object's buffer 0215 * @param payload the callback's data 0216 * @return 0 or an error code 0217 */ 0218 GIT_EXTERN(int) git_packbuilder_foreach(git_packbuilder *pb, git_packbuilder_foreach_cb cb, void *payload); 0219 0220 /** 0221 * Get the total number of objects the packbuilder will write out 0222 * 0223 * @param pb the packbuilder 0224 * @return the number of objects in the packfile 0225 */ 0226 GIT_EXTERN(size_t) git_packbuilder_object_count(git_packbuilder *pb); 0227 0228 /** 0229 * Get the number of objects the packbuilder has already written out 0230 * 0231 * @param pb the packbuilder 0232 * @return the number of objects which have already been written 0233 */ 0234 GIT_EXTERN(size_t) git_packbuilder_written(git_packbuilder *pb); 0235 0236 /** Packbuilder progress notification function */ 0237 typedef int GIT_CALLBACK(git_packbuilder_progress)( 0238 int stage, 0239 uint32_t current, 0240 uint32_t total, 0241 void *payload); 0242 0243 /** 0244 * Set the callbacks for a packbuilder 0245 * 0246 * @param pb The packbuilder object 0247 * @param progress_cb Function to call with progress information during 0248 * pack building. Be aware that this is called inline with pack building 0249 * operations, so performance may be affected. 0250 * @param progress_cb_payload Payload for progress callback. 0251 * @return 0 or an error code 0252 */ 0253 GIT_EXTERN(int) git_packbuilder_set_callbacks( 0254 git_packbuilder *pb, 0255 git_packbuilder_progress progress_cb, 0256 void *progress_cb_payload); 0257 0258 /** 0259 * Free the packbuilder and all associated data 0260 * 0261 * @param pb The packbuilder 0262 */ 0263 GIT_EXTERN(void) git_packbuilder_free(git_packbuilder *pb); 0264 0265 /** @} */ 0266 GIT_END_DECL 0267 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |