1 #ifndef REFS_REFS_INTERNAL_H
2 #define REFS_REFS_INTERNAL_H
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.
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).
14 #define REF_DELETING 0x02
17 * Used as a flag in ref_update::flags when a loose ref is being
20 #define REF_ISPRUNING 0x04
23 * Used as a flag in ref_update::flags when the reference should be
24 * updated to new_sha1.
26 #define REF_HAVE_NEW 0x08
29 * Used as a flag in ref_update::flags when old_sha1 should be
32 #define REF_HAVE_OLD 0x10
35 * Used as a flag in ref_update::flags when the lockfile needs to be
38 #define REF_NEEDS_COMMIT 0x20
41 * 0x40 is REF_FORCE_CREATE_REFLOG, so skip it if you're adding a
42 * value to ref_update::flags
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().
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").
58 int refname_is_safe(const char *refname);
61 /* object was peeled successfully: */
65 * object cannot be peeled because the named object (or an
66 * object referred to by a tag in the peel chain), does not
71 /* object cannot be peeled because it is not a tag: */
74 /* ref_entry contains no peeled value because it is a symref: */
78 * ref_entry cannot be peeled because it is broken (i.e., the
79 * symbolic reference cannot even be resolved to an object
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.
92 enum peel_status peel_object(const unsigned char *name, unsigned char *sha1);
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.
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
109 * extras and skip must be sorted.
111 int verify_refname_available(const char *newname,
112 struct string_list *extras,
113 struct string_list *skip,
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.
121 int copy_reflog_msg(char *buf, const char *msg);
123 int should_autocreate_reflog(const char *refname);
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.
134 * If (flags & REF_HAVE_NEW), set the reference to this value:
136 unsigned char new_sha1[20];
138 * If (flags & REF_HAVE_OLD), check that the reference
139 * previously had this value:
141 unsigned char old_sha1[20];
143 * One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF,
144 * REF_DELETING, and REF_ISPRUNING:
147 struct ref_lock *lock;
150 const char refname[FLEX_ARRAY];
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.
163 enum ref_transaction_state {
164 REF_TRANSACTION_OPEN = 0,
165 REF_TRANSACTION_CLOSED = 1
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.
173 struct ref_transaction {
174 struct ref_update **updates;
177 enum ref_transaction_state state;
180 int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
181 const unsigned char *new_sha1, const char *msg,
182 int flags, struct strbuf *err);
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.
191 * extras and skip must be sorted lists of reference names. Either one
192 * can be NULL, signifying the empty list.
194 const char *find_descendant_ref(const char *dirname,
195 const struct string_list *extras,
196 const struct string_list *skip);
198 int rename_ref_available(const char *oldname, const char *newname);
200 /* We allow "recursive" symbolic refs. Only within reason, though */
201 #define SYMREF_MAXDEPTH 5
203 /* Include broken references in a do_for_each_ref*() iteration: */
204 #define DO_FOR_EACH_INCLUDE_BROKEN 0x01
207 * The common backend for the for_each_*ref* functions
209 int do_for_each_ref(const char *submodule, const char *base,
210 each_ref_fn fn, int trim, int flags, void *cb_data);
212 int read_raw_ref(const char *refname, unsigned char *sha1,
213 struct strbuf *symref, unsigned int *flags);
215 #endif /* REFS_REFS_INTERNAL_H */