@@ -339,7 +339,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)
339339static int write_message (const void * buf , size_t len , const char * filename ,
340340 int append_eol )
341341{
342- static struct lock_file msg_file ;
342+ struct lock_file msg_file = LOCK_INIT ;
343343
344344 int msg_fd = hold_lock_file_for_update (& msg_file , filename , 0 );
345345 if (msg_fd < 0 )
@@ -352,10 +352,8 @@ static int write_message(const void *buf, size_t len, const char *filename,
352352 rollback_lock_file (& msg_file );
353353 return error_errno (_ ("could not write eol to '%s'" ), filename );
354354 }
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 );
359357
360358 return 0 ;
361359}
@@ -485,7 +483,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
485483 struct tree * result , * next_tree , * base_tree , * head_tree ;
486484 int clean ;
487485 char * * xopt ;
488- static struct lock_file index_lock ;
486+ struct lock_file index_lock = LOCK_INIT ;
489487
490488 if (hold_locked_index (& index_lock , LOCK_REPORT_ON_ERROR ) < 0 )
491489 return -1 ;
@@ -514,8 +512,10 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
514512 fputs (o .obuf .buf , stdout );
515513 strbuf_release (& o .obuf );
516514 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 );
518517 return clean ;
518+ }
519519
520520 if (active_cache_changed &&
521521 write_locked_index (& the_index , & index_lock , COMMIT_LOCK ))
@@ -1705,7 +1705,7 @@ static int prepare_revs(struct replay_opts *opts)
17051705
17061706static int read_and_refresh_cache (struct replay_opts * opts )
17071707{
1708- static struct lock_file index_lock ;
1708+ struct lock_file index_lock = LOCK_INIT ;
17091709 int index_fd = hold_locked_index (& index_lock , 0 );
17101710 if (read_index_preload (& the_index , NULL ) < 0 ) {
17111711 rollback_lock_file (& index_lock );
@@ -2108,16 +2108,14 @@ static int create_seq_dir(void)
21082108
21092109static int save_head (const char * head )
21102110{
2111- static struct lock_file head_lock ;
2111+ struct lock_file head_lock = LOCK_INIT ;
21122112 struct strbuf buf = STRBUF_INIT ;
21132113 int fd ;
21142114 ssize_t written ;
21152115
21162116 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 )
21192118 return error_errno (_ ("could not lock HEAD" ));
2120- }
21212119 strbuf_addf (& buf , "%s\n" , head );
21222120 written = write_in_full (fd , buf .buf , buf .len );
21232121 strbuf_release (& buf );
@@ -2126,10 +2124,8 @@ static int save_head(const char *head)
21262124 return error_errno (_ ("could not write to '%s'" ),
21272125 git_path_head_file ());
21282126 }
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 ());
21332129 return 0 ;
21342130}
21352131
@@ -2233,7 +2229,7 @@ int sequencer_rollback(struct replay_opts *opts)
22332229
22342230static int save_todo (struct todo_list * todo_list , struct replay_opts * opts )
22352231{
2236- static struct lock_file todo_lock ;
2232+ struct lock_file todo_lock = LOCK_INIT ;
22372233 const char * todo_path = get_todo_path (opts );
22382234 int next = todo_list -> current , offset , fd ;
22392235
@@ -2253,7 +2249,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
22532249 todo_list -> buf .len - offset ) < 0 )
22542250 return error_errno (_ ("could not write to '%s'" ), todo_path );
22552251 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 );
22572253
22582254 if (is_rebase_i (opts )) {
22592255 const char * done_path = rebase_path_done ();
0 commit comments