@@ -3085,24 +3085,13 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
30853085}
30863086
30873087/*
3088- * Write sha1 into the ref specified by the lock. Make sure that errno
3089- * is sane on error.
3088+ * Commit a change to a loose reference that has already been written
3089+ * to the loose reference lockfile. Also update the reflogs if
3090+ * necessary, using the specified lockmsg (which can be NULL).
30903091 */
3091- static int write_ref_sha1 (struct ref_lock * lock ,
3092- const unsigned char * sha1 , const char * logmsg )
3092+ static int commit_ref_update (struct ref_lock * lock ,
3093+ const unsigned char * sha1 , const char * logmsg )
30933094{
3094- if (!lock ) {
3095- errno = EINVAL ;
3096- return -1 ;
3097- }
3098- if (!lock -> force_write && !hashcmp (lock -> old_sha1 , sha1 )) {
3099- unlock_ref (lock );
3100- return 0 ;
3101- }
3102-
3103- if (write_ref_to_lockfile (lock , sha1 ))
3104- return -1 ;
3105-
31063095 clear_loose_ref_cache (& ref_cache );
31073096 if (log_ref_write (lock -> ref_name , lock -> old_sha1 , sha1 , logmsg ) < 0 ||
31083097 (strcmp (lock -> ref_name , lock -> orig_ref_name ) &&
@@ -3141,6 +3130,30 @@ static int write_ref_sha1(struct ref_lock *lock,
31413130 return 0 ;
31423131}
31433132
3133+ /*
3134+ * Write sha1 as the new value of the reference specified by the
3135+ * (open) lock. On error, roll back the lockfile and set errno
3136+ * appropriately.
3137+ */
3138+ static int write_ref_sha1 (struct ref_lock * lock ,
3139+ const unsigned char * sha1 , const char * logmsg )
3140+ {
3141+ if (!lock ) {
3142+ errno = EINVAL ;
3143+ return -1 ;
3144+ }
3145+ if (!lock -> force_write && !hashcmp (lock -> old_sha1 , sha1 )) {
3146+ unlock_ref (lock );
3147+ return 0 ;
3148+ }
3149+
3150+ if (write_ref_to_lockfile (lock , sha1 ) ||
3151+ commit_ref_update (lock , sha1 , logmsg ))
3152+ return -1 ;
3153+
3154+ return 0 ;
3155+ }
3156+
31443157int create_symref (const char * ref_target , const char * refs_heads_master ,
31453158 const char * logmsg )
31463159{
0 commit comments