{"thread":{"id":"33738","subject":"[RFC] git: make signoff header configurable","startedAt":"2013-05-06T21:33:52Z","lastAt":"2013-05-07T04:53:31Z","messageCount":2,"participants":["Arend van Spriel","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"216556","messageId":"1367876032-6833-1-git-send-email-arend@broadcom.com","threadId":"33738","inReplyTo":null,"subject":"[RFC] git: make signoff header configurable","fromName":"Arend van Spriel","fromEmail":"arend@broadcom.com","sentAt":"2013-05-06T21:33:52Z","receivedAt":"2013-05-06T21:33:52Z","isPatch":false,"sender":{"key":"arend@broadcom.com","avatar":null},"body":"When using -s for commit, revert, and format-patch (there\nmay be more) command the comments message gets a generated\nand hard-coded signed-off-by message. For some projects a\ndifferent header is used, eg. HostAP. Adding a config parameter\nnamed 'signoff.label'.\n\nSigned-off-by: Arend van Spriel <arend@broadcom.com>\n---\nI had an itch to scratch. Like the -s command line parameter to\nget the signed-off message added, but not all projects use the\nsame signature format. So let me know what you think about this\nidea. Never contributed to git before so decided to make it an\nRFC first as this solution may be a bit hack-ish.\n\nRegards,\nArend\n---\n builtin/commit.c |    5 +++--\n config.c         |   12 ++++++++++++\n sequencer.c      |   15 +++++++++++++--\n sequencer.h      |    3 ++-\n 4 files changed, 30 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex d2f30d9..6e28325 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -848,6 +848,7 @@ static int rest_is_empty(struct strbuf *sb, int start)\n {\n \tint i, eol;\n \tconst char *nl;\n+\tchar *so_hdr = get_signoff_header();\n \n \t/* Check if the rest is just whitespace and Signed-of-by's. */\n \tfor (i = start; i < sb->len; i++) {\n@@ -857,8 +858,8 @@ static int rest_is_empty(struct strbuf *sb, int start)\n \t\telse\n \t\t\teol = sb->len;\n \n-\t\tif (strlen(sign_off_header) <= eol - i &&\n-\t\t    !prefixcmp(sb->buf + i, sign_off_header)) {\n+\t\tif (strlen(so_hdr) <= eol - i &&\n+\t\t    !prefixcmp(sb->buf + i, so_hdr)) {\n \t\t\ti = eol;\n \t\t\tcontinue;\n \t\t}\ndiff --git a/config.c b/config.c\nindex aefd80b..110fa04 100644\n--- a/config.c\n+++ b/config.c\n@@ -9,6 +9,7 @@\n #include \"exec_cmd.h\"\n #include \"strbuf.h\"\n #include \"quote.h\"\n+#include \"sequencer.h\"\n \n typedef struct config_file {\n \tstruct config_file *prev;\n@@ -892,6 +893,17 @@ int git_default_config(const char *var, const char *value, void *dummy)\n \t\tpack_size_limit_cfg = git_config_ulong(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"signoff.label\")) {\n+\t\tconst char *label;\n+\n+\t\tif (!git_config_string(&label, var, value)) {\n+\t\t\tsize_t len = strlen(label) + 3;\n+\t\t\tsign_off_header = xcalloc(1, len);\n+\t\t\tsnprintf(sign_off_header, len, \"%s: \", label);\n+\t\t\tfree((void *)label);\n+\t\t}\n+\t\treturn 0;\n+\t}\n \t/* Add other config variables here and to Documentation/config.txt. */\n \treturn 0;\n }\ndiff --git a/sequencer.c b/sequencer.c\nindex cf8fbeb..7e9a0dd 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -17,9 +17,20 @@\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \n-const char sign_off_header[] = \"Signed-off-by: \";\n+static const char def_signoff_header[] = \"Signed-off-by\";\n+char *sign_off_header = NULL;\n static const char cherry_picked_prefix[] = \"(cherry picked from commit \";\n \n+char *get_signoff_header(void)\n+{\n+\tif (!sign_off_header) {\n+\t\tsize_t len = strlen(def_signoff_header) + 3;\n+\t\tsign_off_header = xcalloc(1, len);\n+\t\tsnprintf(sign_off_header, len, \"%s: \", def_signoff_header);\n+\t}\n+\treturn sign_off_header;\n+}\n+\n static int is_rfc2822_line(const char *buf, int len)\n {\n \tint i;\n@@ -1130,7 +1141,7 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)\n \tstruct strbuf sob = STRBUF_INIT;\n \tint has_footer;\n \n-\tstrbuf_addstr(&sob, sign_off_header);\n+\tstrbuf_addstr(&sob, get_signoff_header());\n \tstrbuf_addstr(&sob, fmt_name(getenv(\"GIT_COMMITTER_NAME\"),\n \t\t\t\tgetenv(\"GIT_COMMITTER_EMAIL\")));\n \tstrbuf_addch(&sob, '\\n');\ndiff --git a/sequencer.h b/sequencer.h\nindex 1fc22dc..5a91105 100644\n--- a/sequencer.h\n+++ b/sequencer.h\n@@ -48,8 +48,9 @@ struct replay_opts {\n \n int sequencer_pick_revisions(struct replay_opts *opts);\n \n-extern const char sign_off_header[];\n+extern char* sign_off_header;\n \n+char *get_signoff_header(void);\n void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag);\n \n #endif\n-- \n1.7.10.4\n"},{"id":"216593","messageId":"7vehdjo0fo.fsf@alter.siamese.dyndns.org","threadId":"33738","inReplyTo":"1367876032-6833-1-git-send-email-arend@broadcom.com","subject":"Re: [RFC] git: make signoff header configurable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-07T04:53:31Z","receivedAt":"2013-05-07T04:53:31Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Arend van Spriel\" <arend@broadcom.com> writes:\n\n> I had an itch to scratch. Like the -s command line parameter to\n> get the signed-off message added, but not all projects use the\n> same signature format. So let me know what you think about this\n> idea. Never contributed to git before so decided to make it an\n> RFC first as this solution may be a bit hack-ish.\n\nIt is customary to declare things like \"char *get_signoff_header()\"\nthat are meant to be available pretty much everywhere in cache.h\n(look for /* Environment bits from configuration mechanism */) and\nnot in an unrelated header like sequencer.h (which builtin/commit.c\nor config.c have no business including).  Also, default-config may\nbe a bit too generic place to read this information; it is used by\nmany read-only commands like \"log\", \"diff\", etc. that have no reason\nto know this custom trailer setting.\n\nOther than these, I do not see anything glaringly \"hack-ish\" in the\nimplementation itself.  Of course, a non-RFC patch would come with\ndocumentation and test script updates.\n\nBy the way, what you are adding is a trailer, not a header, as it\ncomes at the very end ;-).\n\nTo projects that adopt the S-o-b convention from the kernel, the act\nof signing off has a very specific legal meaning (I know it is not\nan electronic signature, but the intention counts in court); I am\nnot sure if it is even a good idea to make \"-s\" mean something\ndifferent depending on the configuration in the first place, though.\n\nWouldn't a commit template a better alternative for appending a\nrandom stuff in the log message, I wonder.\n\n>  builtin/commit.c |    5 +++--\n>  config.c         |   12 ++++++++++++\n>  sequencer.c      |   15 +++++++++++++--\n>  sequencer.h      |    3 ++-\n>  4 files changed, 30 insertions(+), 5 deletions(-)\n> diff --git a/sequencer.h b/sequencer.h\n> index 1fc22dc..5a91105 100644\n> --- a/sequencer.h\n> +++ b/sequencer.h\n> @@ -48,8 +48,9 @@ struct replay_opts {\n>  \n>  int sequencer_pick_revisions(struct replay_opts *opts);\n>  \n> -extern const char sign_off_header[];\n> +extern char* sign_off_header;\n\nThe asterisk sticks to the identifier, not type, i.e.\n\n\textern char *signoff_label;\n\nBut I suspect you do not need to make this extern (for the same\nreason we can keep def_signoff_header[] a static), as long as the\npublic facing API \"get-signoff-header\" is extern.\n\n> +char *get_signoff_header(void);\n>  void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag);\n>  \n>  #endif\n"}]}