11#include "cache.h"
22#include "lockfile.h"
33#include "refs.h"
4+ #include "refs/refs-internal.h"
45#include "object.h"
56#include "tag.h"
67#include "dir.h"
@@ -34,41 +35,6 @@ static unsigned char refname_disposition[256] = {
3435 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 , 0 , 0 , 4 , 4
3536};
3637
37- /*
38- * Flag passed to lock_ref_sha1_basic() telling it to tolerate broken
39- * refs (i.e., because the reference is about to be deleted anyway).
40- */
41- #define REF_DELETING 0x02
42-
43- /*
44- * Used as a flag in ref_update::flags when a loose ref is being
45- * pruned.
46- */
47- #define REF_ISPRUNING 0x04
48-
49- /*
50- * Used as a flag in ref_update::flags when the reference should be
51- * updated to new_sha1.
52- */
53- #define REF_HAVE_NEW 0x08
54-
55- /*
56- * Used as a flag in ref_update::flags when old_sha1 should be
57- * checked.
58- */
59- #define REF_HAVE_OLD 0x10
60-
61- /*
62- * Used as a flag in ref_update::flags when the lockfile needs to be
63- * committed.
64- */
65- #define REF_NEEDS_COMMIT 0x20
66-
67- /*
68- * 0x40 is REF_FORCE_CREATE_REFLOG, so skip it if you're adding a
69- * value to ref_update::flags
70- */
71-
7238/*
7339 * Try to read one refname component from the front of refname.
7440 * Return the length of the component found, or -1 if the component is
@@ -340,20 +306,7 @@ static struct ref_dir *get_ref_dir(struct ref_entry *entry)
340306 return dir ;
341307}
342308
343- /*
344- * Return true iff refname is minimally safe. "Safe" here means that
345- * deleting a loose reference by this name will not do any damage, for
346- * example by causing a file that is not a reference to be deleted.
347- * This function does not check that the reference name is legal; for
348- * that, use check_refname_format().
349- *
350- * We consider a refname that starts with "refs/" to be safe as long
351- * as any ".." components that it might contain do not escape "refs/".
352- * Names that do not start with "refs/" are considered safe iff they
353- * consist entirely of upper case characters and '_' (like "HEAD" and
354- * "MERGE_HEAD" but not "config" or "FOO/BAR").
355- */
356- static int refname_is_safe (const char * refname )
309+ int refname_is_safe (const char * refname )
357310{
358311 if (starts_with (refname , "refs/" )) {
359312 char * buf ;
@@ -1823,39 +1776,7 @@ static int filter_refs(const char *refname, const struct object_id *oid,
18231776 return filter -> fn (refname , oid , flags , filter -> cb_data );
18241777}
18251778
1826- enum peel_status {
1827- /* object was peeled successfully: */
1828- PEEL_PEELED = 0 ,
1829-
1830- /*
1831- * object cannot be peeled because the named object (or an
1832- * object referred to by a tag in the peel chain), does not
1833- * exist.
1834- */
1835- PEEL_INVALID = -1 ,
1836-
1837- /* object cannot be peeled because it is not a tag: */
1838- PEEL_NON_TAG = -2 ,
1839-
1840- /* ref_entry contains no peeled value because it is a symref: */
1841- PEEL_IS_SYMREF = -3 ,
1842-
1843- /*
1844- * ref_entry cannot be peeled because it is broken (i.e., the
1845- * symbolic reference cannot even be resolved to an object
1846- * name):
1847- */
1848- PEEL_BROKEN = -4
1849- };
1850-
1851- /*
1852- * Peel the named object; i.e., if the object is a tag, resolve the
1853- * tag recursively until a non-tag is found. If successful, store the
1854- * result to sha1 and return PEEL_PEELED. If the object is not a tag
1855- * or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively,
1856- * and leave sha1 unchanged.
1857- */
1858- static enum peel_status peel_object (const unsigned char * name , unsigned char * sha1 )
1779+ enum peel_status peel_object (const unsigned char * name , unsigned char * sha1 )
18591780{
18601781 struct object * o = lookup_unknown_object (name );
18611782
@@ -3110,27 +3031,10 @@ static int rename_tmp_log(const char *newrefname)
31103031 return ret ;
31113032}
31123033
3113- /*
3114- * Return 0 if a reference named refname could be created without
3115- * conflicting with the name of an existing reference. Otherwise,
3116- * return a negative value and write an explanation to err. If extras
3117- * is non-NULL, it is a list of additional refnames with which refname
3118- * is not allowed to conflict. If skip is non-NULL, ignore potential
3119- * conflicts with refs in skip (e.g., because they are scheduled for
3120- * deletion in the same operation). Behavior is undefined if the same
3121- * name is listed in both extras and skip.
3122- *
3123- * Two reference names conflict if one of them exactly matches the
3124- * leading components of the other; e.g., "foo/bar" conflicts with
3125- * both "foo" and with "foo/bar/baz" but not with "foo/bar" or
3126- * "foo/barbados".
3127- *
3128- * extras and skip must be sorted.
3129- */
3130- static int verify_refname_available (const char * newname ,
3131- struct string_list * extras ,
3132- struct string_list * skip ,
3133- struct strbuf * err )
3034+ int verify_refname_available (const char * newname ,
3035+ struct string_list * extras ,
3036+ struct string_list * skip ,
3037+ struct strbuf * err )
31343038{
31353039 struct ref_dir * packed_refs = get_packed_refs (& ref_cache );
31363040 struct ref_dir * loose_refs = get_loose_refs (& ref_cache );
@@ -3284,12 +3188,7 @@ static int commit_ref(struct ref_lock *lock)
32843188 return 0 ;
32853189}
32863190
3287- /*
3288- * copy the reflog message msg to buf, which has been allocated sufficiently
3289- * large, while cleaning up the whitespaces. Especially, convert LF to space,
3290- * because reflog file is one line per entry.
3291- */
3292- static int copy_reflog_msg (char * buf , const char * msg )
3191+ int copy_reflog_msg (char * buf , const char * msg )
32933192{
32943193 char * cp = buf ;
32953194 char c ;
@@ -3310,7 +3209,7 @@ static int copy_reflog_msg(char *buf, const char *msg)
33103209 return cp - buf ;
33113210}
33123211
3313- static int should_autocreate_reflog (const char * refname )
3212+ int should_autocreate_reflog (const char * refname )
33143213{
33153214 if (!log_all_ref_updates )
33163215 return 0 ;
@@ -3963,61 +3862,6 @@ int for_each_reflog(each_ref_fn fn, void *cb_data)
39633862 return retval ;
39643863}
39653864
3966- /**
3967- * Information needed for a single ref update. Set new_sha1 to the new
3968- * value or to null_sha1 to delete the ref. To check the old value
3969- * while the ref is locked, set (flags & REF_HAVE_OLD) and set
3970- * old_sha1 to the old value, or to null_sha1 to ensure the ref does
3971- * not exist before update.
3972- */
3973- struct ref_update {
3974- /*
3975- * If (flags & REF_HAVE_NEW), set the reference to this value:
3976- */
3977- unsigned char new_sha1 [20 ];
3978- /*
3979- * If (flags & REF_HAVE_OLD), check that the reference
3980- * previously had this value:
3981- */
3982- unsigned char old_sha1 [20 ];
3983- /*
3984- * One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF,
3985- * REF_DELETING, and REF_ISPRUNING:
3986- */
3987- unsigned int flags ;
3988- struct ref_lock * lock ;
3989- int type ;
3990- char * msg ;
3991- const char refname [FLEX_ARRAY ];
3992- };
3993-
3994- /*
3995- * Transaction states.
3996- * OPEN: The transaction is in a valid state and can accept new updates.
3997- * An OPEN transaction can be committed.
3998- * CLOSED: A closed transaction is no longer active and no other operations
3999- * than free can be used on it in this state.
4000- * A transaction can either become closed by successfully committing
4001- * an active transaction or if there is a failure while building
4002- * the transaction thus rendering it failed/inactive.
4003- */
4004- enum ref_transaction_state {
4005- REF_TRANSACTION_OPEN = 0 ,
4006- REF_TRANSACTION_CLOSED = 1
4007- };
4008-
4009- /*
4010- * Data structure for holding a reference transaction, which can
4011- * consist of checks and updates to multiple references, carried out
4012- * as atomically as possible. This structure is opaque to callers.
4013- */
4014- struct ref_transaction {
4015- struct ref_update * * updates ;
4016- size_t alloc ;
4017- size_t nr ;
4018- enum ref_transaction_state state ;
4019- };
4020-
40213865struct ref_transaction * ref_transaction_begin (struct strbuf * err )
40223866{
40233867 assert (err );
0 commit comments