@@ -339,7 +339,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)
339
339
static int write_message (const void * buf , size_t len , const char * filename ,
340
340
int append_eol )
341
341
{
342
- static struct lock_file msg_file ;
342
+ struct lock_file msg_file = LOCK_INIT ;
343
343
344
344
int msg_fd = hold_lock_file_for_update (& msg_file , filename , 0 );
345
345
if (msg_fd < 0 )
@@ -352,10 +352,8 @@ static int write_message(const void *buf, size_t len, const char *filename,
352
352
rollback_lock_file (& msg_file );
353
353
return error_errno (_ ("could not write eol to '%s'" ), filename );
354
354
}
355
- if (commit_lock_file (& msg_file ) < 0 ) {
356
- rollback_lock_file (& msg_file );
357
- return error (_ ("failed to finalize '%s'." ), filename );
358
- }
355
+ if (commit_lock_file (& msg_file ) < 0 )
356
+ return error (_ ("failed to finalize '%s'" ), filename );
359
357
360
358
return 0 ;
361
359
}
@@ -485,7 +483,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
485
483
struct tree * result , * next_tree , * base_tree , * head_tree ;
486
484
int clean ;
487
485
char * * xopt ;
488
- static struct lock_file index_lock ;
486
+ struct lock_file index_lock = LOCK_INIT ;
489
487
490
488
if (hold_locked_index (& index_lock , LOCK_REPORT_ON_ERROR ) < 0 )
491
489
return -1 ;
@@ -514,8 +512,10 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
514
512
fputs (o .obuf .buf , stdout );
515
513
strbuf_release (& o .obuf );
516
514
diff_warn_rename_limit ("merge.renamelimit" , o .needed_rename_limit , 0 );
517
- if (clean < 0 )
515
+ if (clean < 0 ) {
516
+ rollback_lock_file (& index_lock );
518
517
return clean ;
518
+ }
519
519
520
520
if (active_cache_changed &&
521
521
write_locked_index (& the_index , & index_lock , COMMIT_LOCK ))
@@ -1705,7 +1705,7 @@ static int prepare_revs(struct replay_opts *opts)
1705
1705
1706
1706
static int read_and_refresh_cache (struct replay_opts * opts )
1707
1707
{
1708
- static struct lock_file index_lock ;
1708
+ struct lock_file index_lock = LOCK_INIT ;
1709
1709
int index_fd = hold_locked_index (& index_lock , 0 );
1710
1710
if (read_index_preload (& the_index , NULL ) < 0 ) {
1711
1711
rollback_lock_file (& index_lock );
@@ -2108,16 +2108,14 @@ static int create_seq_dir(void)
2108
2108
2109
2109
static int save_head (const char * head )
2110
2110
{
2111
- static struct lock_file head_lock ;
2111
+ struct lock_file head_lock = LOCK_INIT ;
2112
2112
struct strbuf buf = STRBUF_INIT ;
2113
2113
int fd ;
2114
2114
ssize_t written ;
2115
2115
2116
2116
fd = hold_lock_file_for_update (& head_lock , git_path_head_file (), 0 );
2117
- if (fd < 0 ) {
2118
- rollback_lock_file (& head_lock );
2117
+ if (fd < 0 )
2119
2118
return error_errno (_ ("could not lock HEAD" ));
2120
- }
2121
2119
strbuf_addf (& buf , "%s\n" , head );
2122
2120
written = write_in_full (fd , buf .buf , buf .len );
2123
2121
strbuf_release (& buf );
@@ -2126,10 +2124,8 @@ static int save_head(const char *head)
2126
2124
return error_errno (_ ("could not write to '%s'" ),
2127
2125
git_path_head_file ());
2128
2126
}
2129
- if (commit_lock_file (& head_lock ) < 0 ) {
2130
- rollback_lock_file (& head_lock );
2131
- return error (_ ("failed to finalize '%s'." ), git_path_head_file ());
2132
- }
2127
+ if (commit_lock_file (& head_lock ) < 0 )
2128
+ return error (_ ("failed to finalize '%s'" ), git_path_head_file ());
2133
2129
return 0 ;
2134
2130
}
2135
2131
@@ -2233,7 +2229,7 @@ int sequencer_rollback(struct replay_opts *opts)
2233
2229
2234
2230
static int save_todo (struct todo_list * todo_list , struct replay_opts * opts )
2235
2231
{
2236
- static struct lock_file todo_lock ;
2232
+ struct lock_file todo_lock = LOCK_INIT ;
2237
2233
const char * todo_path = get_todo_path (opts );
2238
2234
int next = todo_list -> current , offset , fd ;
2239
2235
@@ -2253,7 +2249,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
2253
2249
todo_list -> buf .len - offset ) < 0 )
2254
2250
return error_errno (_ ("could not write to '%s'" ), todo_path );
2255
2251
if (commit_lock_file (& todo_lock ) < 0 )
2256
- return error (_ ("failed to finalize '%s'. " ), todo_path );
2252
+ return error (_ ("failed to finalize '%s'" ), todo_path );
2257
2253
2258
2254
if (is_rebase_i (opts )) {
2259
2255
const char * done_path = rebase_path_done ();
0 commit comments