MCPcopy Create free account
hub / github.com/git/git / fill_commit_message

Function fill_commit_message

builtin/history.c:41–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41static int fill_commit_message(struct repository *repo,
42 const struct object_id *old_tree,
43 const struct object_id *new_tree,
44 const char *default_message,
45 const char *action,
46 struct strbuf *out)
47{
48 const char *path = git_path_commit_editmsg();
49 const char *hint =
50 _("Please enter the commit message for the %s changes."
51 " Lines starting\nwith '%s' will be ignored, and an"
52 " empty message aborts the commit.\n");
53 struct wt_status s;
54
55 strbuf_addstr(out, default_message);
56 strbuf_addch(out, '\n');
57 strbuf_commented_addf(out, comment_line_str, hint, action, comment_line_str);
58 write_file_buf(path, out->buf, out->len);
59
60 wt_status_prepare(repo, &s);
61 FREE_AND_NULL(s.branch);
62 s.ahead_behind_flags = AHEAD_BEHIND_QUICK;
63 s.commit_template = 1;
64 s.colopts = 0;
65 s.display_comment_prefix = 1;
66 s.hints = 0;
67 s.use_color = 0;
68 s.whence = FROM_COMMIT;
69 s.committable = 1;
70
71 s.fp = fopen(git_path_commit_editmsg(), "a");
72 if (!s.fp)
73 return error_errno(_("could not open '%s'"), git_path_commit_editmsg());
74
75 wt_status_collect_changes_trees(&s, old_tree, new_tree);
76 wt_status_print(&s);
77 wt_status_collect_free_buffers(&s);
78 string_list_clear_func(&s.change, change_data_free);
79
80 strbuf_reset(out);
81 if (launch_editor(path, out, NULL)) {
82 fprintf(stderr, _("Aborting commit as launching the editor failed.\n"));
83 return -1;
84 }
85 strbuf_stripspace(out, comment_line_str);
86
87 cleanup_message(out, COMMIT_MSG_CLEANUP_ALL, 0);
88
89 if (!out->len) {
90 fprintf(stderr, _("Aborting commit due to empty commit message.\n"));
91 return -1;
92 }
93
94 return 0;
95}
96
97enum commit_tree_flags {
98 COMMIT_TREE_EDIT_MESSAGE = (1 << 0),

Callers 1

commit_tree_extFunction · 0.85

Calls 13

strbuf_addstrFunction · 0.85
strbuf_addchFunction · 0.85
strbuf_commented_addfFunction · 0.85
write_file_bufFunction · 0.85
wt_status_prepareFunction · 0.85
error_errnoFunction · 0.85
wt_status_printFunction · 0.85
string_list_clear_funcFunction · 0.85
launch_editorFunction · 0.85
strbuf_stripspaceFunction · 0.85

Tested by

no test coverage detected