Merge branch 'jc/history-message-prep-fix'

A write file stream resource leak has been fixed as part of a code
cleanup.

* jc/history-message-prep-fix:
  history: streamline message preparation and plug file stream leak
This commit is contained in:
Junio C Hamano
2026-07-15 13:24:18 -07:00

View File

@@ -52,11 +52,6 @@ static int fill_commit_message(struct repository *repo,
" empty message aborts the commit.\n");
struct wt_status s;
strbuf_addstr(out, default_message);
strbuf_addch(out, '\n');
strbuf_commented_addf(out, comment_line_str, hint, action, comment_line_str);
write_file_buf(path, out->buf, out->len);
wt_status_prepare(repo, &s);
FREE_AND_NULL(s.branch);
s.ahead_behind_flags = AHEAD_BEHIND_QUICK;
@@ -68,14 +63,22 @@ static int fill_commit_message(struct repository *repo,
s.whence = FROM_COMMIT;
s.committable = 1;
s.fp = fopen(git_path_commit_editmsg(), "a");
s.fp = fopen(path, "w");
if (!s.fp)
return error_errno(_("could not open '%s'"), git_path_commit_editmsg());
return error_errno(_("could not open '%s'"), path);
strbuf_addstr(out, default_message);
strbuf_addch(out, '\n');
strbuf_commented_addf(out, comment_line_str, hint, action, comment_line_str);
if (fwrite(out->buf, 1, out->len, s.fp) != out->len)
die_errno(_("could not write to '%s'"), path);
wt_status_collect_changes_trees(&s, old_tree, new_tree);
wt_status_print(&s);
wt_status_collect_free_buffers(&s);
string_list_clear_func(&s.change, change_data_free);
if (fclose(s.fp))
die_errno(_("could not write to '%s'"), path);
strbuf_reset(out);
if (launch_editor(path, out, NULL)) {