@@ -62,6 +62,11 @@ static unsigned char refname_disposition[256] = {
62
62
*/
63
63
#define REF_NEEDS_COMMIT 0x20
64
64
65
+ /*
66
+ * 0x40 is REF_FORCE_CREATE_REFLOG, so skip it if you're adding a
67
+ * value to ref_update::flags
68
+ */
69
+
65
70
/*
66
71
* Try to read one refname component from the front of refname.
67
72
* Return the length of the component found, or -1 if the component is
@@ -2914,7 +2919,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
2914
2919
const unsigned char * sha1 , struct strbuf * err );
2915
2920
static int commit_ref_update (struct ref_lock * lock ,
2916
2921
const unsigned char * sha1 , const char * logmsg ,
2917
- struct strbuf * err );
2922
+ int flags , struct strbuf * err );
2918
2923
2919
2924
int rename_ref (const char * oldrefname , const char * newrefname , const char * logmsg )
2920
2925
{
@@ -2976,7 +2981,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
2976
2981
hashcpy (lock -> old_oid .hash , orig_sha1 );
2977
2982
2978
2983
if (write_ref_to_lockfile (lock , orig_sha1 , & err ) ||
2979
- commit_ref_update (lock , orig_sha1 , logmsg , & err )) {
2984
+ commit_ref_update (lock , orig_sha1 , logmsg , 0 , & err )) {
2980
2985
error ("unable to write current sha1 into %s: %s" , newrefname , err .buf );
2981
2986
strbuf_release (& err );
2982
2987
goto rollback ;
@@ -2995,7 +3000,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
2995
3000
flag = log_all_ref_updates ;
2996
3001
log_all_ref_updates = 0 ;
2997
3002
if (write_ref_to_lockfile (lock , orig_sha1 , & err ) ||
2998
- commit_ref_update (lock , orig_sha1 , NULL , & err )) {
3003
+ commit_ref_update (lock , orig_sha1 , NULL , 0 , & err )) {
2999
3004
error ("unable to write current sha1 into %s: %s" , oldrefname , err .buf );
3000
3005
strbuf_release (& err );
3001
3006
}
@@ -3152,15 +3157,16 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
3152
3157
3153
3158
static int log_ref_write_1 (const char * refname , const unsigned char * old_sha1 ,
3154
3159
const unsigned char * new_sha1 , const char * msg ,
3155
- struct strbuf * sb_log_file , struct strbuf * err )
3160
+ struct strbuf * sb_log_file , int flags ,
3161
+ struct strbuf * err )
3156
3162
{
3157
3163
int logfd , result , oflags = O_APPEND | O_WRONLY ;
3158
3164
char * log_file ;
3159
3165
3160
3166
if (log_all_ref_updates < 0 )
3161
3167
log_all_ref_updates = !is_bare_repository ();
3162
3168
3163
- result = log_ref_setup (refname , sb_log_file , err , 0 );
3169
+ result = log_ref_setup (refname , sb_log_file , err , flags & REF_FORCE_CREATE_REFLOG );
3164
3170
3165
3171
if (result )
3166
3172
return result ;
@@ -3189,10 +3195,11 @@ static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
3189
3195
3190
3196
static int log_ref_write (const char * refname , const unsigned char * old_sha1 ,
3191
3197
const unsigned char * new_sha1 , const char * msg ,
3192
- struct strbuf * err )
3198
+ int flags , struct strbuf * err )
3193
3199
{
3194
3200
struct strbuf sb = STRBUF_INIT ;
3195
- int ret = log_ref_write_1 (refname , old_sha1 , new_sha1 , msg , & sb , err );
3201
+ int ret = log_ref_write_1 (refname , old_sha1 , new_sha1 , msg , & sb , flags ,
3202
+ err );
3196
3203
strbuf_release (& sb );
3197
3204
return ret ;
3198
3205
}
@@ -3246,12 +3253,12 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
3246
3253
*/
3247
3254
static int commit_ref_update (struct ref_lock * lock ,
3248
3255
const unsigned char * sha1 , const char * logmsg ,
3249
- struct strbuf * err )
3256
+ int flags , struct strbuf * err )
3250
3257
{
3251
3258
clear_loose_ref_cache (& ref_cache );
3252
- if (log_ref_write (lock -> ref_name , lock -> old_oid .hash , sha1 , logmsg , err ) < 0 ||
3259
+ if (log_ref_write (lock -> ref_name , lock -> old_oid .hash , sha1 , logmsg , flags , err ) < 0 ||
3253
3260
(strcmp (lock -> ref_name , lock -> orig_ref_name ) &&
3254
- log_ref_write (lock -> orig_ref_name , lock -> old_oid .hash , sha1 , logmsg , err ) < 0 )) {
3261
+ log_ref_write (lock -> orig_ref_name , lock -> old_oid .hash , sha1 , logmsg , flags , err ) < 0 )) {
3255
3262
char * old_msg = strbuf_detach (err , NULL );
3256
3263
strbuf_addf (err , "Cannot update the ref '%s': %s" ,
3257
3264
lock -> ref_name , old_msg );
@@ -3281,7 +3288,7 @@ static int commit_ref_update(struct ref_lock *lock,
3281
3288
!strcmp (head_ref , lock -> ref_name )) {
3282
3289
struct strbuf log_err = STRBUF_INIT ;
3283
3290
if (log_ref_write ("HEAD" , lock -> old_oid .hash , sha1 ,
3284
- logmsg , & log_err )) {
3291
+ logmsg , 0 , & log_err )) {
3285
3292
error ("%s" , log_err .buf );
3286
3293
strbuf_release (& log_err );
3287
3294
}
@@ -3355,7 +3362,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
3355
3362
done :
3356
3363
#endif
3357
3364
if (logmsg && !read_ref (refs_heads_master , new_sha1 ) &&
3358
- log_ref_write (ref_target , old_sha1 , new_sha1 , logmsg , & err )) {
3365
+ log_ref_write (ref_target , old_sha1 , new_sha1 , logmsg , 0 , & err )) {
3359
3366
error ("%s" , err .buf );
3360
3367
strbuf_release (& err );
3361
3368
}
@@ -4032,7 +4039,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
4032
4039
4033
4040
if (update -> flags & REF_NEEDS_COMMIT ) {
4034
4041
if (commit_ref_update (update -> lock ,
4035
- update -> new_sha1 , update -> msg , err )) {
4042
+ update -> new_sha1 , update -> msg ,
4043
+ update -> flags , err )) {
4036
4044
/* freed by commit_ref_update(): */
4037
4045
update -> lock = NULL ;
4038
4046
ret = TRANSACTION_GENERIC_ERROR ;
0 commit comments