@@ -14,7 +14,8 @@ static const char * const git_update_ref_usage[] = {
1414};
1515
1616static char line_termination = '\n' ;
17- static int update_flags ;
17+ static unsigned int update_flags ;
18+ static unsigned int default_flags ;
1819static unsigned create_reflog_flag ;
1920static const char * msg ;
2021
@@ -205,7 +206,7 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
205206 msg , & err ))
206207 die ("%s" , err .buf );
207208
208- update_flags = 0 ;
209+ update_flags = default_flags ;
209210 free (refname );
210211 strbuf_release (& err );
211212
@@ -237,7 +238,7 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
237238 msg , & err ))
238239 die ("%s" , err .buf );
239240
240- update_flags = 0 ;
241+ update_flags = default_flags ;
241242 free (refname );
242243 strbuf_release (& err );
243244
@@ -273,7 +274,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
273274 update_flags , msg , & err ))
274275 die ("%s" , err .buf );
275276
276- update_flags = 0 ;
277+ update_flags = default_flags ;
277278 free (refname );
278279 strbuf_release (& err );
279280
@@ -302,7 +303,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
302303 update_flags , & err ))
303304 die ("%s" , err .buf );
304305
305- update_flags = 0 ;
306+ update_flags = default_flags ;
306307 free (refname );
307308 strbuf_release (& err );
308309
@@ -357,7 +358,6 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
357358 const char * refname , * oldval ;
358359 struct object_id oid , oldoid ;
359360 int delete = 0 , no_deref = 0 , read_stdin = 0 , end_null = 0 ;
360- unsigned int flags = 0 ;
361361 int create_reflog = 0 ;
362362 struct option options [] = {
363363 OPT_STRING ( 'm' , NULL , & msg , N_ ("reason" ), N_ ("reason of the update" )),
@@ -378,14 +378,19 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
378378
379379 create_reflog_flag = create_reflog ? REF_FORCE_CREATE_REFLOG : 0 ;
380380
381+ if (no_deref ) {
382+ default_flags = REF_NO_DEREF ;
383+ update_flags = default_flags ;
384+ }
385+
381386 if (read_stdin ) {
382387 struct strbuf err = STRBUF_INIT ;
383388 struct ref_transaction * transaction ;
384389
385390 transaction = ref_transaction_begin (& err );
386391 if (!transaction )
387392 die ("%s" , err .buf );
388- if (delete || no_deref || argc > 0 )
393+ if (delete || argc > 0 )
389394 usage_with_options (git_update_ref_usage , options );
390395 if (end_null )
391396 line_termination = '\0' ;
@@ -427,18 +432,16 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
427432 die ("%s: not a valid old SHA1" , oldval );
428433 }
429434
430- if (no_deref )
431- flags = REF_NO_DEREF ;
432435 if (delete )
433436 /*
434437 * For purposes of backwards compatibility, we treat
435438 * NULL_SHA1 as "don't care" here:
436439 */
437440 return delete_ref (msg , refname ,
438441 (oldval && !is_null_oid (& oldoid )) ? & oldoid : NULL ,
439- flags );
442+ default_flags );
440443 else
441444 return update_ref (msg , refname , & oid , oldval ? & oldoid : NULL ,
442- flags | create_reflog_flag ,
445+ default_flags | create_reflog_flag ,
443446 UPDATE_REFS_DIE_ON_ERR );
444447}
0 commit comments