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 #ifndef INCLUDE_git_transaction_h__ 8 #define INCLUDE_git_transaction_h__ 9 10 #include "common.h" 11 #include "types.h" 12 13 /** 14 * @file git2/transaction.h 15 * @brief Git transactional reference routines 16 * @defgroup git_transaction Git transactional reference routines 17 * @ingroup Git 18 * @{ 19 */ 20 GIT_BEGIN_DECL 21 22 /** 23 * Create a new transaction object 24 * 25 * This does not lock anything, but sets up the transaction object to 26 * know from which repository to lock. 27 * 28 * @param out the resulting transaction 29 * @param repo the repository in which to lock 30 * @return 0 or an error code 31 */ 32 GIT_EXTERN(int) git_transaction_new(git_transaction **out, git_repository *repo); 33 34 /** 35 * Lock a reference 36 * 37 * Lock the specified reference. This is the first step to updating a 38 * reference. 39 * 40 * @param tx the transaction 41 * @param refname the reference to lock 42 * @return 0 or an error message 43 */ 44 GIT_EXTERN(int) git_transaction_lock_ref(git_transaction *tx, const char *refname); 45 46 /** 47 * Set the target of a reference 48 * 49 * Set the target of the specified reference. This reference must be 50 * locked. 51 * 52 * @param tx the transaction 53 * @param refname reference to update 54 * @param target target to set the reference to 55 * @param sig signature to use in the reflog; pass NULL to read the identity from the config 56 * @param msg message to use in the reflog 57 * @return 0, GIT_ENOTFOUND if the reference is not among the locked ones, or an error code 58 */ 59 GIT_EXTERN(int) git_transaction_set_target(git_transaction *tx, const char *refname, const git_oid *target, const git_signature *sig, const char *msg); 60 61 /** 62 * Set the target of a reference 63 * 64 * Set the target of the specified reference. This reference must be 65 * locked. 66 * 67 * @param tx the transaction 68 * @param refname reference to update 69 * @param target target to set the reference to 70 * @param sig signature to use in the reflog; pass NULL to read the identity from the config 71 * @param msg message to use in the reflog 72 * @return 0, GIT_ENOTFOUND if the reference is not among the locked ones, or an error code 73 */ 74 GIT_EXTERN(int) git_transaction_set_symbolic_target(git_transaction *tx, const char *refname, const char *target, const git_signature *sig, const char *msg); 75 76 /** 77 * Set the reflog of a reference 78 * 79 * Set the specified reference's reflog. If this is combined with 80 * setting the target, that update won't be written to the reflog. 81 * 82 * @param tx the transaction 83 * @param refname the reference whose reflog to set 84 * @param reflog the reflog as it should be written out 85 * @return 0, GIT_ENOTFOUND if the reference is not among the locked ones, or an error code 86 */ 87 GIT_EXTERN(int) git_transaction_set_reflog(git_transaction *tx, const char *refname, const git_reflog *reflog); 88 89 /** 90 * Remove a reference 91 * 92 * @param tx the transaction 93 * @param refname the reference to remove 94 * @return 0, GIT_ENOTFOUND if the reference is not among the locked ones, or an error code 95 */ 96 GIT_EXTERN(int) git_transaction_remove(git_transaction *tx, const char *refname); 97 98 /** 99 * Commit the changes from the transaction 100 * 101 * Perform the changes that have been queued. The updates will be made 102 * one by one, and the first failure will stop the processing. 103 * 104 * @param tx the transaction 105 * @return 0 or an error code 106 */ 107 GIT_EXTERN(int) git_transaction_commit(git_transaction *tx); 108 109 /** 110 * Free the resources allocated by this transaction 111 * 112 * If any references remain locked, they will be unlocked without any 113 * changes made to them. 114 * 115 * @param tx the transaction 116 */ 117 GIT_EXTERN(void) git_transaction_free(git_transaction *tx); 118 119 /** @} */ 120 GIT_END_DECL 121 #endif 122