@@ -119,7 +119,7 @@ static void add_merge_config(struct ref **head,
119119
120120 for (rm = * head ; rm ; rm = rm -> next ) {
121121 if (branch_merge_matches (branch , i , rm -> name )) {
122- rm -> merge = 1 ;
122+ rm -> fetch_head_status = FETCH_HEAD_MERGE ;
123123 break ;
124124 }
125125 }
@@ -140,7 +140,7 @@ static void add_merge_config(struct ref **head,
140140 refspec .src = branch -> merge [i ]-> src ;
141141 get_fetch_map (remote_refs , & refspec , tail , 1 );
142142 for (rm = * old_tail ; rm ; rm = rm -> next )
143- rm -> merge = 1 ;
143+ rm -> fetch_head_status = FETCH_HEAD_MERGE ;
144144 }
145145}
146146
@@ -167,7 +167,7 @@ static struct ref *get_ref_map(struct transport *transport,
167167 }
168168 /* Merge everything on the command line, but not --tags */
169169 for (rm = ref_map ; rm ; rm = rm -> next )
170- rm -> merge = 1 ;
170+ rm -> fetch_head_status = FETCH_HEAD_MERGE ;
171171 if (tags == TAGS_SET )
172172 get_fetch_map (remote_refs , tag_refspec , & tail , 0 );
173173 } else {
@@ -186,7 +186,7 @@ static struct ref *get_ref_map(struct transport *transport,
186186 * autotags = 1 ;
187187 if (!i && !has_merge && ref_map &&
188188 !remote -> fetch [0 ].pattern )
189- ref_map -> merge = 1 ;
189+ ref_map -> fetch_head_status = FETCH_HEAD_MERGE ;
190190 }
191191 /*
192192 * if the remote we're fetching from is the same
@@ -202,7 +202,7 @@ static struct ref *get_ref_map(struct transport *transport,
202202 ref_map = get_remote_ref (remote_refs , "HEAD" );
203203 if (!ref_map )
204204 die (_ ("Couldn't find remote ref HEAD" ));
205- ref_map -> merge = 1 ;
205+ ref_map -> fetch_head_status = FETCH_HEAD_MERGE ;
206206 tail = & ref_map -> next ;
207207 }
208208 }
@@ -389,7 +389,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
389389 const char * what , * kind ;
390390 struct ref * rm ;
391391 char * url , * filename = dry_run ? "/dev/null" : git_path ("FETCH_HEAD" );
392- int want_merge ;
392+ int want_status ;
393393
394394 fp = fopen (filename , "a" );
395395 if (!fp )
@@ -407,19 +407,22 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
407407 }
408408
409409 /*
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.
410+ * We do a pass for each fetch_head_status type in their enum order, so
411+ * merged entries are written before not-for-merge. That lets readers
412+ * use FETCH_HEAD as a refname to refer to the ref to be merged.
413413 */
414- for (want_merge = 1 ; 0 <= want_merge ; want_merge -- ) {
414+ for (want_status = FETCH_HEAD_MERGE ;
415+ want_status <= FETCH_HEAD_IGNORE ;
416+ want_status ++ ) {
415417 for (rm = ref_map ; rm ; rm = rm -> next ) {
416418 struct ref * ref = NULL ;
419+ const char * merge_status_marker = "" ;
417420
418421 commit = lookup_commit_reference_gently (rm -> old_sha1 , 1 );
419422 if (!commit )
420- rm -> merge = 0 ;
423+ rm -> fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE ;
421424
422- if (rm -> merge != want_merge )
425+ if (rm -> fetch_head_status != want_status )
423426 continue ;
424427
425428 if (rm -> peer_ref ) {
@@ -465,16 +468,26 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
465468 strbuf_addf (& note , "%s " , kind );
466469 strbuf_addf (& note , "'%s' of " , what );
467470 }
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 );
471+ switch (rm -> fetch_head_status ) {
472+ case FETCH_HEAD_NOT_FOR_MERGE :
473+ merge_status_marker = "not-for-merge" ;
474+ /* fall-through */
475+ case FETCH_HEAD_MERGE :
476+ fprintf (fp , "%s\t%s\t%s" ,
477+ sha1_to_hex (rm -> old_sha1 ),
478+ merge_status_marker ,
479+ note .buf );
480+ for (i = 0 ; i < url_len ; ++ i )
481+ if ('\n' == url [i ])
482+ fputs ("\\n" , fp );
483+ else
484+ fputc (url [i ], fp );
485+ fputc ('\n' , fp );
486+ break ;
487+ default :
488+ /* do not write anything to FETCH_HEAD */
489+ break ;
490+ }
478491
479492 strbuf_reset (& note );
480493 if (ref ) {
0 commit comments