commit_ref_update(): new function, extracted from write_ref_sha1()

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed May 9, 2015 at 17:18 UTC ad4cd6c29743274001cce323b670f7fb0c035ff1
1 file changed +20 -7
refs.c
+20 -7
@@ -3059,15 +3059,13 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
3059 }
3060
3061 /*
3062 - * Write sha1 into the ref specified by the lock. Make sure that errno
3063 - * is sane on error.
3062 + * Commit a change to a loose reference that has already been written
3063 + * to the loose reference lockfile. Also update the reflogs if
3064 + * necessary, using the specified lockmsg (which can be NULL).
3065 */
3065 -static int write_ref_sha1(struct ref_lock *lock,
3066 - const unsigned char *sha1, const char *logmsg)
3066 +static int commit_ref_update(struct ref_lock *lock,
3067 + const unsigned char *sha1, const char *logmsg)
3068 {
3068 - if (write_ref_to_lockfile(lock, sha1))
3069 - return -1;
3070 -
3069 clear_loose_ref_cache(&ref_cache);
3070 if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||
3071 (strcmp(lock->ref_name, lock->orig_ref_name) &&
@@ -3106,6 +3104,21 @@ static int write_ref_sha1(struct ref_lock *lock,
3104 return 0;
3105 }
3106
3107 +/*
3108 + * Write sha1 as the new value of the reference specified by the
3109 + * (open) lock. On error, roll back the lockfile and set errno
3110 + * appropriately.
3111 + */
3112 +static int write_ref_sha1(struct ref_lock *lock,
3113 + const unsigned char *sha1, const char *logmsg)
3114 +{
3115 + if (write_ref_to_lockfile(lock, sha1) ||
3116 + commit_ref_update(lock, sha1, logmsg))
3117 + return -1;
3118 +
3119 + return 0;
3120 +}
3121 +
3122 int create_symref(const char *ref_target, const char *refs_heads_master,
3123 const char *logmsg)
3124 {