@@ -580,6 +580,7 @@ int rerere_remaining(struct string_list *merge_rr)
580580 */
581581static int merge (const struct rerere_id * id , const char * path )
582582{
583+ FILE * f ;
583584 int ret ;
584585 mmfile_t cur = {NULL , 0 }, base = {NULL , 0 }, other = {NULL , 0 };
585586 mmbuffer_t result = {NULL , 0 };
@@ -588,8 +589,10 @@ static int merge(const struct rerere_id *id, const char *path)
588589 * Normalize the conflicts in path and write it out to
589590 * "thisimage" temporary file.
590591 */
591- if (handle_file (path , NULL , rerere_path (id , "thisimage" )) < 0 )
592- return 1 ;
592+ if (handle_file (path , NULL , rerere_path (id , "thisimage" )) < 0 ) {
593+ ret = 1 ;
594+ goto out ;
595+ }
593596
594597 if (read_mmfile (& cur , rerere_path (id , "thisimage" )) ||
595598 read_mmfile (& base , rerere_path (id , "preimage" )) ||
@@ -603,29 +606,28 @@ static int merge(const struct rerere_id *id, const char *path)
603606 * low-level merge driver settings.
604607 */
605608 ret = ll_merge (& result , path , & base , NULL , & cur , "" , & other , "" , NULL );
606- if (! ret ) {
607- FILE * f ;
609+ if (ret )
610+ goto out ;
608611
609- /*
610- * A successful replay of recorded resolution.
611- * Mark that "postimage" was used to help gc.
612- */
613- if (utime (rerere_path (id , "postimage" ), NULL ) < 0 )
614- warning ("failed utime() on %s: %s" ,
615- rerere_path (id , "postimage" ),
616- strerror (errno ));
617-
618- /* Update "path" with the resolution */
619- f = fopen (path , "w" );
620- if (!f )
621- return error ("Could not open %s: %s" , path ,
622- strerror (errno ));
623- if (fwrite (result .ptr , result .size , 1 , f ) != 1 )
624- error ("Could not write %s: %s" , path , strerror (errno ));
625- if (fclose (f ))
626- return error ("Writing %s failed: %s" , path ,
627- strerror (errno ));
628- }
612+ /*
613+ * A successful replay of recorded resolution.
614+ * Mark that "postimage" was used to help gc.
615+ */
616+ if (utime (rerere_path (id , "postimage" ), NULL ) < 0 )
617+ warning ("failed utime() on %s: %s" ,
618+ rerere_path (id , "postimage" ),
619+ strerror (errno ));
620+
621+ /* Update "path" with the resolution */
622+ f = fopen (path , "w" );
623+ if (!f )
624+ return error ("Could not open %s: %s" , path ,
625+ strerror (errno ));
626+ if (fwrite (result .ptr , result .size , 1 , f ) != 1 )
627+ error ("Could not write %s: %s" , path , strerror (errno ));
628+ if (fclose (f ))
629+ return error ("Writing %s failed: %s" , path ,
630+ strerror (errno ));
629631
630632out :
631633 free (cur .ptr );
0 commit comments