|
||||
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_repository_h__ 0008 #define INCLUDE_git_repository_h__ 0009 0010 #include "common.h" 0011 #include "types.h" 0012 #include "oid.h" 0013 #include "buffer.h" 0014 #include "commit.h" 0015 0016 /** 0017 * @file git2/repository.h 0018 * @brief Git repository management routines 0019 * @defgroup git_repository Git repository management routines 0020 * @ingroup Git 0021 * @{ 0022 */ 0023 GIT_BEGIN_DECL 0024 0025 /** 0026 * Open a git repository. 0027 * 0028 * The 'path' argument must point to either a git repository 0029 * folder, or an existing work dir. 0030 * 0031 * The method will automatically detect if 'path' is a normal 0032 * or bare repository or fail is 'path' is neither. 0033 * 0034 * @param out pointer to the repo which will be opened 0035 * @param path the path to the repository 0036 * @return 0 or an error code 0037 */ 0038 GIT_EXTERN(int) git_repository_open(git_repository **out, const char *path); 0039 /** 0040 * Open working tree as a repository 0041 * 0042 * Open the working directory of the working tree as a normal 0043 * repository that can then be worked on. 0044 * 0045 * @param out Output pointer containing opened repository 0046 * @param wt Working tree to open 0047 * @return 0 or an error code 0048 */ 0049 GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_worktree *wt); 0050 0051 /** 0052 * Create a "fake" repository to wrap an object database 0053 * 0054 * Create a repository object to wrap an object database to be used 0055 * with the API when all you have is an object database. This doesn't 0056 * have any paths associated with it, so use with care. 0057 * 0058 * @param out pointer to the repo 0059 * @param odb the object database to wrap 0060 * @param oid_type the oid type of the object database 0061 * @return 0 or an error code 0062 */ 0063 #ifdef GIT_EXPERIMENTAL_SHA256 0064 GIT_EXTERN(int) git_repository_wrap_odb( 0065 git_repository **out, 0066 git_odb *odb, 0067 git_oid_t oid_type); 0068 #else 0069 GIT_EXTERN(int) git_repository_wrap_odb( 0070 git_repository **out, 0071 git_odb *odb); 0072 #endif 0073 0074 /** 0075 * Look for a git repository and copy its path in the given buffer. 0076 * The lookup start from base_path and walk across parent directories 0077 * if nothing has been found. The lookup ends when the first repository 0078 * is found, or when reaching a directory referenced in ceiling_dirs 0079 * or when the filesystem changes (in case across_fs is true). 0080 * 0081 * The method will automatically detect if the repository is bare 0082 * (if there is a repository). 0083 * 0084 * @param out A pointer to a user-allocated git_buf which will contain 0085 * the found path. 0086 * 0087 * @param start_path The base path where the lookup starts. 0088 * 0089 * @param across_fs If true, then the lookup will not stop when a 0090 * filesystem device change is detected while exploring parent directories. 0091 * 0092 * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR separated list of 0093 * absolute symbolic link free paths. The lookup will stop when any 0094 * of this paths is reached. Note that the lookup always performs on 0095 * start_path no matter start_path appears in ceiling_dirs ceiling_dirs 0096 * might be NULL (which is equivalent to an empty string) 0097 * 0098 * @return 0 or an error code 0099 */ 0100 GIT_EXTERN(int) git_repository_discover( 0101 git_buf *out, 0102 const char *start_path, 0103 int across_fs, 0104 const char *ceiling_dirs); 0105 0106 /** 0107 * Option flags for `git_repository_open_ext`. 0108 */ 0109 typedef enum { 0110 /** 0111 * Only open the repository if it can be immediately found in the 0112 * start_path. Do not walk up from the start_path looking at parent 0113 * directories. 0114 */ 0115 GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0), 0116 0117 /** 0118 * Unless this flag is set, open will not continue searching across 0119 * filesystem boundaries (i.e. when `st_dev` changes from the `stat` 0120 * system call). For example, searching in a user's home directory at 0121 * "/home/user/source/" will not return "/.git/" as the found repo if 0122 * "/" is a different filesystem than "/home". 0123 */ 0124 GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1), 0125 0126 /** 0127 * Open repository as a bare repo regardless of core.bare config, and 0128 * defer loading config file for faster setup. 0129 * Unlike `git_repository_open_bare`, this can follow gitlinks. 0130 */ 0131 GIT_REPOSITORY_OPEN_BARE = (1 << 2), 0132 0133 /** 0134 * Do not check for a repository by appending /.git to the start_path; 0135 * only open the repository if start_path itself points to the git 0136 * directory. 0137 */ 0138 GIT_REPOSITORY_OPEN_NO_DOTGIT = (1 << 3), 0139 0140 /** 0141 * Find and open a git repository, respecting the environment variables 0142 * used by the git command-line tools. 0143 * If set, `git_repository_open_ext` will ignore the other flags and 0144 * the `ceiling_dirs` argument, and will allow a NULL `path` to use 0145 * `GIT_DIR` or search from the current directory. 0146 * The search for a repository will respect $GIT_CEILING_DIRECTORIES and 0147 * $GIT_DISCOVERY_ACROSS_FILESYSTEM. The opened repository will 0148 * respect $GIT_INDEX_FILE, $GIT_NAMESPACE, $GIT_OBJECT_DIRECTORY, and 0149 * $GIT_ALTERNATE_OBJECT_DIRECTORIES. 0150 * In the future, this flag will also cause `git_repository_open_ext` 0151 * to respect $GIT_WORK_TREE and $GIT_COMMON_DIR; currently, 0152 * `git_repository_open_ext` with this flag will error out if either 0153 * $GIT_WORK_TREE or $GIT_COMMON_DIR is set. 0154 */ 0155 GIT_REPOSITORY_OPEN_FROM_ENV = (1 << 4) 0156 } git_repository_open_flag_t; 0157 0158 /** 0159 * Find and open a repository with extended controls. 0160 * 0161 * @param out Pointer to the repo which will be opened. This can 0162 * actually be NULL if you only want to use the error code to 0163 * see if a repo at this path could be opened. 0164 * @param path Path to open as git repository. If the flags 0165 * permit "searching", then this can be a path to a subdirectory 0166 * inside the working directory of the repository. May be NULL if 0167 * flags is GIT_REPOSITORY_OPEN_FROM_ENV. 0168 * @param flags A combination of the GIT_REPOSITORY_OPEN flags above. 0169 * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR delimited list of path 0170 * prefixes at which the search for a containing repository should 0171 * terminate. 0172 * @return 0 on success, GIT_ENOTFOUND if no repository could be found, 0173 * or -1 if there was a repository but open failed for some reason 0174 * (such as repo corruption or system errors). 0175 */ 0176 GIT_EXTERN(int) git_repository_open_ext( 0177 git_repository **out, 0178 const char *path, 0179 unsigned int flags, 0180 const char *ceiling_dirs); 0181 0182 /** 0183 * Open a bare repository on the serverside. 0184 * 0185 * This is a fast open for bare repositories that will come in handy 0186 * if you're e.g. hosting git repositories and need to access them 0187 * efficiently 0188 * 0189 * @param out Pointer to the repo which will be opened. 0190 * @param bare_path Direct path to the bare repository 0191 * @return 0 on success, or an error code 0192 */ 0193 GIT_EXTERN(int) git_repository_open_bare(git_repository **out, const char *bare_path); 0194 0195 /** 0196 * Free a previously allocated repository 0197 * 0198 * Note that after a repository is free'd, all the objects it has spawned 0199 * will still exist until they are manually closed by the user 0200 * with `git_object_free`, but accessing any of the attributes of 0201 * an object without a backing repository will result in undefined 0202 * behavior 0203 * 0204 * @param repo repository handle to close. If NULL nothing occurs. 0205 */ 0206 GIT_EXTERN(void) git_repository_free(git_repository *repo); 0207 0208 /** 0209 * Creates a new Git repository in the given folder. 0210 * 0211 * TODO: 0212 * - Reinit the repository 0213 * 0214 * @param out pointer to the repo which will be created or reinitialized 0215 * @param path the path to the repository 0216 * @param is_bare if true, a Git repository without a working directory is 0217 * created at the pointed path. If false, provided path will be 0218 * considered as the working directory into which the .git directory 0219 * will be created. 0220 * 0221 * @return 0 or an error code 0222 */ 0223 GIT_EXTERN(int) git_repository_init( 0224 git_repository **out, 0225 const char *path, 0226 unsigned is_bare); 0227 0228 /** 0229 * Option flags for `git_repository_init_ext`. 0230 * 0231 * These flags configure extra behaviors to `git_repository_init_ext`. 0232 * In every case, the default behavior is the zero value (i.e. flag is 0233 * not set). Just OR the flag values together for the `flags` parameter 0234 * when initializing a new repo. 0235 */ 0236 typedef enum { 0237 /** 0238 * Create a bare repository with no working directory. 0239 */ 0240 GIT_REPOSITORY_INIT_BARE = (1u << 0), 0241 0242 /** 0243 * Return an GIT_EEXISTS error if the repo_path appears to already be 0244 * an git repository. 0245 */ 0246 GIT_REPOSITORY_INIT_NO_REINIT = (1u << 1), 0247 0248 /** 0249 * Normally a "/.git/" will be appended to the repo path for 0250 * non-bare repos (if it is not already there), but passing this flag 0251 * prevents that behavior. 0252 */ 0253 GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1u << 2), 0254 0255 /** 0256 * Make the repo_path (and workdir_path) as needed. Init is always willing 0257 * to create the ".git" directory even without this flag. This flag tells 0258 * init to create the trailing component of the repo and workdir paths 0259 * as needed. 0260 */ 0261 GIT_REPOSITORY_INIT_MKDIR = (1u << 3), 0262 0263 /** 0264 * Recursively make all components of the repo and workdir paths as 0265 * necessary. 0266 */ 0267 GIT_REPOSITORY_INIT_MKPATH = (1u << 4), 0268 0269 /** 0270 * libgit2 normally uses internal templates to initialize a new repo. 0271 * This flags enables external templates, looking the "template_path" from 0272 * the options if set, or the `init.templatedir` global config if not, 0273 * or falling back on "/usr/share/git-core/templates" if it exists. 0274 */ 0275 GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1u << 5), 0276 0277 /** 0278 * If an alternate workdir is specified, use relative paths for the gitdir 0279 * and core.worktree. 0280 */ 0281 GIT_REPOSITORY_INIT_RELATIVE_GITLINK = (1u << 6) 0282 } git_repository_init_flag_t; 0283 0284 /** 0285 * Mode options for `git_repository_init_ext`. 0286 * 0287 * Set the mode field of the `git_repository_init_options` structure 0288 * either to the custom mode that you would like, or to one of the 0289 * defined modes. 0290 */ 0291 typedef enum { 0292 /** 0293 * Use permissions configured by umask - the default. 0294 */ 0295 GIT_REPOSITORY_INIT_SHARED_UMASK = 0, 0296 0297 /** 0298 * Use "--shared=group" behavior, chmod'ing the new repo to be group 0299 * writable and "g+sx" for sticky group assignment. 0300 */ 0301 GIT_REPOSITORY_INIT_SHARED_GROUP = 0002775, 0302 0303 /** 0304 * Use "--shared=all" behavior, adding world readability. 0305 */ 0306 GIT_REPOSITORY_INIT_SHARED_ALL = 0002777 0307 } git_repository_init_mode_t; 0308 0309 /** 0310 * Extended options structure for `git_repository_init_ext`. 0311 * 0312 * This contains extra options for `git_repository_init_ext` that enable 0313 * additional initialization features. 0314 */ 0315 typedef struct { 0316 unsigned int version; 0317 0318 /** 0319 * Combination of GIT_REPOSITORY_INIT flags above. 0320 */ 0321 uint32_t flags; 0322 0323 /** 0324 * Set to one of the standard GIT_REPOSITORY_INIT_SHARED_... constants 0325 * above, or to a custom value that you would like. 0326 */ 0327 uint32_t mode; 0328 0329 /** 0330 * The path to the working dir or NULL for default (i.e. repo_path parent 0331 * on non-bare repos). IF THIS IS RELATIVE PATH, IT WILL BE EVALUATED 0332 * RELATIVE TO THE REPO_PATH. If this is not the "natural" working 0333 * directory, a .git gitlink file will be created here linking to the 0334 * repo_path. 0335 */ 0336 const char *workdir_path; 0337 0338 /** 0339 * If set, this will be used to initialize the "description" file in the 0340 * repository, instead of using the template content. 0341 */ 0342 const char *description; 0343 0344 /** 0345 * When GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set, this contains 0346 * the path to use for the template directory. If this is NULL, the config 0347 * or default directory options will be used instead. 0348 */ 0349 const char *template_path; 0350 0351 /** 0352 * The name of the head to point HEAD at. If NULL, then this will be 0353 * treated as "master" and the HEAD ref will be set to "refs/heads/master". 0354 * If this begins with "refs/" it will be used verbatim; 0355 * otherwise "refs/heads/" will be prefixed. 0356 */ 0357 const char *initial_head; 0358 0359 /** 0360 * If this is non-NULL, then after the rest of the repository 0361 * initialization is completed, an "origin" remote will be added 0362 * pointing to this URL. 0363 */ 0364 const char *origin_url; 0365 0366 #ifdef GIT_EXPERIMENTAL_SHA256 0367 /** 0368 * 0369 * Type of object IDs to use for this repository, or 0 for 0370 * default (currently SHA1). 0371 */ 0372 git_oid_t oid_type; 0373 #endif 0374 } git_repository_init_options; 0375 0376 #define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1 0377 #define GIT_REPOSITORY_INIT_OPTIONS_INIT {GIT_REPOSITORY_INIT_OPTIONS_VERSION} 0378 0379 /** 0380 * Initialize git_repository_init_options structure 0381 * 0382 * Initializes a `git_repository_init_options` with default values. Equivalent to 0383 * creating an instance with `GIT_REPOSITORY_INIT_OPTIONS_INIT`. 0384 * 0385 * @param opts The `git_repository_init_options` struct to initialize. 0386 * @param version The struct version; pass `GIT_REPOSITORY_INIT_OPTIONS_VERSION`. 0387 * @return Zero on success; -1 on failure. 0388 */ 0389 GIT_EXTERN(int) git_repository_init_options_init( 0390 git_repository_init_options *opts, 0391 unsigned int version); 0392 0393 /** 0394 * Create a new Git repository in the given folder with extended controls. 0395 * 0396 * This will initialize a new git repository (creating the repo_path 0397 * if requested by flags) and working directory as needed. It will 0398 * auto-detect the case sensitivity of the file system and if the 0399 * file system supports file mode bits correctly. 0400 * 0401 * @param out Pointer to the repo which will be created or reinitialized. 0402 * @param repo_path The path to the repository. 0403 * @param opts Pointer to git_repository_init_options struct. 0404 * @return 0 or an error code on failure. 0405 */ 0406 GIT_EXTERN(int) git_repository_init_ext( 0407 git_repository **out, 0408 const char *repo_path, 0409 git_repository_init_options *opts); 0410 0411 /** 0412 * Retrieve and resolve the reference pointed at by HEAD. 0413 * 0414 * The returned `git_reference` will be owned by caller and 0415 * `git_reference_free()` must be called when done with it to release the 0416 * allocated memory and prevent a leak. 0417 * 0418 * @param out pointer to the reference which will be retrieved 0419 * @param repo a repository object 0420 * 0421 * @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing 0422 * branch, GIT_ENOTFOUND when HEAD is missing; an error code otherwise 0423 */ 0424 GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo); 0425 0426 /** 0427 * Retrieve the referenced HEAD for the worktree 0428 * 0429 * @param out pointer to the reference which will be retrieved 0430 * @param repo a repository object 0431 * @param name name of the worktree to retrieve HEAD for 0432 * @return 0 when successful, error-code otherwise 0433 */ 0434 GIT_EXTERN(int) git_repository_head_for_worktree(git_reference **out, git_repository *repo, 0435 const char *name); 0436 0437 /** 0438 * Check if a repository's HEAD is detached 0439 * 0440 * A repository's HEAD is detached when it points directly to a commit 0441 * instead of a branch. 0442 * 0443 * @param repo Repo to test 0444 * @return 1 if HEAD is detached, 0 if it's not; error code if there 0445 * was an error. 0446 */ 0447 GIT_EXTERN(int) git_repository_head_detached(git_repository *repo); 0448 0449 /** 0450 * Check if a worktree's HEAD is detached 0451 * 0452 * A worktree's HEAD is detached when it points directly to a 0453 * commit instead of a branch. 0454 * 0455 * @param repo a repository object 0456 * @param name name of the worktree to retrieve HEAD for 0457 * @return 1 if HEAD is detached, 0 if its not; error code if 0458 * there was an error 0459 */ 0460 GIT_EXTERN(int) git_repository_head_detached_for_worktree(git_repository *repo, 0461 const char *name); 0462 0463 /** 0464 * Check if the current branch is unborn 0465 * 0466 * An unborn branch is one named from HEAD but which doesn't exist in 0467 * the refs namespace, because it doesn't have any commit to point to. 0468 * 0469 * @param repo Repo to test 0470 * @return 1 if the current branch is unborn, 0 if it's not; error 0471 * code if there was an error 0472 */ 0473 GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo); 0474 0475 /** 0476 * Check if a repository is empty 0477 * 0478 * An empty repository has just been initialized and contains no references 0479 * apart from HEAD, which must be pointing to the unborn master branch, 0480 * or the branch specified for the repository in the `init.defaultBranch` 0481 * configuration variable. 0482 * 0483 * @param repo Repo to test 0484 * @return 1 if the repository is empty, 0 if it isn't, error code 0485 * if the repository is corrupted 0486 */ 0487 GIT_EXTERN(int) git_repository_is_empty(git_repository *repo); 0488 0489 /** 0490 * List of items which belong to the git repository layout 0491 */ 0492 typedef enum { 0493 GIT_REPOSITORY_ITEM_GITDIR, 0494 GIT_REPOSITORY_ITEM_WORKDIR, 0495 GIT_REPOSITORY_ITEM_COMMONDIR, 0496 GIT_REPOSITORY_ITEM_INDEX, 0497 GIT_REPOSITORY_ITEM_OBJECTS, 0498 GIT_REPOSITORY_ITEM_REFS, 0499 GIT_REPOSITORY_ITEM_PACKED_REFS, 0500 GIT_REPOSITORY_ITEM_REMOTES, 0501 GIT_REPOSITORY_ITEM_CONFIG, 0502 GIT_REPOSITORY_ITEM_INFO, 0503 GIT_REPOSITORY_ITEM_HOOKS, 0504 GIT_REPOSITORY_ITEM_LOGS, 0505 GIT_REPOSITORY_ITEM_MODULES, 0506 GIT_REPOSITORY_ITEM_WORKTREES, 0507 GIT_REPOSITORY_ITEM_WORKTREE_CONFIG, 0508 GIT_REPOSITORY_ITEM__LAST 0509 } git_repository_item_t; 0510 0511 /** 0512 * Get the location of a specific repository file or directory 0513 * 0514 * This function will retrieve the path of a specific repository 0515 * item. It will thereby honor things like the repository's 0516 * common directory, gitdir, etc. In case a file path cannot 0517 * exist for a given item (e.g. the working directory of a bare 0518 * repository), GIT_ENOTFOUND is returned. 0519 * 0520 * @param out Buffer to store the path at 0521 * @param repo Repository to get path for 0522 * @param item The repository item for which to retrieve the path 0523 * @return 0, GIT_ENOTFOUND if the path cannot exist or an error code 0524 */ 0525 GIT_EXTERN(int) git_repository_item_path(git_buf *out, const git_repository *repo, git_repository_item_t item); 0526 0527 /** 0528 * Get the path of this repository 0529 * 0530 * This is the path of the `.git` folder for normal repositories, 0531 * or of the repository itself for bare repositories. 0532 * 0533 * @param repo A repository object 0534 * @return the path to the repository 0535 */ 0536 GIT_EXTERN(const char *) git_repository_path(const git_repository *repo); 0537 0538 /** 0539 * Get the path of the working directory for this repository 0540 * 0541 * If the repository is bare, this function will always return 0542 * NULL. 0543 * 0544 * @param repo A repository object 0545 * @return the path to the working dir, if it exists 0546 */ 0547 GIT_EXTERN(const char *) git_repository_workdir(const git_repository *repo); 0548 0549 /** 0550 * Get the path of the shared common directory for this repository. 0551 * 0552 * If the repository is bare, it is the root directory for the repository. 0553 * If the repository is a worktree, it is the parent repo's gitdir. 0554 * Otherwise, it is the gitdir. 0555 * 0556 * @param repo A repository object 0557 * @return the path to the common dir 0558 */ 0559 GIT_EXTERN(const char *) git_repository_commondir(const git_repository *repo); 0560 0561 /** 0562 * Set the path to the working directory for this repository 0563 * 0564 * The working directory doesn't need to be the same one 0565 * that contains the `.git` folder for this repository. 0566 * 0567 * If this repository is bare, setting its working directory 0568 * will turn it into a normal repository, capable of performing 0569 * all the common workdir operations (checkout, status, index 0570 * manipulation, etc). 0571 * 0572 * @param repo A repository object 0573 * @param workdir The path to a working directory 0574 * @param update_gitlink Create/update gitlink in workdir and set config 0575 * "core.worktree" (if workdir is not the parent of the .git directory) 0576 * @return 0, or an error code 0577 */ 0578 GIT_EXTERN(int) git_repository_set_workdir( 0579 git_repository *repo, const char *workdir, int update_gitlink); 0580 0581 /** 0582 * Check if a repository is bare 0583 * 0584 * @param repo Repo to test 0585 * @return 1 if the repository is bare, 0 otherwise. 0586 */ 0587 GIT_EXTERN(int) git_repository_is_bare(const git_repository *repo); 0588 0589 /** 0590 * Check if a repository is a linked work tree 0591 * 0592 * @param repo Repo to test 0593 * @return 1 if the repository is a linked work tree, 0 otherwise. 0594 */ 0595 GIT_EXTERN(int) git_repository_is_worktree(const git_repository *repo); 0596 0597 /** 0598 * Get the configuration file for this repository. 0599 * 0600 * If a configuration file has not been set, the default 0601 * config set for the repository will be returned, including 0602 * global and system configurations (if they are available). 0603 * 0604 * The configuration file must be freed once it's no longer 0605 * being used by the user. 0606 * 0607 * @param out Pointer to store the loaded configuration 0608 * @param repo A repository object 0609 * @return 0, or an error code 0610 */ 0611 GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo); 0612 0613 /** 0614 * Get a snapshot of the repository's configuration 0615 * 0616 * Convenience function to take a snapshot from the repository's 0617 * configuration. The contents of this snapshot will not change, 0618 * even if the underlying config files are modified. 0619 * 0620 * The configuration file must be freed once it's no longer 0621 * being used by the user. 0622 * 0623 * @param out Pointer to store the loaded configuration 0624 * @param repo the repository 0625 * @return 0, or an error code 0626 */ 0627 GIT_EXTERN(int) git_repository_config_snapshot(git_config **out, git_repository *repo); 0628 0629 /** 0630 * Get the Object Database for this repository. 0631 * 0632 * If a custom ODB has not been set, the default 0633 * database for the repository will be returned (the one 0634 * located in `.git/objects`). 0635 * 0636 * The ODB must be freed once it's no longer being used by 0637 * the user. 0638 * 0639 * @param out Pointer to store the loaded ODB 0640 * @param repo A repository object 0641 * @return 0, or an error code 0642 */ 0643 GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo); 0644 0645 /** 0646 * Get the Reference Database Backend for this repository. 0647 * 0648 * If a custom refsdb has not been set, the default database for 0649 * the repository will be returned (the one that manipulates loose 0650 * and packed references in the `.git` directory). 0651 * 0652 * The refdb must be freed once it's no longer being used by 0653 * the user. 0654 * 0655 * @param out Pointer to store the loaded refdb 0656 * @param repo A repository object 0657 * @return 0, or an error code 0658 */ 0659 GIT_EXTERN(int) git_repository_refdb(git_refdb **out, git_repository *repo); 0660 0661 /** 0662 * Get the Index file for this repository. 0663 * 0664 * If a custom index has not been set, the default 0665 * index for the repository will be returned (the one 0666 * located in `.git/index`). 0667 * 0668 * The index must be freed once it's no longer being used by 0669 * the user. 0670 * 0671 * @param out Pointer to store the loaded index 0672 * @param repo A repository object 0673 * @return 0, or an error code 0674 */ 0675 GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo); 0676 0677 /** 0678 * Retrieve git's prepared message 0679 * 0680 * Operations such as git revert/cherry-pick/merge with the -n option 0681 * stop just short of creating a commit with the changes and save 0682 * their prepared message in .git/MERGE_MSG so the next git-commit 0683 * execution can present it to the user for them to amend if they 0684 * wish. 0685 * 0686 * Use this function to get the contents of this file. Don't forget to 0687 * remove the file after you create the commit. 0688 * 0689 * @param out git_buf to write data into 0690 * @param repo Repository to read prepared message from 0691 * @return 0, GIT_ENOTFOUND if no message exists or an error code 0692 */ 0693 GIT_EXTERN(int) git_repository_message(git_buf *out, git_repository *repo); 0694 0695 /** 0696 * Remove git's prepared message. 0697 * 0698 * Remove the message that `git_repository_message` retrieves. 0699 * 0700 * @param repo Repository to remove prepared message from. 0701 * @return 0 or an error code. 0702 */ 0703 GIT_EXTERN(int) git_repository_message_remove(git_repository *repo); 0704 0705 /** 0706 * Remove all the metadata associated with an ongoing command like merge, 0707 * revert, cherry-pick, etc. For example: MERGE_HEAD, MERGE_MSG, etc. 0708 * 0709 * @param repo A repository object 0710 * @return 0 on success, or error 0711 */ 0712 GIT_EXTERN(int) git_repository_state_cleanup(git_repository *repo); 0713 0714 /** 0715 * Callback used to iterate over each FETCH_HEAD entry 0716 * 0717 * @see git_repository_fetchhead_foreach 0718 * 0719 * @param ref_name The reference name 0720 * @param remote_url The remote URL 0721 * @param oid The reference target OID 0722 * @param is_merge Was the reference the result of a merge 0723 * @param payload Payload passed to git_repository_fetchhead_foreach 0724 * @return non-zero to terminate the iteration 0725 */ 0726 typedef int GIT_CALLBACK(git_repository_fetchhead_foreach_cb)(const char *ref_name, 0727 const char *remote_url, 0728 const git_oid *oid, 0729 unsigned int is_merge, 0730 void *payload); 0731 0732 /** 0733 * Invoke 'callback' for each entry in the given FETCH_HEAD file. 0734 * 0735 * Return a non-zero value from the callback to stop the loop. 0736 * 0737 * @param repo A repository object 0738 * @param callback Callback function 0739 * @param payload Pointer to callback data (optional) 0740 * @return 0 on success, non-zero callback return value, GIT_ENOTFOUND if 0741 * there is no FETCH_HEAD file, or other error code. 0742 */ 0743 GIT_EXTERN(int) git_repository_fetchhead_foreach( 0744 git_repository *repo, 0745 git_repository_fetchhead_foreach_cb callback, 0746 void *payload); 0747 0748 /** 0749 * Callback used to iterate over each MERGE_HEAD entry 0750 * 0751 * @see git_repository_mergehead_foreach 0752 * 0753 * @param oid The merge OID 0754 * @param payload Payload passed to git_repository_mergehead_foreach 0755 * @return non-zero to terminate the iteration 0756 */ 0757 typedef int GIT_CALLBACK(git_repository_mergehead_foreach_cb)(const git_oid *oid, 0758 void *payload); 0759 0760 /** 0761 * If a merge is in progress, invoke 'callback' for each commit ID in the 0762 * MERGE_HEAD file. 0763 * 0764 * Return a non-zero value from the callback to stop the loop. 0765 * 0766 * @param repo A repository object 0767 * @param callback Callback function 0768 * @param payload Pointer to callback data (optional) 0769 * @return 0 on success, non-zero callback return value, GIT_ENOTFOUND if 0770 * there is no MERGE_HEAD file, or other error code. 0771 */ 0772 GIT_EXTERN(int) git_repository_mergehead_foreach( 0773 git_repository *repo, 0774 git_repository_mergehead_foreach_cb callback, 0775 void *payload); 0776 0777 /** 0778 * Calculate hash of file using repository filtering rules. 0779 * 0780 * If you simply want to calculate the hash of a file on disk with no filters, 0781 * you can just use the `git_odb_hashfile()` API. However, if you want to 0782 * hash a file in the repository and you want to apply filtering rules (e.g. 0783 * crlf filters) before generating the SHA, then use this function. 0784 * 0785 * Note: if the repository has `core.safecrlf` set to fail and the 0786 * filtering triggers that failure, then this function will return an 0787 * error and not calculate the hash of the file. 0788 * 0789 * @param out Output value of calculated SHA 0790 * @param repo Repository pointer 0791 * @param path Path to file on disk whose contents should be hashed. This 0792 * may be an absolute path or a relative path, in which case it 0793 * will be treated as a path within the working directory. 0794 * @param type The object type to hash as (e.g. GIT_OBJECT_BLOB) 0795 * @param as_path The path to use to look up filtering rules. If this is 0796 * an empty string then no filters will be applied when 0797 * calculating the hash. If this is `NULL` and the `path` 0798 * parameter is a file within the repository's working 0799 * directory, then the `path` will be used. 0800 * @return 0 on success, or an error code 0801 */ 0802 GIT_EXTERN(int) git_repository_hashfile( 0803 git_oid *out, 0804 git_repository *repo, 0805 const char *path, 0806 git_object_t type, 0807 const char *as_path); 0808 0809 /** 0810 * Make the repository HEAD point to the specified reference. 0811 * 0812 * If the provided reference points to a Tree or a Blob, the HEAD is 0813 * unaltered and -1 is returned. 0814 * 0815 * If the provided reference points to a branch, the HEAD will point 0816 * to that branch, staying attached, or become attached if it isn't yet. 0817 * If the branch doesn't exist yet, no error will be return. The HEAD 0818 * will then be attached to an unborn branch. 0819 * 0820 * Otherwise, the HEAD will be detached and will directly point to 0821 * the Commit. 0822 * 0823 * @param repo Repository pointer 0824 * @param refname Canonical name of the reference the HEAD should point at 0825 * @return 0 on success, or an error code 0826 */ 0827 GIT_EXTERN(int) git_repository_set_head( 0828 git_repository *repo, 0829 const char *refname); 0830 0831 /** 0832 * Make the repository HEAD directly point to the Commit. 0833 * 0834 * If the provided committish cannot be found in the repository, the HEAD 0835 * is unaltered and GIT_ENOTFOUND is returned. 0836 * 0837 * If the provided committish cannot be peeled into a commit, the HEAD 0838 * is unaltered and -1 is returned. 0839 * 0840 * Otherwise, the HEAD will eventually be detached and will directly point to 0841 * the peeled Commit. 0842 * 0843 * @param repo Repository pointer 0844 * @param committish Object id of the Commit the HEAD should point to 0845 * @return 0 on success, or an error code 0846 */ 0847 GIT_EXTERN(int) git_repository_set_head_detached( 0848 git_repository *repo, 0849 const git_oid *committish); 0850 0851 /** 0852 * Make the repository HEAD directly point to the Commit. 0853 * 0854 * This behaves like `git_repository_set_head_detached()` but takes an 0855 * annotated commit, which lets you specify which extended sha syntax 0856 * string was specified by a user, allowing for more exact reflog 0857 * messages. 0858 * 0859 * See the documentation for `git_repository_set_head_detached()`. 0860 * 0861 * @see git_repository_set_head_detached 0862 */ 0863 GIT_EXTERN(int) git_repository_set_head_detached_from_annotated( 0864 git_repository *repo, 0865 const git_annotated_commit *committish); 0866 0867 /** 0868 * Detach the HEAD. 0869 * 0870 * If the HEAD is already detached and points to a Commit, 0 is returned. 0871 * 0872 * If the HEAD is already detached and points to a Tag, the HEAD is 0873 * updated into making it point to the peeled Commit, and 0 is returned. 0874 * 0875 * If the HEAD is already detached and points to a non committish, the HEAD is 0876 * unaltered, and -1 is returned. 0877 * 0878 * Otherwise, the HEAD will be detached and point to the peeled Commit. 0879 * 0880 * @param repo Repository pointer 0881 * @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing 0882 * branch or an error code 0883 */ 0884 GIT_EXTERN(int) git_repository_detach_head( 0885 git_repository *repo); 0886 0887 /** 0888 * Repository state 0889 * 0890 * These values represent possible states for the repository to be in, 0891 * based on the current operation which is ongoing. 0892 */ 0893 typedef enum { 0894 GIT_REPOSITORY_STATE_NONE, 0895 GIT_REPOSITORY_STATE_MERGE, 0896 GIT_REPOSITORY_STATE_REVERT, 0897 GIT_REPOSITORY_STATE_REVERT_SEQUENCE, 0898 GIT_REPOSITORY_STATE_CHERRYPICK, 0899 GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE, 0900 GIT_REPOSITORY_STATE_BISECT, 0901 GIT_REPOSITORY_STATE_REBASE, 0902 GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, 0903 GIT_REPOSITORY_STATE_REBASE_MERGE, 0904 GIT_REPOSITORY_STATE_APPLY_MAILBOX, 0905 GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE 0906 } git_repository_state_t; 0907 0908 /** 0909 * Determines the status of a git repository - ie, whether an operation 0910 * (merge, cherry-pick, etc) is in progress. 0911 * 0912 * @param repo Repository pointer 0913 * @return The state of the repository 0914 */ 0915 GIT_EXTERN(int) git_repository_state(git_repository *repo); 0916 0917 /** 0918 * Sets the active namespace for this Git Repository 0919 * 0920 * This namespace affects all reference operations for the repo. 0921 * See `man gitnamespaces` 0922 * 0923 * @param repo The repo 0924 * @param nmspace The namespace. This should not include the refs 0925 * folder, e.g. to namespace all references under `refs/namespaces/foo/`, 0926 * use `foo` as the namespace. 0927 * @return 0 on success, -1 on error 0928 */ 0929 GIT_EXTERN(int) git_repository_set_namespace(git_repository *repo, const char *nmspace); 0930 0931 /** 0932 * Get the currently active namespace for this repository 0933 * 0934 * @param repo The repo 0935 * @return the active namespace, or NULL if there isn't one 0936 */ 0937 GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo); 0938 0939 0940 /** 0941 * Determine if the repository was a shallow clone 0942 * 0943 * @param repo The repository 0944 * @return 1 if shallow, zero if not 0945 */ 0946 GIT_EXTERN(int) git_repository_is_shallow(git_repository *repo); 0947 0948 /** 0949 * Retrieve the configured identity to use for reflogs 0950 * 0951 * The memory is owned by the repository and must not be freed by the 0952 * user. 0953 * 0954 * @param name where to store the pointer to the name 0955 * @param email where to store the pointer to the email 0956 * @param repo the repository 0957 * @return 0 or an error code 0958 */ 0959 GIT_EXTERN(int) git_repository_ident(const char **name, const char **email, const git_repository *repo); 0960 0961 /** 0962 * Set the identity to be used for writing reflogs 0963 * 0964 * If both are set, this name and email will be used to write to the 0965 * reflog. Pass NULL to unset. When unset, the identity will be taken 0966 * from the repository's configuration. 0967 * 0968 * @param repo the repository to configure 0969 * @param name the name to use for the reflog entries 0970 * @param email the email to use for the reflog entries 0971 * @return 0 or an error code. 0972 */ 0973 GIT_EXTERN(int) git_repository_set_ident(git_repository *repo, const char *name, const char *email); 0974 0975 /** 0976 * Gets the object type used by this repository. 0977 * 0978 * @param repo the repository 0979 * @return the object id type 0980 */ 0981 GIT_EXTERN(git_oid_t) git_repository_oid_type(git_repository *repo); 0982 0983 /** 0984 * Gets the parents of the next commit, given the current repository state. 0985 * Generally, this is the HEAD commit, except when performing a merge, in 0986 * which case it is two or more commits. 0987 * 0988 * @param commits a `git_commitarray` that will contain the commit parents 0989 * @param repo the repository 0990 * @return 0 or an error code 0991 */ 0992 GIT_EXTERN(int) git_repository_commit_parents(git_commitarray *commits, git_repository *repo); 0993 0994 /** @} */ 0995 GIT_END_DECL 0996 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |