MCPcopy Index your code
hub / github.com/git/git / prepare_to_commit

Function prepare_to_commit

builtin/commit.c:762–1139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

760}
761
762static int prepare_to_commit(const char *index_file, const char *prefix,
763 struct commit *current_head,
764 struct wt_status *s,
765 struct strbuf *author_ident)
766{
767 struct stat statbuf;
768 struct strbuf committer_ident = STRBUF_INIT;
769 int committable;
770 struct strbuf sb = STRBUF_INIT;
771 const char *hook_arg1 = NULL;
772 const char *hook_arg2 = NULL;
773 int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE);
774 int old_display_comment_prefix;
775 int invoked_hook;
776
777 /* This checks and barfs if author is badly specified */
778 determine_author_info(author_ident);
779
780 if (!no_verify && run_commit_hook(use_editor, index_file, &invoked_hook,
781 "pre-commit", NULL))
782 return 0;
783
784 if (squash_message) {
785 /*
786 * Insert the proper subject line before other commit
787 * message options add their content.
788 */
789 if (use_message && !strcmp(use_message, squash_message))
790 strbuf_addstr(&sb, "squash! ");
791 else {
792 struct pretty_print_context ctx = {0};
793 struct commit *c;
794 c = lookup_commit_reference_by_name(squash_message);
795 if (!c)
796 die(_("could not lookup commit '%s'"), squash_message);
797 ctx.output_encoding = get_commit_output_encoding();
798 repo_format_commit_message(the_repository, c,
799 "squash! %s\n\n", &sb,
800 &ctx);
801 }
802 }
803
804 if (have_option_m && !fixup_message) {
805 strbuf_addbuf(&sb, &message);
806 hook_arg1 = "message";
807 } else if (logfile && !strcmp(logfile, "-")) {
808 if (isatty(0))
809 fprintf(stderr, _("(reading log message from standard input)\n"));
810 if (strbuf_read(&sb, 0, 0) < 0)
811 die_errno(_("could not read log from standard input"));
812 hook_arg1 = "message";
813 } else if (logfile) {
814 if (strbuf_read_file(&sb, logfile, 0) < 0)
815 die_errno(_("could not read log file '%s'"),
816 logfile);
817 hook_arg1 = "message";
818 } else if (use_message) {
819 const char *buffer;

Callers 1

cmd_commitFunction · 0.70

Calls 15

determine_author_infoFunction · 0.85
run_commit_hookFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_addbufFunction · 0.85
strbuf_readFunction · 0.85
die_errnoFunction · 0.85
strbuf_read_fileFunction · 0.85
skip_blank_linesFunction · 0.85
xstrfmtFunction · 0.85

Tested by

no test coverage detected