@@ -119,7 +119,7 @@ static void add_merge_config(struct ref **head,
119
119
120
120
for (rm = * head ; rm ; rm = rm -> next ) {
121
121
if (branch_merge_matches (branch , i , rm -> name )) {
122
- rm -> merge = 1 ;
122
+ rm -> fetch_head_status = FETCH_HEAD_MERGE ;
123
123
break ;
124
124
}
125
125
}
@@ -140,7 +140,7 @@ static void add_merge_config(struct ref **head,
140
140
refspec .src = branch -> merge [i ]-> src ;
141
141
get_fetch_map (remote_refs , & refspec , tail , 1 );
142
142
for (rm = * old_tail ; rm ; rm = rm -> next )
143
- rm -> merge = 1 ;
143
+ rm -> fetch_head_status = FETCH_HEAD_MERGE ;
144
144
}
145
145
}
146
146
@@ -160,16 +160,32 @@ static struct ref *get_ref_map(struct transport *transport,
160
160
const struct ref * remote_refs = transport_get_remote_refs (transport );
161
161
162
162
if (ref_count || tags == TAGS_SET ) {
163
+ struct ref * * old_tail ;
164
+
163
165
for (i = 0 ; i < ref_count ; i ++ ) {
164
166
get_fetch_map (remote_refs , & refs [i ], & tail , 0 );
165
167
if (refs [i ].dst && refs [i ].dst [0 ])
166
168
* autotags = 1 ;
167
169
}
168
170
/* Merge everything on the command line, but not --tags */
169
171
for (rm = ref_map ; rm ; rm = rm -> next )
170
- rm -> merge = 1 ;
172
+ rm -> fetch_head_status = FETCH_HEAD_MERGE ;
171
173
if (tags == TAGS_SET )
172
174
get_fetch_map (remote_refs , tag_refspec , & tail , 0 );
175
+
176
+ /*
177
+ * For any refs that we happen to be fetching via command-line
178
+ * arguments, take the opportunity to update their configured
179
+ * counterparts. However, we do not want to mention these
180
+ * entries in FETCH_HEAD at all, as they would simply be
181
+ * duplicates of existing entries.
182
+ */
183
+ old_tail = tail ;
184
+ for (i = 0 ; i < transport -> remote -> fetch_refspec_nr ; i ++ )
185
+ get_fetch_map (ref_map , & transport -> remote -> fetch [i ],
186
+ & tail , 1 );
187
+ for (rm = * old_tail ; rm ; rm = rm -> next )
188
+ rm -> fetch_head_status = FETCH_HEAD_IGNORE ;
173
189
} else {
174
190
/* Use the defaults */
175
191
struct remote * remote = transport -> remote ;
@@ -186,7 +202,7 @@ static struct ref *get_ref_map(struct transport *transport,
186
202
* autotags = 1 ;
187
203
if (!i && !has_merge && ref_map &&
188
204
!remote -> fetch [0 ].pattern )
189
- ref_map -> merge = 1 ;
205
+ ref_map -> fetch_head_status = FETCH_HEAD_MERGE ;
190
206
}
191
207
/*
192
208
* if the remote we're fetching from is the same
@@ -202,7 +218,7 @@ static struct ref *get_ref_map(struct transport *transport,
202
218
ref_map = get_remote_ref (remote_refs , "HEAD" );
203
219
if (!ref_map )
204
220
die (_ ("Couldn't find remote ref HEAD" ));
205
- ref_map -> merge = 1 ;
221
+ ref_map -> fetch_head_status = FETCH_HEAD_MERGE ;
206
222
tail = & ref_map -> next ;
207
223
}
208
224
}
@@ -389,7 +405,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
389
405
const char * what , * kind ;
390
406
struct ref * rm ;
391
407
char * url , * filename = dry_run ? "/dev/null" : git_path ("FETCH_HEAD" );
392
- int want_merge ;
408
+ int want_status ;
393
409
394
410
fp = fopen (filename , "a" );
395
411
if (!fp )
@@ -407,19 +423,22 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
407
423
}
408
424
409
425
/*
410
- * The first pass writes objects to be merged and then the
411
- * second pass writes the rest, in order to allow using
412
- * FETCH_HEAD as a refname to refer to the ref to be merged.
426
+ * We do a pass for each fetch_head_status type in their enum order, so
427
+ * merged entries are written before not-for-merge. That lets readers
428
+ * use FETCH_HEAD as a refname to refer to the ref to be merged.
413
429
*/
414
- for (want_merge = 1 ; 0 <= want_merge ; want_merge -- ) {
430
+ for (want_status = FETCH_HEAD_MERGE ;
431
+ want_status <= FETCH_HEAD_IGNORE ;
432
+ want_status ++ ) {
415
433
for (rm = ref_map ; rm ; rm = rm -> next ) {
416
434
struct ref * ref = NULL ;
435
+ const char * merge_status_marker = "" ;
417
436
418
437
commit = lookup_commit_reference_gently (rm -> old_sha1 , 1 );
419
438
if (!commit )
420
- rm -> merge = 0 ;
439
+ rm -> fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE ;
421
440
422
- if (rm -> merge != want_merge )
441
+ if (rm -> fetch_head_status != want_status )
423
442
continue ;
424
443
425
444
if (rm -> peer_ref ) {
@@ -465,16 +484,26 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
465
484
strbuf_addf (& note , "%s " , kind );
466
485
strbuf_addf (& note , "'%s' of " , what );
467
486
}
468
- fprintf (fp , "%s\t%s\t%s" ,
469
- sha1_to_hex (rm -> old_sha1 ),
470
- rm -> merge ? "" : "not-for-merge" ,
471
- note .buf );
472
- for (i = 0 ; i < url_len ; ++ i )
473
- if ('\n' == url [i ])
474
- fputs ("\\n" , fp );
475
- else
476
- fputc (url [i ], fp );
477
- fputc ('\n' , fp );
487
+ switch (rm -> fetch_head_status ) {
488
+ case FETCH_HEAD_NOT_FOR_MERGE :
489
+ merge_status_marker = "not-for-merge" ;
490
+ /* fall-through */
491
+ case FETCH_HEAD_MERGE :
492
+ fprintf (fp , "%s\t%s\t%s" ,
493
+ sha1_to_hex (rm -> old_sha1 ),
494
+ merge_status_marker ,
495
+ note .buf );
496
+ for (i = 0 ; i < url_len ; ++ i )
497
+ if ('\n' == url [i ])
498
+ fputs ("\\n" , fp );
499
+ else
500
+ fputc (url [i ], fp );
501
+ fputc ('\n' , fp );
502
+ break ;
503
+ default :
504
+ /* do not write anything to FETCH_HEAD */
505
+ break ;
506
+ }
478
507
479
508
strbuf_reset (& note );
480
509
if (ref ) {
0 commit comments