From: Junio C Hamano Date: Thu, 21 Jan 2010 04:28:50 +0000 (-0800) Subject: Merge branch 'nd/status-partial-refresh' X-Git-Tag: v1.7.0-rc0~56 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e98f80f50bf9b78aab8cea6184fd708259d0c3b3?hp=-c Merge branch 'nd/status-partial-refresh' * nd/status-partial-refresh: rm: only refresh entries that we may touch status: only touch path we may need to check --- e98f80f50bf9b78aab8cea6184fd708259d0c3b3 diff --combined builtin-commit.c index fedcda09d0,d5d8eb68cc..55676fd874 --- a/builtin-commit.c +++ b/builtin-commit.c @@@ -36,20 -36,7 +36,20 @@@ static const char * const builtin_statu NULL }; +static const char implicit_ident_advice[] = +"Your name and email address were configured automatically based\n" +"on your username and hostname. Please check that they are accurate.\n" +"You can suppress this message by setting them explicitly:\n" +"\n" +" git config --global user.name Your Name\n" +" git config --global user.email you@example.com\n" +"\n" +"If the identity used for this commit is wrong, you can fix it with:\n" +"\n" +" git commit --amend --author='Your Name '\n"; + static unsigned char head_sha1[20]; + static char *use_message_buffer; static const char commit_editmsg[] = "COMMIT_EDITMSG"; static struct lock_file index_lock; /* real index */ @@@ -81,7 -68,7 +81,7 @@@ static enum } cleanup_mode; static char *cleanup_arg; -static int use_editor = 1, initial_commit, in_merge; +static int use_editor = 1, initial_commit, in_merge, include_status = 1; static const char *only_include_assumed; static struct strbuf message; @@@ -120,7 -107,6 +120,7 @@@ static struct option builtin_commit_opt OPT_FILENAME('t', "template", &template_file, "use specified template file"), OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"), OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"), + OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"), /* end commit message options */ OPT_GROUP("Commit contents options"), @@@ -258,16 -244,6 +258,16 @@@ static void create_base_index(void exit(128); /* We've already reported the error, finish dying */ } +static void refresh_cache_or_die(int refresh_flags) +{ + /* + * refresh_flags contains REFRESH_QUIET, so the only errors + * are for unmerged entries. + */ + if (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN)) + die_resolve_conflict("commit"); +} + static char *prepare_index(int argc, const char **argv, const char *prefix, int is_status) { int fd; @@@ -307,7 -283,7 +307,7 @@@ if (all || (also && pathspec && *pathspec)) { int fd = hold_locked_index(&index_lock, 1); add_files_to_cache(also ? prefix : NULL, pathspec, 0); - refresh_cache(refresh_flags); + refresh_cache_or_die(refresh_flags); if (write_cache(fd, active_cache, active_nr) || close_lock_file(&index_lock)) die("unable to write new_index file"); @@@ -326,7 -302,7 +326,7 @@@ */ if (!pathspec || !*pathspec) { fd = hold_locked_index(&index_lock, 1); - refresh_cache(refresh_flags); + refresh_cache_or_die(refresh_flags); if (write_cache(fd, active_cache, active_nr) || commit_locked_index(&index_lock)) die("unable to write new_index file"); @@@ -614,7 -590,7 +614,7 @@@ static int prepare_to_commit(const cha /* This checks if committer ident is explicitly given */ git_committer_info(0); - if (use_editor) { + if (use_editor && include_status) { char *author_ident; const char *committer_ident; @@@ -656,7 -632,7 +656,7 @@@ author_ident); free(author_ident); - if (!user_ident_explicitly_given) + if (!user_ident_sufficiently_given()) fprintf(fp, "%s" "# Committer: %s\n", @@@ -1047,7 -1023,7 +1047,7 @@@ int cmd_status(int argc, const char **a s.pathspec = get_pathspec(prefix, argv); read_cache(); - refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED); + refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL); s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0; s.in_merge = in_merge; wt_status_collect(&s); @@@ -1078,12 -1054,9 +1078,12 @@@ static void print_summary(const char *p { struct rev_info rev; struct commit *commit; - static const char *format = "format:%h] %s"; + struct strbuf format = STRBUF_INIT; unsigned char junk_sha1[20]; const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL); + struct pretty_print_context pctx = {0}; + struct strbuf author_ident = STRBUF_INIT; + struct strbuf committer_ident = STRBUF_INIT; commit = lookup_commit(sha1); if (!commit) @@@ -1091,25 -1064,6 +1091,25 @@@ if (!commit || parse_commit(commit)) die("could not parse newly created commit"); + strbuf_addstr(&format, "format:%h] %s"); + + format_commit_message(commit, "%an <%ae>", &author_ident, &pctx); + format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx); + if (strbuf_cmp(&author_ident, &committer_ident)) { + strbuf_addstr(&format, "\n Author: "); + strbuf_addbuf_percentquote(&format, &author_ident); + } + if (!user_ident_sufficiently_given()) { + strbuf_addstr(&format, "\n Committer: "); + strbuf_addbuf_percentquote(&format, &committer_ident); + if (advice_implicit_identity) { + strbuf_addch(&format, '\n'); + strbuf_addstr(&format, implicit_ident_advice); + } + } + strbuf_release(&author_ident); + strbuf_release(&committer_ident); + init_revisions(&rev, prefix); setup_revisions(0, NULL, &rev, NULL); @@@ -1120,7 -1074,7 +1120,7 @@@ rev.verbose_header = 1; rev.show_root_diff = 1; - get_commit_format(format, &rev); + get_commit_format(format.buf, &rev); rev.always_show_header = 0; rev.diffopt.detect_rename = 1; rev.diffopt.rename_limit = 100; @@@ -1139,11 -1093,10 +1139,11 @@@ struct pretty_print_context ctx = {0}; struct strbuf buf = STRBUF_INIT; ctx.date_mode = DATE_NORMAL; - format_commit_message(commit, format + 7, &buf, &ctx); + format_commit_message(commit, format.buf + 7, &buf, &ctx); printf("%s\n", buf.buf); strbuf_release(&buf); } + strbuf_release(&format); } static int git_commit_config(const char *k, const char *v, void *cb) @@@ -1152,10 -1105,6 +1152,10 @@@ if (!strcmp(k, "commit.template")) return git_config_pathname(&template_file, k, v); + if (!strcmp(k, "commit.status")) { + include_status = git_config_bool(k, v); + return 0; + } return git_status_config(k, v, s); } @@@ -1301,7 -1250,7 +1301,7 @@@ int cmd_commit(int argc, const char **a "new_index file. Check that disk is not full or quota is\n" "not exceeded, and then \"git reset HEAD\" to recover."); - rerere(); + rerere(0); run_hook(get_index_file(), "post-commit", NULL); if (!quiet) print_summary(prefix, commit_sha1);