{"thread":{"id":"11580","subject":"[PATCH] Use commit template when cherry picking","startedAt":"2008-01-11T07:45:05Z","lastAt":"2008-01-11T21:24:22Z","messageCount":4,"participants":["Deepak Saxena","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64994","messageId":"20080111074505.GC14022@plexity.net","threadId":"11580","inReplyTo":null,"subject":"[PATCH] Use commit template when cherry picking","fromName":"Deepak Saxena","fromEmail":"dsaxena@plexity.net","sentAt":"2008-01-11T07:45:05Z","receivedAt":"2008-01-11T07:45:05Z","isPatch":true,"sender":{"key":"dsaxena@plexity.net","avatar":null},"body":"When using a workflow with a default commit message template/header,\ngit-cherry-pick should also pick that up. Users can manually read\nthe header into the commit message, but this is simpler.\n\nSigned-off-by: Deepak Saxena <dsaxena@mvista.com>\n\n---\n\nWe are using git to manage our kernel tree and we often cherry-pick\npatches from upstream and while we want to save the original commit\nmessage, we also want to apply our default commit header to the log.\nIf this patch is not the ideal solution, please let me know how\nI should go about this.\n\n(I'm not on the mailing list, so please cc: me on replies)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 73f1e35..6bd937a 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -43,7 +43,8 @@ static enum {\n \tCOMMIT_PARTIAL,\n } commit_style;\n \n-static char *logfile, *force_author, *template_file;\n+char *template_file;\n+static char *logfile, *force_author;\n static char *edit_message, *use_message;\n static int all, edit_flag, also, interactive, only, amend, signoff;\n static int quiet, verbose, untracked_files, no_verify, allow_empty;\n@@ -89,7 +90,7 @@ static struct option builtin_commit_options[] = {\n \tOPT_STRING('c', \"reedit-message\", &edit_message, \"COMMIT\", \"reuse and edit message from specified commit \"),\n \tOPT_STRING('C', \"reuse-message\", &use_message, \"COMMIT\", \"reuse message from specified commit\"),\n \tOPT_BOOLEAN('s', \"signoff\", &signoff, \"add Signed-off-by: header\"),\n-\tOPT_STRING('t', \"template\", &template_file, \"FILE\", \"use specified template file\"),\n+\tOPT_STRING('t', \"template\", &template_file, \"FILE\", \"use specified commit message template file\"),\n \tOPT_BOOLEAN('e', \"edit\", &edit_flag, \"force edit of commit\"),\n \n \tOPT_GROUP(\"Commit contents options\"),\ndiff --git a/builtin-revert.c b/builtin-revert.c\nindex 4bf8eb2..cbb57c6 100644\n--- a/builtin-revert.c\n+++ b/builtin-revert.c\n@@ -8,6 +8,7 @@\n #include \"exec_cmd.h\"\n #include \"utf8.h\"\n #include \"parse-options.h\"\n+#include \"strbuf.h\"\n \n /*\n  * This implements the builtins revert and cherry-pick.\n@@ -49,6 +50,7 @@ static void parse_args(int argc, const char **argv)\n \t\tOPT_BOOLEAN('n', \"no-commit\", &no_commit, \"don't automatically commit\"),\n \t\tOPT_BOOLEAN('e', \"edit\", &edit, \"edit the commit message\"),\n \t\tOPT_BOOLEAN('x', NULL, &no_replay, \"append commit name when cherry-picking\"),\n+\t\tOPT_STRING('t', \"template\", &template_file, \"FILE\", \"use specified commit message template file\"),\n \t\tOPT_BOOLEAN('r', NULL, &noop, \"no-op (backward compatibility)\"),\n \t\tOPT_INTEGER('m', \"mainline\", &mainline, \"parent number\"),\n \t\tOPT_END(),\n@@ -249,16 +251,24 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n {\n \tunsigned char head[20];\n \tstruct commit *base, *next, *parent;\n+\tstruct strbuf sb;\n \tint i;\n \tchar *oneline, *reencoded_message = NULL;\n \tconst char *message, *encoding;\n \tconst char *defmsg = xstrdup(git_path(\"MERGE_MSG\"));\n \n-\tgit_config(git_default_config);\n+\tgit_config(git_commit_config);\t\n \tme = action == REVERT ? \"revert\" : \"cherry-pick\";\n \tsetenv(GIT_REFLOG_ACTION, me, 0);\n \tparse_args(argc, argv);\n \n+\tstrbuf_init(&sb, 0);\n+\tif (template_file) {\n+\t\tif (strbuf_read_file(&sb, template_file, 0) < 0)\n+\t\t\t die(\"could not read %s: %s\", \n+\t\t\t\ttemplate_file, strerror(errno));\n+\t}\n+\n \t/* this is copied from the shell script, but it's never triggered... */\n \tif (action == REVERT && !no_replay)\n \t\tdie(\"revert is incompatible with replay\");\n@@ -332,6 +342,8 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \n \toneline = get_oneline(message);\n \n+\tadd_to_msg(sb.buf);\n+\n \tif (action == REVERT) {\n \t\tchar *oneline_body = strchr(oneline, ' ');\n \ndiff --git a/commit.h b/commit.h\nindex 10e2b5d..7746ec6 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -23,6 +23,7 @@ struct commit {\n \n extern int save_commit_buffer;\n extern const char *commit_type;\n+extern char *template_file;\n \n /* While we can decorate any object with a name, it's only used for commits.. */\n extern struct decoration name_decoration;\n@@ -116,6 +117,8 @@ int in_merge_bases(struct commit *, struct commit **, int);\n extern int interactive_add(int argc, const char **argv, const char *prefix);\n extern int rerere(void);\n \n+extern int git_commit_config(const char *k, const char *v);\n+\n static inline int single_parent(struct commit *commit)\n {\n \treturn commit->parents && !commit->parents->next;\n\n-- \n   _____   __o  Living Deepak Saxena - CarFree and CareFree            (o>\n------    -\\<,  Towards Carfree Cities 2008 - www.carfreeportland.org  //\\\n ----- ( )/ ( ) Linux Plumber's Conference - www.linuxplumbersconf.org V_/_\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"},{"id":"65009","messageId":"alpine.LSU.1.00.0801111208020.31053@racer.site","threadId":"11580","inReplyTo":"20080111074505.GC14022@plexity.net","subject":"Re: [PATCH] Use commit template when cherry picking","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-11T12:10:37Z","receivedAt":"2008-01-11T12:10:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 10 Jan 2008, Deepak Saxena wrote:\n\n> We are using git to manage our kernel tree and we often cherry-pick \n> patches from upstream and while we want to save the original commit \n> message, we also want to apply our default commit header to the log. If \n> this patch is not the ideal solution, please let me know how I should go \n> about this.\n\nI would do a combination of \"cherry-pick -n\", \"cat-file commit <commit> | \nsed '1,/^$/d'\" and \"commit -F\" or \"commit -f\".\n\nYou can make this an alias, too.\n\nHth,\nDscho\n"},{"id":"65049","messageId":"7v7iig2npe.fsf@gitster.siamese.dyndns.org","threadId":"11580","inReplyTo":"alpine.LSU.1.00.0801111208020.31053@racer.site","subject":"Re: [PATCH] Use commit template when cherry picking","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-11T18:59:09Z","receivedAt":"2008-01-11T18:59:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> I would do a combination of \"cherry-pick -n\", \"cat-file commit <commit> | \n> sed '1,/^$/d'\" and \"commit -F\" or \"commit -f\".\n\nDoesn't cherry-pick have -e switch to allow you further edit the\nmessage?\n"},{"id":"65065","messageId":"alpine.LSU.1.00.0801112123410.31053@racer.site","threadId":"11580","inReplyTo":"7v7iig2npe.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Use commit template when cherry picking","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-11T21:24:22Z","receivedAt":"2008-01-11T21:24:22Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 11 Jan 2008, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > I would do a combination of \"cherry-pick -n\", \"cat-file commit \n> > <commit> | sed '1,/^$/d'\" and \"commit -F\" or \"commit -f\".\n> \n> Doesn't cherry-pick have -e switch to allow you further edit the\n> message?\n\nGood point.  But nevertheless, Deepak wanted to have a template which is \nautomatically added, and I think the only way to do that right now is as I \ndescribed.\n\nCiao,\nDscho\n"}]}