Merge branch 'dt/refs-backend-pre-vtable'
Code preparation for pluggable ref backends. * dt/refs-backend-pre-vtable: refs: break out ref conflict checks files_log_ref_write: new function initdb: make safe_create_dir public refs: split filesystem-based refs code into a new file refs/refs-internal.h: new header file refname_is_safe(): improve docstring pack_if_possible_fn(): use ref_type() instead of is_per_worktree_ref() copy_msg(): rename to copy_reflog_msg() verify_refname_available(): new function verify_refname_available(): rename function
This commit is contained in:
commit
b1cda70fff
3
Makefile
3
Makefile
@ -772,6 +772,7 @@ LIB_OBJS += reachable.o
|
||||
LIB_OBJS += read-cache.o
|
||||
LIB_OBJS += reflog-walk.o
|
||||
LIB_OBJS += refs.o
|
||||
LIB_OBJS += refs/files-backend.o
|
||||
LIB_OBJS += ref-filter.o
|
||||
LIB_OBJS += remote.o
|
||||
LIB_OBJS += replace_object.o
|
||||
@ -2432,7 +2433,7 @@ profile-clean:
|
||||
$(RM) $(addsuffix *.gcno,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
|
||||
|
||||
clean: profile-clean coverage-clean
|
||||
$(RM) *.o *.res block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o
|
||||
$(RM) *.o *.res refs/*.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o
|
||||
$(RM) xdiff/*.o vcs-svn/*.o ewah/*.o builtin/*.o
|
||||
$(RM) $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
|
||||
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
|
||||
|
@ -24,18 +24,6 @@ static int init_shared_repository = -1;
|
||||
static const char *init_db_template_dir;
|
||||
static const char *git_link;
|
||||
|
||||
static void safe_create_dir(const char *dir, int share)
|
||||
{
|
||||
if (mkdir(dir, 0777) < 0) {
|
||||
if (errno != EEXIST) {
|
||||
perror(dir);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else if (share && adjust_shared_perm(dir))
|
||||
die(_("Could not make %s writable by group"), dir);
|
||||
}
|
||||
|
||||
static void copy_templates_1(struct strbuf *path, struct strbuf *template,
|
||||
DIR *dir)
|
||||
{
|
||||
|
8
cache.h
8
cache.h
@ -1768,4 +1768,12 @@ void stat_validity_update(struct stat_validity *sv, int fd);
|
||||
int versioncmp(const char *s1, const char *s2);
|
||||
void sleep_millisec(int millisec);
|
||||
|
||||
/*
|
||||
* Create a directory and (if share is nonzero) adjust its permissions
|
||||
* according to the shared_repository setting. Only use this for
|
||||
* directories under $GIT_DIR. Don't use it for working tree
|
||||
* directories.
|
||||
*/
|
||||
void safe_create_dir(const char *dir, int share);
|
||||
|
||||
#endif /* CACHE_H */
|
||||
|
12
path.c
12
path.c
@ -740,6 +740,18 @@ int adjust_shared_perm(const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void safe_create_dir(const char *dir, int share)
|
||||
{
|
||||
if (mkdir(dir, 0777) < 0) {
|
||||
if (errno != EEXIST) {
|
||||
perror(dir);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else if (share && adjust_shared_perm(dir))
|
||||
die(_("Could not make %s writable by group"), dir);
|
||||
}
|
||||
|
||||
static int have_same_root(const char *path1, const char *path2)
|
||||
{
|
||||
int is_abs1, is_abs2;
|
||||
|
3512
refs/files-backend.c
Normal file
3512
refs/files-backend.c
Normal file
File diff suppressed because it is too large
Load Diff
200
refs/refs-internal.h
Normal file
200
refs/refs-internal.h
Normal file
@ -0,0 +1,200 @@
|
||||
#ifndef REFS_REFS_INTERNAL_H
|
||||
#define REFS_REFS_INTERNAL_H
|
||||
|
||||
/*
|
||||
* Data structures and functions for the internal use of the refs
|
||||
* module. Code outside of the refs module should use only the public
|
||||
* functions defined in "refs.h", and should *not* include this file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Flag passed to lock_ref_sha1_basic() telling it to tolerate broken
|
||||
* refs (i.e., because the reference is about to be deleted anyway).
|
||||
*/
|
||||
#define REF_DELETING 0x02
|
||||
|
||||
/*
|
||||
* Used as a flag in ref_update::flags when a loose ref is being
|
||||
* pruned.
|
||||
*/
|
||||
#define REF_ISPRUNING 0x04
|
||||
|
||||
/*
|
||||
* Used as a flag in ref_update::flags when the reference should be
|
||||
* updated to new_sha1.
|
||||
*/
|
||||
#define REF_HAVE_NEW 0x08
|
||||
|
||||
/*
|
||||
* Used as a flag in ref_update::flags when old_sha1 should be
|
||||
* checked.
|
||||
*/
|
||||
#define REF_HAVE_OLD 0x10
|
||||
|
||||
/*
|
||||
* Used as a flag in ref_update::flags when the lockfile needs to be
|
||||
* committed.
|
||||
*/
|
||||
#define REF_NEEDS_COMMIT 0x20
|
||||
|
||||
/*
|
||||
* 0x40 is REF_FORCE_CREATE_REFLOG, so skip it if you're adding a
|
||||
* value to ref_update::flags
|
||||
*/
|
||||
|
||||
/*
|
||||
* Return true iff refname is minimally safe. "Safe" here means that
|
||||
* deleting a loose reference by this name will not do any damage, for
|
||||
* example by causing a file that is not a reference to be deleted.
|
||||
* This function does not check that the reference name is legal; for
|
||||
* that, use check_refname_format().
|
||||
*
|
||||
* We consider a refname that starts with "refs/" to be safe as long
|
||||
* as any ".." components that it might contain do not escape "refs/".
|
||||
* Names that do not start with "refs/" are considered safe iff they
|
||||
* consist entirely of upper case characters and '_' (like "HEAD" and
|
||||
* "MERGE_HEAD" but not "config" or "FOO/BAR").
|
||||
*/
|
||||
int refname_is_safe(const char *refname);
|
||||
|
||||
enum peel_status {
|
||||
/* object was peeled successfully: */
|
||||
PEEL_PEELED = 0,
|
||||
|
||||
/*
|
||||
* object cannot be peeled because the named object (or an
|
||||
* object referred to by a tag in the peel chain), does not
|
||||
* exist.
|
||||
*/
|
||||
PEEL_INVALID = -1,
|
||||
|
||||
/* object cannot be peeled because it is not a tag: */
|
||||
PEEL_NON_TAG = -2,
|
||||
|
||||
/* ref_entry contains no peeled value because it is a symref: */
|
||||
PEEL_IS_SYMREF = -3,
|
||||
|
||||
/*
|
||||
* ref_entry cannot be peeled because it is broken (i.e., the
|
||||
* symbolic reference cannot even be resolved to an object
|
||||
* name):
|
||||
*/
|
||||
PEEL_BROKEN = -4
|
||||
};
|
||||
|
||||
/*
|
||||
* Peel the named object; i.e., if the object is a tag, resolve the
|
||||
* tag recursively until a non-tag is found. If successful, store the
|
||||
* result to sha1 and return PEEL_PEELED. If the object is not a tag
|
||||
* or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively,
|
||||
* and leave sha1 unchanged.
|
||||
*/
|
||||
enum peel_status peel_object(const unsigned char *name, unsigned char *sha1);
|
||||
|
||||
/*
|
||||
* Return 0 if a reference named refname could be created without
|
||||
* conflicting with the name of an existing reference. Otherwise,
|
||||
* return a negative value and write an explanation to err. If extras
|
||||
* is non-NULL, it is a list of additional refnames with which refname
|
||||
* is not allowed to conflict. If skip is non-NULL, ignore potential
|
||||
* conflicts with refs in skip (e.g., because they are scheduled for
|
||||
* deletion in the same operation). Behavior is undefined if the same
|
||||
* name is listed in both extras and skip.
|
||||
*
|
||||
* Two reference names conflict if one of them exactly matches the
|
||||
* leading components of the other; e.g., "foo/bar" conflicts with
|
||||
* both "foo" and with "foo/bar/baz" but not with "foo/bar" or
|
||||
* "foo/barbados".
|
||||
*
|
||||
* extras and skip must be sorted.
|
||||
*/
|
||||
int verify_refname_available(const char *newname,
|
||||
struct string_list *extras,
|
||||
struct string_list *skip,
|
||||
struct strbuf *err);
|
||||
|
||||
/*
|
||||
* Copy the reflog message msg to buf, which has been allocated sufficiently
|
||||
* large, while cleaning up the whitespaces. Especially, convert LF to space,
|
||||
* because reflog file is one line per entry.
|
||||
*/
|
||||
int copy_reflog_msg(char *buf, const char *msg);
|
||||
|
||||
int should_autocreate_reflog(const char *refname);
|
||||
|
||||
/**
|
||||
* Information needed for a single ref update. Set new_sha1 to the new
|
||||
* value or to null_sha1 to delete the ref. To check the old value
|
||||
* while the ref is locked, set (flags & REF_HAVE_OLD) and set
|
||||
* old_sha1 to the old value, or to null_sha1 to ensure the ref does
|
||||
* not exist before update.
|
||||
*/
|
||||
struct ref_update {
|
||||
/*
|
||||
* If (flags & REF_HAVE_NEW), set the reference to this value:
|
||||
*/
|
||||
unsigned char new_sha1[20];
|
||||
/*
|
||||
* If (flags & REF_HAVE_OLD), check that the reference
|
||||
* previously had this value:
|
||||
*/
|
||||
unsigned char old_sha1[20];
|
||||
/*
|
||||
* One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF,
|
||||
* REF_DELETING, and REF_ISPRUNING:
|
||||
*/
|
||||
unsigned int flags;
|
||||
struct ref_lock *lock;
|
||||
int type;
|
||||
char *msg;
|
||||
const char refname[FLEX_ARRAY];
|
||||
};
|
||||
|
||||
/*
|
||||
* Transaction states.
|
||||
* OPEN: The transaction is in a valid state and can accept new updates.
|
||||
* An OPEN transaction can be committed.
|
||||
* CLOSED: A closed transaction is no longer active and no other operations
|
||||
* than free can be used on it in this state.
|
||||
* A transaction can either become closed by successfully committing
|
||||
* an active transaction or if there is a failure while building
|
||||
* the transaction thus rendering it failed/inactive.
|
||||
*/
|
||||
enum ref_transaction_state {
|
||||
REF_TRANSACTION_OPEN = 0,
|
||||
REF_TRANSACTION_CLOSED = 1
|
||||
};
|
||||
|
||||
/*
|
||||
* Data structure for holding a reference transaction, which can
|
||||
* consist of checks and updates to multiple references, carried out
|
||||
* as atomically as possible. This structure is opaque to callers.
|
||||
*/
|
||||
struct ref_transaction {
|
||||
struct ref_update **updates;
|
||||
size_t alloc;
|
||||
size_t nr;
|
||||
enum ref_transaction_state state;
|
||||
};
|
||||
|
||||
int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
|
||||
const unsigned char *new_sha1, const char *msg,
|
||||
int flags, struct strbuf *err);
|
||||
|
||||
/*
|
||||
* Check for entries in extras that are within the specified
|
||||
* directory, where dirname is a reference directory name including
|
||||
* the trailing slash (e.g., "refs/heads/foo/"). Ignore any
|
||||
* conflicting references that are found in skip. If there is a
|
||||
* conflicting reference, return its name.
|
||||
*
|
||||
* extras and skip must be sorted lists of reference names. Either one
|
||||
* can be NULL, signifying the empty list.
|
||||
*/
|
||||
const char *find_descendant_ref(const char *dirname,
|
||||
const struct string_list *extras,
|
||||
const struct string_list *skip);
|
||||
|
||||
int rename_ref_available(const char *oldname, const char *newname);
|
||||
|
||||
#endif /* REFS_REFS_INTERNAL_H */
|
Loading…
Reference in New Issue
Block a user