@@ -62,6 +62,11 @@ static unsigned char refname_disposition[256] = {
6262 */
6363#define REF_NEEDS_COMMIT 0x20
6464
65+ /*
66+ * 0x40 is REF_FORCE_CREATE_REFLOG, so skip it if you're adding a
67+ * value to ref_update::flags
68+ */
69+
6570/*
6671 * Try to read one refname component from the front of refname.
6772 * 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,
29142919 const unsigned char * sha1 , struct strbuf * err );
29152920static int commit_ref_update (struct ref_lock * lock ,
29162921 const unsigned char * sha1 , const char * logmsg ,
2917- struct strbuf * err );
2922+ int flags , struct strbuf * err );
29182923
29192924int rename_ref (const char * oldrefname , const char * newrefname , const char * logmsg )
29202925{
@@ -2976,7 +2981,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
29762981 hashcpy (lock -> old_oid .hash , orig_sha1 );
29772982
29782983 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 )) {
29802985 error ("unable to write current sha1 into %s: %s" , newrefname , err .buf );
29812986 strbuf_release (& err );
29822987 goto rollback ;
@@ -2995,7 +3000,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
29953000 flag = log_all_ref_updates ;
29963001 log_all_ref_updates = 0 ;
29973002 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 )) {
29993004 error ("unable to write current sha1 into %s: %s" , oldrefname , err .buf );
30003005 strbuf_release (& err );
30013006 }
@@ -3152,15 +3157,16 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
31523157
31533158static int log_ref_write_1 (const char * refname , const unsigned char * old_sha1 ,
31543159 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 )
31563162{
31573163 int logfd , result , oflags = O_APPEND | O_WRONLY ;
31583164 char * log_file ;
31593165
31603166 if (log_all_ref_updates < 0 )
31613167 log_all_ref_updates = !is_bare_repository ();
31623168
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 );
31643170
31653171 if (result )
31663172 return result ;
@@ -3189,10 +3195,11 @@ static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
31893195
31903196static int log_ref_write (const char * refname , const unsigned char * old_sha1 ,
31913197 const unsigned char * new_sha1 , const char * msg ,
3192- struct strbuf * err )
3198+ int flags , struct strbuf * err )
31933199{
31943200 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 );
31963203 strbuf_release (& sb );
31973204 return ret ;
31983205}
@@ -3246,12 +3253,12 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
32463253 */
32473254static int commit_ref_update (struct ref_lock * lock ,
32483255 const unsigned char * sha1 , const char * logmsg ,
3249- struct strbuf * err )
3256+ int flags , struct strbuf * err )
32503257{
32513258 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 ||
32533260 (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 )) {
32553262 char * old_msg = strbuf_detach (err , NULL );
32563263 strbuf_addf (err , "Cannot update the ref '%s': %s" ,
32573264 lock -> ref_name , old_msg );
@@ -3281,7 +3288,7 @@ static int commit_ref_update(struct ref_lock *lock,
32813288 !strcmp (head_ref , lock -> ref_name )) {
32823289 struct strbuf log_err = STRBUF_INIT ;
32833290 if (log_ref_write ("HEAD" , lock -> old_oid .hash , sha1 ,
3284- logmsg , & log_err )) {
3291+ logmsg , 0 , & log_err )) {
32853292 error ("%s" , log_err .buf );
32863293 strbuf_release (& log_err );
32873294 }
@@ -3355,7 +3362,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
33553362 done :
33563363#endif
33573364 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 )) {
33593366 error ("%s" , err .buf );
33603367 strbuf_release (& err );
33613368 }
@@ -4032,7 +4039,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
40324039
40334040 if (update -> flags & REF_NEEDS_COMMIT ) {
40344041 if (commit_ref_update (update -> lock ,
4035- update -> new_sha1 , update -> msg , err )) {
4042+ update -> new_sha1 , update -> msg ,
4043+ update -> flags , err )) {
40364044 /* freed by commit_ref_update(): */
40374045 update -> lock = NULL ;
40384046 ret = TRANSACTION_GENERIC_ERROR ;
0 commit comments