@@ -14,7 +14,8 @@ static const char * const git_update_ref_usage[] = {
14
14
};
15
15
16
16
static char line_termination = '\n' ;
17
- static int update_flags ;
17
+ static unsigned int update_flags ;
18
+ static unsigned int default_flags ;
18
19
static unsigned create_reflog_flag ;
19
20
static const char * msg ;
20
21
@@ -205,7 +206,7 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
205
206
msg , & err ))
206
207
die ("%s" , err .buf );
207
208
208
- update_flags = 0 ;
209
+ update_flags = default_flags ;
209
210
free (refname );
210
211
strbuf_release (& err );
211
212
@@ -237,7 +238,7 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
237
238
msg , & err ))
238
239
die ("%s" , err .buf );
239
240
240
- update_flags = 0 ;
241
+ update_flags = default_flags ;
241
242
free (refname );
242
243
strbuf_release (& err );
243
244
@@ -273,7 +274,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
273
274
update_flags , msg , & err ))
274
275
die ("%s" , err .buf );
275
276
276
- update_flags = 0 ;
277
+ update_flags = default_flags ;
277
278
free (refname );
278
279
strbuf_release (& err );
279
280
@@ -302,7 +303,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
302
303
update_flags , & err ))
303
304
die ("%s" , err .buf );
304
305
305
- update_flags = 0 ;
306
+ update_flags = default_flags ;
306
307
free (refname );
307
308
strbuf_release (& err );
308
309
@@ -357,7 +358,6 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
357
358
const char * refname , * oldval ;
358
359
struct object_id oid , oldoid ;
359
360
int delete = 0 , no_deref = 0 , read_stdin = 0 , end_null = 0 ;
360
- unsigned int flags = 0 ;
361
361
int create_reflog = 0 ;
362
362
struct option options [] = {
363
363
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)
378
378
379
379
create_reflog_flag = create_reflog ? REF_FORCE_CREATE_REFLOG : 0 ;
380
380
381
+ if (no_deref ) {
382
+ default_flags = REF_NO_DEREF ;
383
+ update_flags = default_flags ;
384
+ }
385
+
381
386
if (read_stdin ) {
382
387
struct strbuf err = STRBUF_INIT ;
383
388
struct ref_transaction * transaction ;
384
389
385
390
transaction = ref_transaction_begin (& err );
386
391
if (!transaction )
387
392
die ("%s" , err .buf );
388
- if (delete || no_deref || argc > 0 )
393
+ if (delete || argc > 0 )
389
394
usage_with_options (git_update_ref_usage , options );
390
395
if (end_null )
391
396
line_termination = '\0' ;
@@ -427,18 +432,16 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
427
432
die ("%s: not a valid old SHA1" , oldval );
428
433
}
429
434
430
- if (no_deref )
431
- flags = REF_NO_DEREF ;
432
435
if (delete )
433
436
/*
434
437
* For purposes of backwards compatibility, we treat
435
438
* NULL_SHA1 as "don't care" here:
436
439
*/
437
440
return delete_ref (msg , refname ,
438
441
(oldval && !is_null_oid (& oldoid )) ? & oldoid : NULL ,
439
- flags );
442
+ default_flags );
440
443
else
441
444
return update_ref (msg , refname , & oid , oldval ? & oldoid : NULL ,
442
- flags | create_reflog_flag ,
445
+ default_flags | create_reflog_flag ,
443
446
UPDATE_REFS_DIE_ON_ERR );
444
447
}
0 commit comments