From: Junio C Hamano Date: Tue, 22 Jun 2010 16:31:48 +0000 (-0700) Subject: Merge branch 'cc/maint-commit-reflog-msg' into maint X-Git-Tag: v1.7.2-rc0~18^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/81b43b54b2b6cfe917820b26bf206254d8b6738e?hp=-c Merge branch 'cc/maint-commit-reflog-msg' into maint * cc/maint-commit-reflog-msg: commit: use value of GIT_REFLOG_ACTION env variable as reflog message --- 81b43b54b2b6cfe917820b26bf206254d8b6738e diff --combined builtin/commit.c index 9d59af0344,58bad61306..80c621dc06 --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -48,11 -48,6 +48,11 @@@ static const char implicit_ident_advice "\n" " git commit --amend --author='Your Name '\n"; +static const char empty_amend_advice[] = +"You asked to amend the most recent commit, but doing so would make\n" +"it empty. You can repeat your command with --allow-empty, or you can\n" +"remove the commit entirely with \"git reset HEAD^\".\n"; + static unsigned char head_sha1[20]; static char *use_message_buffer; @@@ -460,21 -455,15 +460,21 @@@ static void determine_author_info(void if (!a) die("invalid commit: %s", use_message); - lb = strstr(a + 8, " <"); - rb = strstr(a + 8, "> "); - eol = strchr(a + 8, '\n'); - if (!lb || !rb || !eol) + lb = strchrnul(a + strlen("\nauthor "), '<'); + rb = strchrnul(lb, '>'); + eol = strchrnul(rb, '\n'); + if (!*lb || !*rb || !*eol) die("invalid commit: %s", use_message); - name = xstrndup(a + 8, lb - (a + 8)); - email = xstrndup(lb + 2, rb - (lb + 2)); - date = xstrndup(rb + 2, eol - (rb + 2)); + if (lb == a + strlen("\nauthor ")) + /* \nauthor */ + name = xcalloc(1, 1); + else + name = xmemdupz(a + strlen("\nauthor "), + (lb - strlen(" ") - + (a + strlen("\nauthor ")))); + email = xmemdupz(lb + strlen("<"), rb - (lb + strlen("<"))); + date = xmemdupz(rb + strlen("> "), eol - (rb + strlen("> "))); } if (force_author) { @@@ -704,8 -693,6 +704,8 @@@ static int prepare_to_commit(const cha if (!commitable && !in_merge && !allow_empty && !(amend && is_a_merge(head_sha1))) { run_status(stdout, index_file, prefix, 0, s); + if (amend) + fputs(empty_amend_advice, stderr); return 0; } @@@ -1030,7 -1017,6 +1030,7 @@@ static int git_status_config(const cha int cmd_status(int argc, const char **argv, const char *prefix) { struct wt_status s; + int fd; unsigned char sha1[20]; static struct option builtin_status_options[] = { OPT__VERBOSE(&verbose), @@@ -1064,14 -1050,6 +1064,14 @@@ read_cache_preload(s.pathspec); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL); + + fd = hold_locked_index(&index_lock, 0); + if (0 <= fd) { + if (!write_cache(fd, active_cache, active_nr)) + commit_locked_index(&index_lock); + rollback_lock_file(&index_lock); + } + s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0; s.in_merge = in_merge; wt_status_collect(&s); @@@ -1160,11 -1138,13 +1160,11 @@@ static void print_summary(const char *p initial_commit ? " (root-commit)" : ""); if (!log_tree_commit(&rev, commit)) { - struct pretty_print_context ctx = {0}; - struct strbuf buf = STRBUF_INIT; - ctx.date_mode = DATE_NORMAL; - format_commit_message(commit, format.buf + 7, &buf, &ctx); - printf("%s\n", buf.buf); - strbuf_release(&buf); + rev.always_show_header = 1; + rev.use_terminator = 1; + log_tree_commit(&rev, commit); } + strbuf_release(&format); } @@@ -1252,13 -1232,16 +1252,16 @@@ int cmd_commit(int argc, const char **a } /* Determine parents */ + reflog_msg = getenv("GIT_REFLOG_ACTION"); if (initial_commit) { - reflog_msg = "commit (initial)"; + if (!reflog_msg) + reflog_msg = "commit (initial)"; } else if (amend) { struct commit_list *c; struct commit *commit; - reflog_msg = "commit (amend)"; + if (!reflog_msg) + reflog_msg = "commit (amend)"; commit = lookup_commit(head_sha1); if (!commit || parse_commit(commit)) die("could not parse HEAD commit"); @@@ -1269,7 -1252,8 +1272,8 @@@ struct strbuf m = STRBUF_INIT; FILE *fp; - reflog_msg = "commit (merge)"; + if (!reflog_msg) + reflog_msg = "commit (merge)"; pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next; fp = fopen(git_path("MERGE_HEAD"), "r"); if (fp == NULL) @@@ -1292,7 -1276,8 +1296,8 @@@ if (allow_fast_forward) parents = reduce_heads(parents); } else { - reflog_msg = "commit"; + if (!reflog_msg) + reflog_msg = "commit"; pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next; }