1#ifndef REFS_REFS_INTERNAL_H 2#define REFS_REFS_INTERNAL_H 3 4/* 5 * Data structures and functions for the internal use of the refs 6 * module. Code outside of the refs module should use only the public 7 * functions defined in "refs.h", and should *not* include this file. 8 */ 9 10/* 11 * Flag passed to lock_ref_sha1_basic() telling it to tolerate broken 12 * refs (i.e., because the reference is about to be deleted anyway). 13 */ 14#define REF_DELETING 0x02 15 16/* 17 * Used as a flag in ref_update::flags when a loose ref is being 18 * pruned. 19 */ 20#define REF_ISPRUNING 0x04 21 22/* 23 * Used as a flag in ref_update::flags when the reference should be 24 * updated to new_sha1. 25 */ 26#define REF_HAVE_NEW 0x08 27 28/* 29 * Used as a flag in ref_update::flags when old_sha1 should be 30 * checked. 31 */ 32#define REF_HAVE_OLD 0x10 33 34/* 35 * Used as a flag in ref_update::flags when the lockfile needs to be 36 * committed. 37 */ 38#define REF_NEEDS_COMMIT 0x20 39 40/* 41 * 0x40 is REF_FORCE_CREATE_REFLOG, so skip it if you're adding a 42 * value to ref_update::flags 43 */ 44 45/* 46 * Return true iff refname is minimally safe. "Safe" here means that 47 * deleting a loose reference by this name will not do any damage, for 48 * example by causing a file that is not a reference to be deleted. 49 * This function does not check that the reference name is legal; for 50 * that, use check_refname_format(). 51 * 52 * We consider a refname that starts with "refs/" to be safe as long 53 * as any ".." components that it might contain do not escape "refs/". 54 * Names that do not start with "refs/" are considered safe iff they 55 * consist entirely of upper case characters and '_' (like "HEAD" and 56 * "MERGE_HEAD" but not "config" or "FOO/BAR"). 57 */ 58intrefname_is_safe(const char*refname); 59 60enum peel_status { 61/* object was peeled successfully: */ 62 PEEL_PEELED =0, 63 64/* 65 * object cannot be peeled because the named object (or an 66 * object referred to by a tag in the peel chain), does not 67 * exist. 68 */ 69 PEEL_INVALID = -1, 70 71/* object cannot be peeled because it is not a tag: */ 72 PEEL_NON_TAG = -2, 73 74/* ref_entry contains no peeled value because it is a symref: */ 75 PEEL_IS_SYMREF = -3, 76 77/* 78 * ref_entry cannot be peeled because it is broken (i.e., the 79 * symbolic reference cannot even be resolved to an object 80 * name): 81 */ 82 PEEL_BROKEN = -4 83}; 84 85/* 86 * Peel the named object; i.e., if the object is a tag, resolve the 87 * tag recursively until a non-tag is found. If successful, store the 88 * result to sha1 and return PEEL_PEELED. If the object is not a tag 89 * or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively, 90 * and leave sha1 unchanged. 91 */ 92enum peel_status peel_object(const unsigned char*name,unsigned char*sha1); 93 94/* 95 * Return 0 if a reference named refname could be created without 96 * conflicting with the name of an existing reference. Otherwise, 97 * return a negative value and write an explanation to err. If extras 98 * is non-NULL, it is a list of additional refnames with which refname 99 * is not allowed to conflict. If skip is non-NULL, ignore potential 100 * conflicts with refs in skip (e.g., because they are scheduled for 101 * deletion in the same operation). Behavior is undefined if the same 102 * name is listed in both extras and skip. 103 * 104 * Two reference names conflict if one of them exactly matches the 105 * leading components of the other; e.g., "foo/bar" conflicts with 106 * both "foo" and with "foo/bar/baz" but not with "foo/bar" or 107 * "foo/barbados". 108 * 109 * extras and skip must be sorted. 110 */ 111intverify_refname_available(const char*newname, 112struct string_list *extras, 113struct string_list *skip, 114struct strbuf *err); 115 116/* 117 * Copy the reflog message msg to buf, which has been allocated sufficiently 118 * large, while cleaning up the whitespaces. Especially, convert LF to space, 119 * because reflog file is one line per entry. 120 */ 121intcopy_reflog_msg(char*buf,const char*msg); 122 123intshould_autocreate_reflog(const char*refname); 124 125/** 126 * Information needed for a single ref update. Set new_sha1 to the new 127 * value or to null_sha1 to delete the ref. To check the old value 128 * while the ref is locked, set (flags & REF_HAVE_OLD) and set 129 * old_sha1 to the old value, or to null_sha1 to ensure the ref does 130 * not exist before update. 131 */ 132struct ref_update { 133/* 134 * If (flags & REF_HAVE_NEW), set the reference to this value: 135 */ 136unsigned char new_sha1[20]; 137/* 138 * If (flags & REF_HAVE_OLD), check that the reference 139 * previously had this value: 140 */ 141unsigned char old_sha1[20]; 142/* 143 * One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF, 144 * REF_DELETING, and REF_ISPRUNING: 145 */ 146unsigned int flags; 147struct ref_lock *lock; 148int type; 149char*msg; 150const char refname[FLEX_ARRAY]; 151}; 152 153/* 154 * Transaction states. 155 * OPEN: The transaction is in a valid state and can accept new updates. 156 * An OPEN transaction can be committed. 157 * CLOSED: A closed transaction is no longer active and no other operations 158 * than free can be used on it in this state. 159 * A transaction can either become closed by successfully committing 160 * an active transaction or if there is a failure while building 161 * the transaction thus rendering it failed/inactive. 162 */ 163enum ref_transaction_state { 164 REF_TRANSACTION_OPEN =0, 165 REF_TRANSACTION_CLOSED =1 166}; 167 168/* 169 * Data structure for holding a reference transaction, which can 170 * consist of checks and updates to multiple references, carried out 171 * as atomically as possible. This structure is opaque to callers. 172 */ 173struct ref_transaction { 174struct ref_update **updates; 175size_t alloc; 176size_t nr; 177enum ref_transaction_state state; 178}; 179 180intfiles_log_ref_write(const char*refname,const unsigned char*old_sha1, 181const unsigned char*new_sha1,const char*msg, 182int flags,struct strbuf *err); 183 184/* 185 * Check for entries in extras that are within the specified 186 * directory, where dirname is a reference directory name including 187 * the trailing slash (e.g., "refs/heads/foo/"). Ignore any 188 * conflicting references that are found in skip. If there is a 189 * conflicting reference, return its name. 190 * 191 * extras and skip must be sorted lists of reference names. Either one 192 * can be NULL, signifying the empty list. 193 */ 194const char*find_descendant_ref(const char*dirname, 195const struct string_list *extras, 196const struct string_list *skip); 197 198intrename_ref_available(const char*oldname,const char*newname); 199 200#endif/* REFS_REFS_INTERNAL_H */