@@ -316,13 +316,15 @@ static void squash_message(struct commit *commit)
316316 struct rev_info rev ;
317317 struct strbuf out = STRBUF_INIT ;
318318 struct commit_list * j ;
319+ const char * filename ;
319320 int fd ;
320321 struct pretty_print_context ctx = {0 };
321322
322323 printf (_ ("Squash commit -- not updating HEAD\n" ));
323- fd = open (git_path ("SQUASH_MSG" ), O_WRONLY | O_CREAT , 0666 );
324+ filename = git_path ("SQUASH_MSG" );
325+ fd = open (filename , O_WRONLY | O_CREAT , 0666 );
324326 if (fd < 0 )
325- die_errno (_ ("Could not write to '%s'" ), git_path ( "SQUASH_MSG" ) );
327+ die_errno (_ ("Could not write to '%s'" ), filename );
326328
327329 init_revisions (& rev , NULL );
328330 rev .ignore_merges = 1 ;
@@ -492,14 +494,16 @@ static void merge_name(const char *remote, struct strbuf *msg)
492494
493495 if (!strcmp (remote , "FETCH_HEAD" ) &&
494496 !access (git_path ("FETCH_HEAD" ), R_OK )) {
497+ const char * filename ;
495498 FILE * fp ;
496499 struct strbuf line = STRBUF_INIT ;
497500 char * ptr ;
498501
499- fp = fopen (git_path ("FETCH_HEAD" ), "r" );
502+ filename = git_path ("FETCH_HEAD" );
503+ fp = fopen (filename , "r" );
500504 if (!fp )
501505 die_errno (_ ("could not open '%s' for reading" ),
502- git_path ( "FETCH_HEAD" ) );
506+ filename );
503507 strbuf_getline (& line , fp , '\n' );
504508 fclose (fp );
505509 ptr = strstr (line .buf , "\tnot-for-merge\t" );
@@ -847,20 +851,22 @@ static void add_strategies(const char *string, unsigned attr)
847851
848852static void write_merge_msg (struct strbuf * msg )
849853{
850- int fd = open (git_path ("MERGE_MSG" ), O_WRONLY | O_CREAT , 0666 );
854+ const char * filename = git_path ("MERGE_MSG" );
855+ int fd = open (filename , O_WRONLY | O_CREAT , 0666 );
851856 if (fd < 0 )
852857 die_errno (_ ("Could not open '%s' for writing" ),
853- git_path ( "MERGE_MSG" ) );
858+ filename );
854859 if (write_in_full (fd , msg -> buf , msg -> len ) != msg -> len )
855- die_errno (_ ("Could not write to '%s'" ), git_path ( "MERGE_MSG" ) );
860+ die_errno (_ ("Could not write to '%s'" ), filename );
856861 close (fd );
857862}
858863
859864static void read_merge_msg (struct strbuf * msg )
860865{
866+ const char * filename = git_path ("MERGE_MSG" );
861867 strbuf_reset (msg );
862- if (strbuf_read_file (msg , git_path ( "MERGE_MSG" ) , 0 ) < 0 )
863- die_errno (_ ("Could not read from '%s'" ), git_path ( "MERGE_MSG" ) );
868+ if (strbuf_read_file (msg , filename , 0 ) < 0 )
869+ die_errno (_ ("Could not read from '%s'" ), filename );
864870}
865871
866872static void write_merge_state (void );
@@ -948,13 +954,14 @@ static int finish_automerge(struct commit *head,
948954
949955static int suggest_conflicts (int renormalizing )
950956{
957+ const char * filename ;
951958 FILE * fp ;
952959 int pos ;
953960
954- fp = fopen (git_path ("MERGE_MSG" ), "a" );
961+ filename = git_path ("MERGE_MSG" );
962+ fp = fopen (filename , "a" );
955963 if (!fp )
956- die_errno (_ ("Could not open '%s' for writing" ),
957- git_path ("MERGE_MSG" ));
964+ die_errno (_ ("Could not open '%s' for writing" ), filename );
958965 fprintf (fp , "\nConflicts:\n" );
959966 for (pos = 0 ; pos < active_nr ; pos ++ ) {
960967 struct cache_entry * ce = active_cache [pos ];
@@ -1046,31 +1053,33 @@ static int setup_with_upstream(const char ***argv)
10461053
10471054static void write_merge_state (void )
10481055{
1056+ const char * filename ;
10491057 int fd ;
10501058 struct commit_list * j ;
10511059 struct strbuf buf = STRBUF_INIT ;
10521060
10531061 for (j = remoteheads ; j ; j = j -> next )
10541062 strbuf_addf (& buf , "%s\n" ,
10551063 sha1_to_hex (j -> item -> object .sha1 ));
1056- fd = open (git_path ("MERGE_HEAD" ), O_WRONLY | O_CREAT , 0666 );
1064+ filename = git_path ("MERGE_HEAD" );
1065+ fd = open (filename , O_WRONLY | O_CREAT , 0666 );
10571066 if (fd < 0 )
1058- die_errno (_ ("Could not open '%s' for writing" ),
1059- git_path ("MERGE_HEAD" ));
1067+ die_errno (_ ("Could not open '%s' for writing" ), filename );
10601068 if (write_in_full (fd , buf .buf , buf .len ) != buf .len )
1061- die_errno (_ ("Could not write to '%s'" ), git_path ( "MERGE_HEAD" ) );
1069+ die_errno (_ ("Could not write to '%s'" ), filename );
10621070 close (fd );
10631071 strbuf_addch (& merge_msg , '\n' );
10641072 write_merge_msg (& merge_msg );
1065- fd = open (git_path ("MERGE_MODE" ), O_WRONLY | O_CREAT | O_TRUNC , 0666 );
1073+
1074+ filename = git_path ("MERGE_MODE" );
1075+ fd = open (filename , O_WRONLY | O_CREAT | O_TRUNC , 0666 );
10661076 if (fd < 0 )
1067- die_errno (_ ("Could not open '%s' for writing" ),
1068- git_path ("MERGE_MODE" ));
1077+ die_errno (_ ("Could not open '%s' for writing" ), filename );
10691078 strbuf_reset (& buf );
10701079 if (!allow_fast_forward )
10711080 strbuf_addf (& buf , "no-ff" );
10721081 if (write_in_full (fd , buf .buf , buf .len ) != buf .len )
1073- die_errno (_ ("Could not write to '%s'" ), git_path ( "MERGE_MODE" ) );
1082+ die_errno (_ ("Could not write to '%s'" ), filename );
10741083 close (fd );
10751084}
10761085
0 commit comments