From 58f233ce1ed67bbc31a429fde5c65d5050fdbd7d Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 22 Jun 2015 16:03:01 +0200 Subject: initial_ref_transaction_commit(): function for initial ref creation "git clone" uses shortcuts when creating the initial set of references: * It writes them directly to packed-refs. * It doesn't lock the individual references (though it does lock the packed-refs file). * It doesn't check for refname conflicts between two new references or between one new reference and any hypothetical old ones. * It doesn't create reflog entries for the reference creations. This functionality was implemented in builtin/clone.c. But really that file shouldn't have such intimate knowledge of how references are stored. So provide a new function in the refs API, initial_ref_transaction_commit(), which can be used for initial reference creation. The new function is based on the ref_transaction interface. This means that we can make some other functions private to the refs module. That will be done in a followup commit. It would seem to make sense to add a test here that there are no existing references, because that is how the function *should* be used. But in fact, the "testgit" remote helper appears to call it *after* having set up refs/remotes//HEAD and refs/remotes//master, so we can't be so strict. For now, the function trusts its caller to only call it when it makes sense. Future commits will add some more limited sanity checks. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'refs.h') diff --git a/refs.h b/refs.h index 5f3bea7a42..9602889c3c 100644 --- a/refs.h +++ b/refs.h @@ -365,6 +365,20 @@ int ref_transaction_verify(struct ref_transaction *transaction, int ref_transaction_commit(struct ref_transaction *transaction, struct strbuf *err); +/* + * Like ref_transaction_commit(), but optimized for creating + * references when originally initializing a repository (e.g., by "git + * clone"). It writes the new references directly to packed-refs + * without locking the individual references. + * + * It is a bug to call this function when there might be other + * processes accessing the repository or if there are existing + * references that might conflict with the ones being created. All + * old_sha1 values must either be absent or NULL_SHA1. + */ +int initial_ref_transaction_commit(struct ref_transaction *transaction, + struct strbuf *err); + /* * Free an existing transaction and all associated data. */ -- cgit v1.2.1