@@ -3085,24 +3085,13 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
3085
3085
}
3086
3086
3087
3087
/*
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).
3090
3091
*/
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 )
3093
3094
{
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
-
3106
3095
clear_loose_ref_cache (& ref_cache );
3107
3096
if (log_ref_write (lock -> ref_name , lock -> old_sha1 , sha1 , logmsg ) < 0 ||
3108
3097
(strcmp (lock -> ref_name , lock -> orig_ref_name ) &&
@@ -3141,6 +3130,30 @@ static int write_ref_sha1(struct ref_lock *lock,
3141
3130
return 0 ;
3142
3131
}
3143
3132
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
+
3144
3157
int create_symref (const char * ref_target , const char * refs_heads_master ,
3145
3158
const char * logmsg )
3146
3159
{
0 commit comments