@@ -316,13 +316,15 @@ static void squash_message(struct commit *commit)
316
316
struct rev_info rev ;
317
317
struct strbuf out = STRBUF_INIT ;
318
318
struct commit_list * j ;
319
+ const char * filename ;
319
320
int fd ;
320
321
struct pretty_print_context ctx = {0 };
321
322
322
323
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 );
324
326
if (fd < 0 )
325
- die_errno (_ ("Could not write to '%s'" ), git_path ( "SQUASH_MSG" ) );
327
+ die_errno (_ ("Could not write to '%s'" ), filename );
326
328
327
329
init_revisions (& rev , NULL );
328
330
rev .ignore_merges = 1 ;
@@ -492,14 +494,16 @@ static void merge_name(const char *remote, struct strbuf *msg)
492
494
493
495
if (!strcmp (remote , "FETCH_HEAD" ) &&
494
496
!access (git_path ("FETCH_HEAD" ), R_OK )) {
497
+ const char * filename ;
495
498
FILE * fp ;
496
499
struct strbuf line = STRBUF_INIT ;
497
500
char * ptr ;
498
501
499
- fp = fopen (git_path ("FETCH_HEAD" ), "r" );
502
+ filename = git_path ("FETCH_HEAD" );
503
+ fp = fopen (filename , "r" );
500
504
if (!fp )
501
505
die_errno (_ ("could not open '%s' for reading" ),
502
- git_path ( "FETCH_HEAD" ) );
506
+ filename );
503
507
strbuf_getline (& line , fp , '\n' );
504
508
fclose (fp );
505
509
ptr = strstr (line .buf , "\tnot-for-merge\t" );
@@ -847,20 +851,22 @@ static void add_strategies(const char *string, unsigned attr)
847
851
848
852
static void write_merge_msg (struct strbuf * msg )
849
853
{
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 );
851
856
if (fd < 0 )
852
857
die_errno (_ ("Could not open '%s' for writing" ),
853
- git_path ( "MERGE_MSG" ) );
858
+ filename );
854
859
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 );
856
861
close (fd );
857
862
}
858
863
859
864
static void read_merge_msg (struct strbuf * msg )
860
865
{
866
+ const char * filename = git_path ("MERGE_MSG" );
861
867
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 );
864
870
}
865
871
866
872
static void write_merge_state (void );
@@ -948,13 +954,14 @@ static int finish_automerge(struct commit *head,
948
954
949
955
static int suggest_conflicts (int renormalizing )
950
956
{
957
+ const char * filename ;
951
958
FILE * fp ;
952
959
int pos ;
953
960
954
- fp = fopen (git_path ("MERGE_MSG" ), "a" );
961
+ filename = git_path ("MERGE_MSG" );
962
+ fp = fopen (filename , "a" );
955
963
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 );
958
965
fprintf (fp , "\nConflicts:\n" );
959
966
for (pos = 0 ; pos < active_nr ; pos ++ ) {
960
967
struct cache_entry * ce = active_cache [pos ];
@@ -1046,31 +1053,33 @@ static int setup_with_upstream(const char ***argv)
1046
1053
1047
1054
static void write_merge_state (void )
1048
1055
{
1056
+ const char * filename ;
1049
1057
int fd ;
1050
1058
struct commit_list * j ;
1051
1059
struct strbuf buf = STRBUF_INIT ;
1052
1060
1053
1061
for (j = remoteheads ; j ; j = j -> next )
1054
1062
strbuf_addf (& buf , "%s\n" ,
1055
1063
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 );
1057
1066
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 );
1060
1068
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 );
1062
1070
close (fd );
1063
1071
strbuf_addch (& merge_msg , '\n' );
1064
1072
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 );
1066
1076
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 );
1069
1078
strbuf_reset (& buf );
1070
1079
if (!allow_fast_forward )
1071
1080
strbuf_addf (& buf , "no-ff" );
1072
1081
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 );
1074
1083
close (fd );
1075
1084
}
1076
1085
0 commit comments