{"thread":{"id":"36749","subject":"[PATCH v12 03/11] trailer: read and process config information","startedAt":"2014-05-25T05:32:11Z","lastAt":"2014-07-01T13:34:50Z","messageCount":19,"participants":["Christian Couder","Junio C Hamano","Jakub Narębski"],"isPatch":true,"patchVersion":12,"patchTotal":11},"messages":[{"id":"242653","messageId":"20140525051254.5329.66539.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":null,"subject":"[PATCH v12 00/11] Add interpret-trailers builtin","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:11Z","receivedAt":"2014-05-25T05:32:11Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This patch series implements a new command:\n\n        git interpret-trailers\n\nand an infrastructure to process trailers that can be reused,\nfor example in \"commit.c\".\n\n1) Rationale:\n\nThis command should help with RFC 822 style headers, called\n\"trailers\", that are found at the end of commit messages.\n\n(Note that these headers do not follow and are not intended to\nfollow many rules that are in RFC 822. For example they do not\nfollow the line breaking rules, the encoding rules and probably\nmany other rules.)\n\nFor a long time, these trailers have become a de facto standard\nway to add helpful information into commit messages.\n\nUntil now git commit has only supported the well known\n\"Signed-off-by: \" trailer, that is used by many projects like\nthe Linux kernel and Git.\n\nIt is better to keep builtin/commit.c uncontaminated by any more\nhard-wired logic, like what we have for the signed-off-by line.  Any\nnew things can and should be doable in hooks, and this filter would\nhelp writing these hooks.\n\nAnd that is why the design goal of the filter is to make it at least\nas powerful as the built-in logic we have for signed-off-by lines;\nthat would allow us to later eject the hard-wired logic for\nsigned-off-by line from the main codepath, if/when we wanted to.\n\nAlternatively, we could build a library-ish API around this filter\ncode and replace the hard-wired logic for signed-off-by line with a\ncall into that API, if/when we wanted to, but that requires (in\naddition to the \"at least as powerful as the built-in logic\") that\nthe implementation of this stand-alone filter can be cleanly made\ninto a reusable library, so that is a bit higher bar to cross than\n\"everything can be doable with hooks\" alternative.\n\n2) Current state:\n\nCurrently the usage string of this command is:\n\ngit interpret-trailers [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]\n\nThe following features are implemented:\n\n        - the result is printed on stdout\n        - the --trailer arguments are interpreted\n        - messages read from <file>... or stdin are interpreted\n        - the \"trailer.<token>.key\" options in the config are interpreted\n        - the \"trailer.<token>.where\" options are interpreted\n        - the \"trailer.<token>.ifExist\" options are interpreted\n        - the \"trailer.<token>.ifMissing\" options are interpreted\n        - the \"trailer.<token>.command\" config works\n        - $ARG can be used in commands\n        - messages can contain a patch\n        - lines in messages starting with a comment char are ignored (new)\n        - there are 35 tests\n        - there is some documentation\n        - there are examples in the documentation (new)\n\nPossible improvements:\n        - integration with \"git commit\"\n        - support GIT_COMMIT_PROTO env variable in commands\n\n3) Changes since version 11, thanks to Michael, Jonathan and Junio:\n\n* the patch to ignore comments in messages has been squashed into\n  the original series (5/11 and 8/11)\n* the comment char config variable is used to ignore comments in\n  messages (as suggested by Michael) (5/11)\n* the patch that add examples in the documentation has been\n  squashed into the original (11/11)\n* one of the examples has been split into 2 examples (as suggested\n  by Junio) (11/11)\n* there is no special case for # when printing the trailers, (as\n  suggested by Junio); so we always use ': ' as separator, except\n  when trailer.<token>.key ends with a non alphanumeric character;\n  in that case we add no separator as we suppose that the key\n  already contains a separator (6/11, 8/11 and 10/11)\n* documentation has been improved to be clearer, and more\n  explicit, especially about how the key config variable is\n  used (11/11)\n\nChristian Couder (11):\n  trailer: add data structures and basic functions\n  trailer: process trailers from input message and arguments\n  trailer: read and process config information\n  trailer: process command line trailer arguments\n  trailer: parse trailers from file or stdin\n  trailer: put all the processing together and print\n  trailer: add interpret-trailers command\n  trailer: add tests for \"git interpret-trailers\"\n  trailer: execute command from 'trailer.<name>.command'\n  trailer: add tests for commands in config file\n  Documentation: add documentation for 'git interpret-trailers'\n\n .gitignore                               |   1 +\n Documentation/git-interpret-trailers.txt | 264 +++++++++++\n Makefile                                 |   2 +\n builtin.h                                |   1 +\n builtin/interpret-trailers.c             |  44 ++\n command-list.txt                         |   1 +\n git.c                                    |   1 +\n t/t7513-interpret-trailers.sh            | 568 +++++++++++++++++++++++\n trailer.c                                | 755 +++++++++++++++++++++++++++++++\n trailer.h                                |   6 +\n 10 files changed, 1643 insertions(+)\n create mode 100644 Documentation/git-interpret-trailers.txt\n create mode 100644 builtin/interpret-trailers.c\n create mode 100755 t/t7513-interpret-trailers.sh\n create mode 100644 trailer.c\n create mode 100644 trailer.h\n\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242650","messageId":"20140525053223.5329.33185.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 01/11] trailer: add data structures and basic functions","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:12Z","receivedAt":"2014-05-25T05:32:12Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"We will use a doubly linked list to store all information\nabout trailers and their configuration.\n\nThis way we can easily remove or add trailers to or from\ntrailer lists while traversing the lists in either direction.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Makefile  |  1 +\n trailer.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 50 insertions(+)\n create mode 100644 trailer.c\n\ndiff --git a/Makefile b/Makefile\nindex b4af1e2..ec90feb 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -871,6 +871,7 @@ LIB_OBJS += submodule.o\n LIB_OBJS += symlinks.o\n LIB_OBJS += tag.o\n LIB_OBJS += trace.o\n+LIB_OBJS += trailer.o\n LIB_OBJS += transport.o\n LIB_OBJS += transport-helper.o\n LIB_OBJS += tree-diff.o\ndiff --git a/trailer.c b/trailer.c\nnew file mode 100644\nindex 0000000..db93a63\n--- /dev/null\n+++ b/trailer.c\n@@ -0,0 +1,49 @@\n+#include \"cache.h\"\n+/*\n+ * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>\n+ */\n+\n+enum action_where { WHERE_AFTER, WHERE_BEFORE };\n+enum action_if_exists { EXISTS_ADD_IF_DIFFERENT, EXISTS_ADD_IF_DIFFERENT_NEIGHBOR,\n+\t\t\tEXISTS_ADD, EXISTS_OVERWRITE, EXISTS_DO_NOTHING };\n+enum action_if_missing { MISSING_ADD, MISSING_DO_NOTHING };\n+\n+struct conf_info {\n+\tchar *name;\n+\tchar *key;\n+\tchar *command;\n+\tenum action_where where;\n+\tenum action_if_exists if_exists;\n+\tenum action_if_missing if_missing;\n+};\n+\n+struct trailer_item {\n+\tstruct trailer_item *previous;\n+\tstruct trailer_item *next;\n+\tconst char *token;\n+\tconst char *value;\n+\tstruct conf_info conf;\n+};\n+\n+static int same_token(struct trailer_item *a, struct trailer_item *b, int alnum_len)\n+{\n+\treturn !strncasecmp(a->token, b->token, alnum_len);\n+}\n+\n+static int same_value(struct trailer_item *a, struct trailer_item *b)\n+{\n+\treturn !strcasecmp(a->value, b->value);\n+}\n+\n+static int same_trailer(struct trailer_item *a, struct trailer_item *b, int alnum_len)\n+{\n+\treturn same_token(a, b, alnum_len) && same_value(a, b);\n+}\n+\n+/* Get the length of buf from its beginning until its last alphanumeric character */\n+static size_t alnum_len(const char *buf, size_t len)\n+{\n+\twhile (len > 0 && !isalnum(buf[len - 1]))\n+\t\tlen--;\n+\treturn len;\n+}\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242649","messageId":"20140525053223.5329.32217.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 02/11] trailer: process trailers from input message and arguments","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:13Z","receivedAt":"2014-05-25T05:32:13Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Implement the logic to process trailers from the input message\nand from arguments.\n\nAt the beginning trailers from the input message are in their\nown \"in_tok\" doubly linked list, and trailers from arguments\nare in their own \"arg_tok\" doubly linked list.\n\nThe lists are traversed and when an \"arg_tok\" should be \"applied\",\nit is removed from its list and inserted into the \"in_tok\" list.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n trailer.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 198 insertions(+)\n\ndiff --git a/trailer.c b/trailer.c\nindex db93a63..52108c2 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -47,3 +47,201 @@ static size_t alnum_len(const char *buf, size_t len)\n \t\tlen--;\n \treturn len;\n }\n+\n+static void free_trailer_item(struct trailer_item *item)\n+{\n+\tfree(item->conf.name);\n+\tfree(item->conf.key);\n+\tfree(item->conf.command);\n+\tfree((char *)item->token);\n+\tfree((char *)item->value);\n+\tfree(item);\n+}\n+\n+static void add_arg_to_input_list(struct trailer_item *in_tok,\n+\t\t\t\t  struct trailer_item *arg_tok)\n+{\n+\tif (arg_tok->conf.where == WHERE_AFTER) {\n+\t\targ_tok->next = in_tok->next;\n+\t\tin_tok->next = arg_tok;\n+\t\targ_tok->previous = in_tok;\n+\t\tif (arg_tok->next)\n+\t\t\targ_tok->next->previous = arg_tok;\n+\t} else {\n+\t\targ_tok->previous = in_tok->previous;\n+\t\tin_tok->previous = arg_tok;\n+\t\targ_tok->next = in_tok;\n+\t\tif (arg_tok->previous)\n+\t\t\targ_tok->previous->next = arg_tok;\n+\t}\n+}\n+\n+static int check_if_different(struct trailer_item *in_tok,\n+\t\t\t      struct trailer_item *arg_tok,\n+\t\t\t      int alnum_len, int check_all)\n+{\n+\tenum action_where where = arg_tok->conf.where;\n+\tdo {\n+\t\tif (!in_tok)\n+\t\t\treturn 1;\n+\t\tif (same_trailer(in_tok, arg_tok, alnum_len))\n+\t\t\treturn 0;\n+\t\t/*\n+\t\t * if we want to add a trailer after another one,\n+\t\t * we have to check those before this one\n+\t\t */\n+\t\tin_tok = (where == WHERE_AFTER) ? in_tok->previous : in_tok->next;\n+\t} while (check_all);\n+\treturn 1;\n+}\n+\n+static void apply_arg_if_exists(struct trailer_item *in_tok,\n+\t\t\t\tstruct trailer_item *arg_tok,\n+\t\t\t\tint alnum_len)\n+{\n+\tswitch (arg_tok->conf.if_exists) {\n+\tcase EXISTS_DO_NOTHING:\n+\t\tfree_trailer_item(arg_tok);\n+\t\tbreak;\n+\tcase EXISTS_OVERWRITE:\n+\t\tfree((char *)in_tok->value);\n+\t\tin_tok->value = xstrdup(arg_tok->value);\n+\t\tfree_trailer_item(arg_tok);\n+\t\tbreak;\n+\tcase EXISTS_ADD:\n+\t\tadd_arg_to_input_list(in_tok, arg_tok);\n+\t\tbreak;\n+\tcase EXISTS_ADD_IF_DIFFERENT:\n+\t\tif (check_if_different(in_tok, arg_tok, alnum_len, 1))\n+\t\t\tadd_arg_to_input_list(in_tok, arg_tok);\n+\t\telse\n+\t\t\tfree_trailer_item(arg_tok);\n+\t\tbreak;\n+\tcase EXISTS_ADD_IF_DIFFERENT_NEIGHBOR:\n+\t\tif (check_if_different(in_tok, arg_tok, alnum_len, 0))\n+\t\t\tadd_arg_to_input_list(in_tok, arg_tok);\n+\t\telse\n+\t\t\tfree_trailer_item(arg_tok);\n+\t\tbreak;\n+\t}\n+}\n+\n+static void remove_from_list(struct trailer_item *item,\n+\t\t\t     struct trailer_item **first)\n+{\n+\tif (item->next)\n+\t\titem->next->previous = item->previous;\n+\tif (item->previous)\n+\t\titem->previous->next = item->next;\n+\telse\n+\t\t*first = item->next;\n+}\n+\n+static struct trailer_item *remove_first(struct trailer_item **first)\n+{\n+\tstruct trailer_item *item = *first;\n+\t*first = item->next;\n+\tif (item->next) {\n+\t\titem->next->previous = NULL;\n+\t\titem->next = NULL;\n+\t}\n+\treturn item;\n+}\n+\n+static void process_input_token(struct trailer_item *in_tok,\n+\t\t\t\tstruct trailer_item **arg_tok_first,\n+\t\t\t\tenum action_where where)\n+{\n+\tstruct trailer_item *arg_tok;\n+\tstruct trailer_item *next_arg;\n+\n+\tint after = where == WHERE_AFTER;\n+\tint tok_alnum_len = alnum_len(in_tok->token, strlen(in_tok->token));\n+\n+\tfor (arg_tok = *arg_tok_first; arg_tok; arg_tok = next_arg) {\n+\t\tnext_arg = arg_tok->next;\n+\t\tif (!same_token(in_tok, arg_tok, tok_alnum_len))\n+\t\t\tcontinue;\n+\t\tif (arg_tok->conf.where != where)\n+\t\t\tcontinue;\n+\t\tremove_from_list(arg_tok, arg_tok_first);\n+\t\tapply_arg_if_exists(in_tok, arg_tok, tok_alnum_len);\n+\t\t/*\n+\t\t * If arg has been added to input,\n+\t\t * then we need to process it too now.\n+\t\t */\n+\t\tif ((after ? in_tok->next : in_tok->previous) == arg_tok)\n+\t\t\tin_tok = arg_tok;\n+\t}\n+}\n+\n+static void update_last(struct trailer_item **last)\n+{\n+\tif (*last)\n+\t\twhile ((*last)->next != NULL)\n+\t\t\t*last = (*last)->next;\n+}\n+\n+static void update_first(struct trailer_item **first)\n+{\n+\tif (*first)\n+\t\twhile ((*first)->previous != NULL)\n+\t\t\t*first = (*first)->previous;\n+}\n+\n+static void apply_arg_if_missing(struct trailer_item **in_tok_first,\n+\t\t\t\t struct trailer_item **in_tok_last,\n+\t\t\t\t struct trailer_item *arg_tok)\n+{\n+\tstruct trailer_item **in_tok;\n+\tenum action_where where;\n+\n+\tswitch (arg_tok->conf.if_missing) {\n+\tcase MISSING_DO_NOTHING:\n+\t\tfree_trailer_item(arg_tok);\n+\t\tbreak;\n+\tcase MISSING_ADD:\n+\t\twhere = arg_tok->conf.where;\n+\t\tin_tok = (where == WHERE_AFTER) ? in_tok_last : in_tok_first;\n+\t\tif (*in_tok) {\n+\t\t\tadd_arg_to_input_list(*in_tok, arg_tok);\n+\t\t\t*in_tok = arg_tok;\n+\t\t} else {\n+\t\t\t*in_tok_first = arg_tok;\n+\t\t\t*in_tok_last = arg_tok;\n+\t\t}\n+\t\tbreak;\n+\t}\n+}\n+\n+static void process_trailers_lists(struct trailer_item **in_tok_first,\n+\t\t\t\t   struct trailer_item **in_tok_last,\n+\t\t\t\t   struct trailer_item **arg_tok_first)\n+{\n+\tstruct trailer_item *in_tok;\n+\tstruct trailer_item *arg_tok;\n+\n+\tif (!*arg_tok_first)\n+\t\treturn;\n+\n+\t/* Process input from end to start */\n+\tfor (in_tok = *in_tok_last; in_tok; in_tok = in_tok->previous)\n+\t\tprocess_input_token(in_tok, arg_tok_first, WHERE_AFTER);\n+\n+\tupdate_last(in_tok_last);\n+\n+\tif (!*arg_tok_first)\n+\t\treturn;\n+\n+\t/* Process input from start to end */\n+\tfor (in_tok = *in_tok_first; in_tok; in_tok = in_tok->next)\n+\t\tprocess_input_token(in_tok, arg_tok_first, WHERE_BEFORE);\n+\n+\tupdate_first(in_tok_first);\n+\n+\t/* Process args left */\n+\twhile (*arg_tok_first) {\n+\t\targ_tok = remove_first(arg_tok_first);\n+\t\tapply_arg_if_missing(in_tok_first, in_tok_last, arg_tok);\n+\t}\n+}\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242645","messageId":"20140525053223.5329.63949.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 03/11] trailer: read and process config information","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:14Z","receivedAt":"2014-05-25T05:32:14Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Read the configuration to get trailer information, and then process\nit and store it in a doubly linked list.\n\nThe config information is stored in the list whose first item is\npointed to by:\n\nstatic struct trailer_item *first_conf_item;\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n trailer.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 146 insertions(+)\n\ndiff --git a/trailer.c b/trailer.c\nindex 52108c2..f376be5 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -25,6 +25,8 @@ struct trailer_item {\n \tstruct conf_info conf;\n };\n \n+static struct trailer_item *first_conf_item;\n+\n static int same_token(struct trailer_item *a, struct trailer_item *b, int alnum_len)\n {\n \treturn !strncasecmp(a->token, b->token, alnum_len);\n@@ -245,3 +247,147 @@ static void process_trailers_lists(struct trailer_item **in_tok_first,\n \t\tapply_arg_if_missing(in_tok_first, in_tok_last, arg_tok);\n \t}\n }\n+\n+static int set_where(struct conf_info *item, const char *value)\n+{\n+\tif (!strcasecmp(\"after\", value))\n+\t\titem->where = WHERE_AFTER;\n+\telse if (!strcasecmp(\"before\", value))\n+\t\titem->where = WHERE_BEFORE;\n+\telse\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+static int set_if_exists(struct conf_info *item, const char *value)\n+{\n+\tif (!strcasecmp(\"addIfDifferent\", value))\n+\t\titem->if_exists = EXISTS_ADD_IF_DIFFERENT;\n+\telse if (!strcasecmp(\"addIfDifferentNeighbor\", value))\n+\t\titem->if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR;\n+\telse if (!strcasecmp(\"add\", value))\n+\t\titem->if_exists = EXISTS_ADD;\n+\telse if (!strcasecmp(\"overwrite\", value))\n+\t\titem->if_exists = EXISTS_OVERWRITE;\n+\telse if (!strcasecmp(\"doNothing\", value))\n+\t\titem->if_exists = EXISTS_DO_NOTHING;\n+\telse\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+static int set_if_missing(struct conf_info *item, const char *value)\n+{\n+\tif (!strcasecmp(\"doNothing\", value))\n+\t\titem->if_missing = MISSING_DO_NOTHING;\n+\telse if (!strcasecmp(\"add\", value))\n+\t\titem->if_missing = MISSING_ADD;\n+\telse\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+static struct trailer_item *get_conf_item(const char *name)\n+{\n+\tstruct trailer_item *item;\n+\tstruct trailer_item *previous;\n+\n+\t/* Look up item with same name */\n+\tfor (previous = NULL, item = first_conf_item;\n+\t     item;\n+\t     previous = item, item = item->next) {\n+\t\tif (!strcasecmp(item->conf.name, name))\n+\t\t\treturn item;\n+\t}\n+\n+\t/* Item does not already exists, create it */\n+\titem = xcalloc(sizeof(struct trailer_item), 1);\n+\titem->conf.name = xstrdup(name);\n+\n+\tif (!previous)\n+\t\tfirst_conf_item = item;\n+\telse {\n+\t\tprevious->next = item;\n+\t\titem->previous = previous;\n+\t}\n+\n+\treturn item;\n+}\n+\n+enum trailer_info_type { TRAILER_KEY, TRAILER_COMMAND, TRAILER_WHERE,\n+\t\t\t TRAILER_IF_EXISTS, TRAILER_IF_MISSING };\n+\n+static struct {\n+\tconst char *name;\n+\tenum trailer_info_type type;\n+} trailer_config_items[] = {\n+\t{ \"key\", TRAILER_KEY },\n+\t{ \"command\", TRAILER_COMMAND },\n+\t{ \"where\", TRAILER_WHERE },\n+\t{ \"ifexists\", TRAILER_IF_EXISTS },\n+\t{ \"ifmissing\", TRAILER_IF_MISSING }\n+};\n+\n+static int git_trailer_config(const char *conf_key, const char *value, void *cb)\n+{\n+\tconst char *trailer_item, *variable_name;\n+\tstruct trailer_item *item;\n+\tstruct conf_info *conf;\n+\tchar *name = NULL;\n+\tenum trailer_info_type type;\n+\tint i;\n+\n+\ttrailer_item = skip_prefix(conf_key, \"trailer.\");\n+\tif (!trailer_item)\n+\t\treturn 0;\n+\n+\tvariable_name = strrchr(trailer_item, '.');\n+\tif (!variable_name) {\n+\t\twarning(_(\"two level trailer config variable %s\"), conf_key);\n+\t\treturn 0;\n+\t}\n+\n+\tvariable_name++;\n+\tfor (i = 0; i < ARRAY_SIZE(trailer_config_items); i++) {\n+\t\tif (strcmp(trailer_config_items[i].name, variable_name))\n+\t\t\tcontinue;\n+\t\tname = xstrndup(trailer_item,  variable_name - trailer_item - 1);\n+\t\ttype = trailer_config_items[i].type;\n+\t\tbreak;\n+\t}\n+\n+\tif (!name)\n+\t\treturn 0;\n+\n+\titem = get_conf_item(name);\n+\tconf = &item->conf;\n+\tfree(name);\n+\n+\tswitch (type) {\n+\tcase TRAILER_KEY:\n+\t\tif (conf->key)\n+\t\t\twarning(_(\"more than one %s\"), conf_key);\n+\t\tconf->key = xstrdup(value);\n+\t\tbreak;\n+\tcase TRAILER_COMMAND:\n+\t\tif (conf->command)\n+\t\t\twarning(_(\"more than one %s\"), conf_key);\n+\t\tconf->command = xstrdup(value);\n+\t\tbreak;\n+\tcase TRAILER_WHERE:\n+\t\tif (set_where(conf, value))\n+\t\t\twarning(_(\"unknown value '%s' for key '%s'\"), value, conf_key);\n+\t\tbreak;\n+\tcase TRAILER_IF_EXISTS:\n+\t\tif (set_if_exists(conf, value))\n+\t\t\twarning(_(\"unknown value '%s' for key '%s'\"), value, conf_key);\n+\t\tbreak;\n+\tcase TRAILER_IF_MISSING:\n+\t\tif (set_if_missing(conf, value))\n+\t\t\twarning(_(\"unknown value '%s' for key '%s'\"), value, conf_key);\n+\t\tbreak;\n+\tdefault:\n+\t\tdie(\"internal bug in trailer.c\");\n+\t}\n+\treturn 0;\n+}\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242656","messageId":"20140525053223.5329.31712.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 04/11] trailer: process command line trailer arguments","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:15Z","receivedAt":"2014-05-25T05:32:15Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Parse the trailer command line arguments and put\nthe result into an arg_tok doubly linked list.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n trailer.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 118 insertions(+)\n\ndiff --git a/trailer.c b/trailer.c\nindex f376be5..f79a369 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"string-list.h\"\n /*\n  * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>\n  */\n@@ -391,3 +392,120 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)\n \t}\n \treturn 0;\n }\n+\n+static int parse_trailer(struct strbuf *tok, struct strbuf *val, const char *trailer)\n+{\n+\tsize_t len = strcspn(trailer, \"=:\");\n+\tif (len == 0)\n+\t\treturn error(_(\"empty trailer token in trailer '%s'\"), trailer);\n+\tif (len < strlen(trailer)) {\n+\t\tstrbuf_add(tok, trailer, len);\n+\t\tstrbuf_trim(tok);\n+\t\tstrbuf_addstr(val, trailer + len + 1);\n+\t\tstrbuf_trim(val);\n+\t} else {\n+\t\tstrbuf_addstr(tok, trailer);\n+\t\tstrbuf_trim(tok);\n+\t}\n+\treturn 0;\n+}\n+\n+\n+static void duplicate_conf(struct conf_info *dst, struct conf_info *src)\n+{\n+\t*dst = *src;\n+\tif (src->name)\n+\t\tdst->name = xstrdup(src->name);\n+\tif (src->key)\n+\t\tdst->key = xstrdup(src->key);\n+\tif (src->command)\n+\t\tdst->command = xstrdup(src->command);\n+}\n+\n+static const char *token_from_item(struct trailer_item *item)\n+{\n+\tif (item->conf.key)\n+\t\treturn item->conf.key;\n+\n+\treturn item->conf.name;\n+}\n+\n+static struct trailer_item *new_trailer_item(struct trailer_item *conf_item,\n+\t\t\t\t\t     char *tok, char *val)\n+{\n+\tstruct trailer_item *new = xcalloc(sizeof(*new), 1);\n+\tnew->value = val;\n+\n+\tif (conf_item) {\n+\t\tduplicate_conf(&new->conf, &conf_item->conf);\n+\t\tnew->token = xstrdup(token_from_item(conf_item));\n+\t\tfree(tok);\n+\t} else\n+\t\tnew->token = tok;\n+\n+\treturn new;\n+}\n+\n+static int token_matches_item(const char *tok, struct trailer_item *item, int alnum_len)\n+{\n+\tif (!strncasecmp(tok, item->conf.name, alnum_len))\n+\t\treturn 1;\n+\treturn item->conf.key ? !strncasecmp(tok, item->conf.key, alnum_len) : 0;\n+}\n+\n+static struct trailer_item *create_trailer_item(const char *string)\n+{\n+\tstruct strbuf tok = STRBUF_INIT;\n+\tstruct strbuf val = STRBUF_INIT;\n+\tstruct trailer_item *item;\n+\tint tok_alnum_len;\n+\n+\tif (parse_trailer(&tok, &val, string))\n+\t\treturn NULL;\n+\n+\ttok_alnum_len = alnum_len(tok.buf, tok.len);\n+\n+\t/* Lookup if the token matches something in the config */\n+\tfor (item = first_conf_item; item; item = item->next) {\n+\t\tif (token_matches_item(tok.buf, item, tok_alnum_len)) {\n+\t\t\tstrbuf_release(&tok);\n+\t\t\treturn new_trailer_item(item,\n+\t\t\t\t\t\tNULL,\n+\t\t\t\t\t\tstrbuf_detach(&val, NULL));\n+\t\t}\n+\t}\n+\n+\treturn new_trailer_item(NULL,\n+\t\t\t\tstrbuf_detach(&tok, NULL),\n+\t\t\t\tstrbuf_detach(&val, NULL));\n+}\n+\n+static void add_trailer_item(struct trailer_item **first,\n+\t\t\t     struct trailer_item **last,\n+\t\t\t     struct trailer_item *new)\n+{\n+\tif (!new)\n+\t\treturn;\n+\tif (!*last) {\n+\t\t*first = new;\n+\t\t*last = new;\n+\t} else {\n+\t\t(*last)->next = new;\n+\t\tnew->previous = *last;\n+\t\t*last = new;\n+\t}\n+}\n+\n+static struct trailer_item *process_command_line_args(struct string_list *trailers)\n+{\n+\tstruct trailer_item *arg_tok_first = NULL;\n+\tstruct trailer_item *arg_tok_last = NULL;\n+\tstruct string_list_item *tr;\n+\n+\tfor_each_string_list_item(tr, trailers) {\n+\t\tstruct trailer_item *new = create_trailer_item(tr->string);\n+\t\tadd_trailer_item(&arg_tok_first, &arg_tok_last, new);\n+\t}\n+\n+\treturn arg_tok_first;\n+}\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242651","messageId":"20140525053223.5329.17922.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 05/11] trailer: parse trailers from file or stdin","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:16Z","receivedAt":"2014-05-25T05:32:16Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Read trailers from a file or from stdin, parse the trailers and then\nput the result into a doubly linked list.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n trailer.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 123 insertions(+)\n\ndiff --git a/trailer.c b/trailer.c\nindex f79a369..40ad1a1 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -51,6 +51,14 @@ static size_t alnum_len(const char *buf, size_t len)\n \treturn len;\n }\n \n+static inline int contains_only_spaces(const char *str)\n+{\n+\tconst char *s = str;\n+\twhile (*s && isspace(*s))\n+\t\ts++;\n+\treturn !*s;\n+}\n+\n static void free_trailer_item(struct trailer_item *item)\n {\n \tfree(item->conf.name);\n@@ -509,3 +517,118 @@ static struct trailer_item *process_command_line_args(struct string_list *traile\n \n \treturn arg_tok_first;\n }\n+\n+static struct strbuf **read_input_file(const char *file)\n+{\n+\tstruct strbuf **lines;\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tif (file) {\n+\t\tif (strbuf_read_file(&sb, file, 0) < 0)\n+\t\t\tdie_errno(_(\"could not read input file '%s'\"), file);\n+\t} else {\n+\t\tif (strbuf_read(&sb, fileno(stdin), 0) < 0)\n+\t\t\tdie_errno(_(\"could not read from stdin\"));\n+\t}\n+\n+\tlines = strbuf_split(&sb, '\\n');\n+\n+\tstrbuf_release(&sb);\n+\n+\treturn lines;\n+}\n+\n+/*\n+ * Return the (0 based) index of the start of the patch or the line\n+ * count if there is no patch in the message.\n+ */\n+static int find_patch_start(struct strbuf **lines, int count)\n+{\n+\tint i;\n+\n+\t/* Get the start of the patch part if any */\n+\tfor (i = 0; i < count; i++) {\n+\t\tif (starts_with(lines[i]->buf, \"---\"))\n+\t\t\treturn i;\n+\t}\n+\n+\treturn count;\n+}\n+\n+/*\n+ * Return the (0 based) index of the first trailer line or count if\n+ * there are no trailers. Trailers are searched only in the lines from\n+ * index (count - 1) down to index 0.\n+ */\n+static int find_trailer_start(struct strbuf **lines, int count)\n+{\n+\tint start, only_spaces = 1;\n+\n+\t/*\n+\t * Get the start of the trailers by looking starting from the end\n+\t * for a line with only spaces before lines with one ':'.\n+\t */\n+\tfor (start = count - 1; start >= 0; start--) {\n+\t\tif (lines[start]->buf[0] == comment_line_char)\n+\t\t\tcontinue;\n+\t\tif (contains_only_spaces(lines[start]->buf)) {\n+\t\t\tif (only_spaces)\n+\t\t\t\tcontinue;\n+\t\t\treturn start + 1;\n+\t\t}\n+\t\tif (strchr(lines[start]->buf, ':')) {\n+\t\t\tif (only_spaces)\n+\t\t\t\tonly_spaces = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\t\treturn count;\n+\t}\n+\n+\treturn only_spaces ? count : 0;\n+}\n+\n+static int has_blank_line_before(struct strbuf **lines, int start)\n+{\n+\tfor (;start >= 0; start--) {\n+\t\tif (lines[start]->buf[0] == comment_line_char)\n+\t\t\tcontinue;\n+\t\treturn contains_only_spaces(lines[start]->buf);\n+\t}\n+\treturn 0;\n+}\n+\n+static void print_lines(struct strbuf **lines, int start, int end)\n+{\n+\tint i;\n+\tfor (i = start; lines[i] && i < end; i++)\n+\t\tprintf(\"%s\", lines[i]->buf);\n+}\n+\n+static int process_input_file(struct strbuf **lines,\n+\t\t\t      struct trailer_item **in_tok_first,\n+\t\t\t      struct trailer_item **in_tok_last)\n+{\n+\tint count = 0;\n+\tint patch_start, trailer_start, i;\n+\n+\t/* Get the line count */\n+\twhile (lines[count])\n+\t\tcount++;\n+\n+\tpatch_start = find_patch_start(lines, count);\n+\ttrailer_start = find_trailer_start(lines, patch_start);\n+\n+\t/* Print lines before the trailers as is */\n+\tprint_lines(lines, 0, trailer_start);\n+\n+\tif (!has_blank_line_before(lines, trailer_start - 1))\n+\t\tprintf(\"\\n\");\n+\n+\t/* Parse trailer lines */\n+\tfor (i = trailer_start; i < patch_start; i++) {\n+\t\tstruct trailer_item *new = create_trailer_item(lines[i]->buf);\n+\t\tadd_trailer_item(in_tok_first, in_tok_last, new);\n+\t}\n+\n+\treturn patch_start;\n+}\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242652","messageId":"20140525053223.5329.76257.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 06/11] trailer: put all the processing together and print","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:17Z","receivedAt":"2014-05-25T05:32:17Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This patch adds the process_trailers() function that\ncalls all the previously added processing functions\nand then prints the results on the standard output.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n trailer.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n trailer.h |  6 ++++++\n 2 files changed, 62 insertions(+)\n create mode 100644 trailer.h\n\ndiff --git a/trailer.c b/trailer.c\nindex 40ad1a1..d648939 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"string-list.h\"\n+#include \"trailer.h\"\n /*\n  * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>\n  */\n@@ -69,6 +70,24 @@ static void free_trailer_item(struct trailer_item *item)\n \tfree(item);\n }\n \n+static void print_tok_val(const char *tok, const char *val)\n+{\n+\tchar c = tok[strlen(tok) - 1];\n+\tif (isalnum(c))\n+\t\tprintf(\"%s: %s\\n\", tok, val);\n+\telse\n+\t\tprintf(\"%s%s\\n\", tok, val);\n+}\n+\n+static void print_all(struct trailer_item *first, int trim_empty)\n+{\n+\tstruct trailer_item *item;\n+\tfor (item = first; item; item = item->next) {\n+\t\tif (!trim_empty || strlen(item->value) > 0)\n+\t\t\tprint_tok_val(item->token, item->value);\n+\t}\n+}\n+\n static void add_arg_to_input_list(struct trailer_item *in_tok,\n \t\t\t\t  struct trailer_item *arg_tok)\n {\n@@ -632,3 +651,40 @@ static int process_input_file(struct strbuf **lines,\n \n \treturn patch_start;\n }\n+\n+static void free_all(struct trailer_item **first)\n+{\n+\twhile (*first) {\n+\t\tstruct trailer_item *item = remove_first(first);\n+\t\tfree_trailer_item(item);\n+\t}\n+}\n+\n+void process_trailers(const char *file, int trim_empty, struct string_list *trailers)\n+{\n+\tstruct trailer_item *in_tok_first = NULL;\n+\tstruct trailer_item *in_tok_last = NULL;\n+\tstruct trailer_item *arg_tok_first;\n+\tstruct strbuf **lines;\n+\tint patch_start;\n+\n+\tgit_config(git_trailer_config, NULL);\n+\n+\tlines = read_input_file(file);\n+\n+\t/* Print the lines before the trailers */\n+\tpatch_start = process_input_file(lines, &in_tok_first, &in_tok_last);\n+\n+\targ_tok_first = process_command_line_args(trailers);\n+\n+\tprocess_trailers_lists(&in_tok_first, &in_tok_last, &arg_tok_first);\n+\n+\tprint_all(in_tok_first, trim_empty);\n+\n+\tfree_all(&in_tok_first);\n+\n+\t/* Print the lines after the trailers as is */\n+\tprint_lines(lines, patch_start, INT_MAX);\n+\n+\tstrbuf_list_free(lines);\n+}\ndiff --git a/trailer.h b/trailer.h\nnew file mode 100644\nindex 0000000..8eb25d5\n--- /dev/null\n+++ b/trailer.h\n@@ -0,0 +1,6 @@\n+#ifndef TRAILER_H\n+#define TRAILER_H\n+\n+void process_trailers(const char *file, int trim_empty, struct string_list *trailers);\n+\n+#endif /* TRAILER_H */\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242654","messageId":"20140525053223.5329.1794.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 07/11] trailer: add interpret-trailers command","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:18Z","receivedAt":"2014-05-25T05:32:18Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This patch adds the \"git interpret-trailers\" command.\nThis command uses the previously added process_trailers()\nfunction in trailer.c.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n .gitignore                   |  1 +\n Makefile                     |  1 +\n builtin.h                    |  1 +\n builtin/interpret-trailers.c | 44 ++++++++++++++++++++++++++++++++++++++++++++\n git.c                        |  1 +\n 5 files changed, 48 insertions(+)\n create mode 100644 builtin/interpret-trailers.c\n\ndiff --git a/.gitignore b/.gitignore\nindex b5f9def..c870ada 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -74,6 +74,7 @@\n /git-index-pack\n /git-init\n /git-init-db\n+/git-interpret-trailers\n /git-instaweb\n /git-log\n /git-ls-files\ndiff --git a/Makefile b/Makefile\nindex ec90feb..a91465e 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -935,6 +935,7 @@ BUILTIN_OBJS += builtin/hash-object.o\n BUILTIN_OBJS += builtin/help.o\n BUILTIN_OBJS += builtin/index-pack.o\n BUILTIN_OBJS += builtin/init-db.o\n+BUILTIN_OBJS += builtin/interpret-trailers.o\n BUILTIN_OBJS += builtin/log.o\n BUILTIN_OBJS += builtin/ls-files.o\n BUILTIN_OBJS += builtin/ls-remote.o\ndiff --git a/builtin.h b/builtin.h\nindex c47c110..8ca0065 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -73,6 +73,7 @@ extern int cmd_hash_object(int argc, const char **argv, const char *prefix);\n extern int cmd_help(int argc, const char **argv, const char *prefix);\n extern int cmd_index_pack(int argc, const char **argv, const char *prefix);\n extern int cmd_init_db(int argc, const char **argv, const char *prefix);\n+extern int cmd_interpret_trailers(int argc, const char **argv, const char *prefix);\n extern int cmd_log(int argc, const char **argv, const char *prefix);\n extern int cmd_log_reflog(int argc, const char **argv, const char *prefix);\n extern int cmd_ls_files(int argc, const char **argv, const char *prefix);\ndiff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c\nnew file mode 100644\nindex 0000000..46838d2\n--- /dev/null\n+++ b/builtin/interpret-trailers.c\n@@ -0,0 +1,44 @@\n+/*\n+ * Builtin \"git interpret-trailers\"\n+ *\n+ * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>\n+ *\n+ */\n+\n+#include \"cache.h\"\n+#include \"builtin.h\"\n+#include \"parse-options.h\"\n+#include \"string-list.h\"\n+#include \"trailer.h\"\n+\n+static const char * const git_interpret_trailers_usage[] = {\n+\tN_(\"git interpret-trailers [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]\"),\n+\tNULL\n+};\n+\n+int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)\n+{\n+\tint trim_empty = 0;\n+\tstruct string_list trailers = STRING_LIST_INIT_DUP;\n+\n+\tstruct option options[] = {\n+\t\tOPT_BOOL(0, \"trim-empty\", &trim_empty, N_(\"trim empty trailers\")),\n+\t\tOPT_STRING_LIST(0, \"trailer\", &trailers, N_(\"trailer\"),\n+\t\t\t\tN_(\"trailer(s) to add\")),\n+\t\tOPT_END()\n+\t};\n+\n+\targc = parse_options(argc, argv, prefix, options,\n+\t\t\t     git_interpret_trailers_usage, 0);\n+\n+\tif (argc) {\n+\t\tint i;\n+\t\tfor (i = 0; i < argc; i++)\n+\t\t\tprocess_trailers(argv[i], trim_empty, &trailers);\n+\t} else\n+\t\tprocess_trailers(NULL, trim_empty, &trailers);\n+\n+\tstring_list_clear(&trailers, 0);\n+\n+\treturn 0;\n+}\ndiff --git a/git.c b/git.c\nindex 7cf2953..63a03eb 100644\n--- a/git.c\n+++ b/git.c\n@@ -380,6 +380,7 @@ static struct cmd_struct commands[] = {\n \t{ \"index-pack\", cmd_index_pack, RUN_SETUP_GENTLY },\n \t{ \"init\", cmd_init_db },\n \t{ \"init-db\", cmd_init_db },\n+\t{ \"interpret-trailers\", cmd_interpret_trailers, RUN_SETUP },\n \t{ \"log\", cmd_log, RUN_SETUP },\n \t{ \"ls-files\", cmd_ls_files, RUN_SETUP },\n \t{ \"ls-remote\", cmd_ls_remote, RUN_SETUP_GENTLY },\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242646","messageId":"20140525053223.5329.36492.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 08/11] trailer: add tests for \"git interpret-trailers\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:19Z","receivedAt":"2014-05-25T05:32:19Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t7513-interpret-trailers.sh | 444 ++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 444 insertions(+)\n create mode 100755 t/t7513-interpret-trailers.sh\n\ndiff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh\nnew file mode 100755\nindex 0000000..9911c7b\n--- /dev/null\n+++ b/t/t7513-interpret-trailers.sh\n@@ -0,0 +1,444 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2013, 2014 Christian Couder\n+#\n+\n+test_description='git interpret-trailers'\n+\n+. ./test-lib.sh\n+\n+# When we want one trailing space at the end of each line, let's use sed\n+# to make sure that these spaces are not removed by any automatic tool.\n+\n+test_expect_success 'setup' '\n+\tcat >basic_message <<-\\EOF &&\n+\t\tsubject\n+\n+\t\tbody\n+\tEOF\n+\tcat >complex_message_body <<-\\EOF &&\n+\t\tmy subject\n+\n+\t\tmy body which is long\n+\t\tand contains some special\n+\t\tchars like : = ? !\n+\n+\tEOF\n+\tsed -e \"s/ Z\\$/ /\" >complex_message_trailers <<-\\EOF &&\n+\t\tFixes: Z\n+\t\tAcked-by: Z\n+\t\tReviewed-by: Z\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tcat >basic_patch <<-\\EOF\n+\t\t---\n+\t\t foo.txt | 2 +-\n+\t\t 1 file changed, 1 insertion(+), 1 deletion(-)\n+\n+\t\tdiff --git a/foo.txt b/foo.txt\n+\t\tindex 0353767..1d91aa1 100644\n+\t\t--- a/foo.txt\n+\t\t+++ b/foo.txt\n+\t\t@@ -1,3 +1,3 @@\n+\n+\t\t-bar\n+\t\t+baz\n+\n+\t\t--\n+\t\t1.9.rc0.11.ga562ddc\n+\n+\tEOF\n+'\n+\n+test_expect_success 'without config' '\n+\tsed -e \"s/ Z\\$/ /\" >expected <<-\\EOF &&\n+\n+\t\tack: Peff\n+\t\tReviewed-by: Z\n+\t\tAcked-by: Johan\n+\tEOF\n+\tgit interpret-trailers --trailer \"ack = Peff\" --trailer \"Reviewed-by\" \\\n+\t\t--trailer \"Acked-by: Johan\" >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success '--trim-empty without config' '\n+\tcat >expected <<-\\EOF &&\n+\n+\t\tack: Peff\n+\t\tAcked-by: Johan\n+\tEOF\n+\tgit interpret-trailers --trim-empty --trailer \"ack = Peff\" \\\n+\t\t--trailer \"Reviewed-by\" --trailer \"Acked-by: Johan\" \\\n+\t\t--trailer \"sob:\" >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with config setup' '\n+\tgit config trailer.ack.key \"Acked-by: \" &&\n+\tcat >expected <<-\\EOF &&\n+\n+\t\tAcked-by: Peff\n+\tEOF\n+\tgit interpret-trailers --trim-empty --trailer \"ack = Peff\" >actual &&\n+\ttest_cmp expected actual &&\n+\tgit interpret-trailers --trim-empty --trailer \"Acked-by = Peff\" >actual &&\n+\ttest_cmp expected actual &&\n+\tgit interpret-trailers --trim-empty --trailer \"Acked-by :Peff\" >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with config setup and = sign' '\n+\tgit config trailer.ack.key \"Acked-by= \" &&\n+\tcat >expected <<-\\EOF &&\n+\n+\t\tAcked-by= Peff\n+\tEOF\n+\tgit interpret-trailers --trim-empty --trailer \"ack = Peff\" >actual &&\n+\ttest_cmp expected actual &&\n+\tgit interpret-trailers --trim-empty --trailer \"Acked-by= Peff\" >actual &&\n+\ttest_cmp expected actual &&\n+\tgit interpret-trailers --trim-empty --trailer \"Acked-by : Peff\" >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with config setup and # sign' '\n+\tgit config trailer.bug.key \"Bug #\" &&\n+\tcat >expected <<-\\EOF &&\n+\n+\t\tBug #42\n+\tEOF\n+\tgit interpret-trailers --trim-empty --trailer \"bug = 42\" >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with commit basic message' '\n+\tcat basic_message >expected &&\n+\techo >>expected &&\n+\tgit interpret-trailers <basic_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with basic patch' '\n+\tcat basic_message >input &&\n+\tcat basic_patch >>input &&\n+\tcat basic_message >expected &&\n+\techo >>expected &&\n+\tcat basic_patch >>expected &&\n+\tgit interpret-trailers <input >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with commit complex message as argument' '\n+\tcat complex_message_body complex_message_trailers >complex_message &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tReviewed-by: Z\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with 2 files arguments' '\n+\tcat basic_message >>expected &&\n+\techo >>expected &&\n+\tcat basic_patch >>expected &&\n+\tgit interpret-trailers complex_message input >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with message that has comments' '\n+\tcat basic_message >>message_with_comments &&\n+\tsed -e \"s/ Z\\$/ /\" >>message_with_comments <<-\\EOF &&\n+\t\t# comment\n+\n+\t\t# other comment\n+\t\tCc: Z\n+\t\t# yet another comment\n+\t\tReviewed-by: Johan\n+\t\tReviewed-by: Z\n+\t\t# last comment\n+\n+\tEOF\n+\tcat basic_patch >>message_with_comments &&\n+\tcat basic_message >expected &&\n+\tcat >>expected <<-\\EOF &&\n+\t\t# comment\n+\n+\t\tCc: Peff\n+\t\tReviewed-by: Johan\n+\tEOF\n+\tcat basic_patch >>expected &&\n+\tgit interpret-trailers --trim-empty --trailer \"Cc: Peff\" message_with_comments >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with commit complex message and trailer args' '\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Peff\n+\t\tReviewed-by: Z\n+\t\tSigned-off-by: Z\n+\t\tBug #42\n+\tEOF\n+\tgit interpret-trailers --trailer \"ack: Peff\" \\\n+\t\t--trailer \"bug: 42\" <complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with complex patch, args and --trim-empty' '\n+\tcat complex_message >complex_patch &&\n+\tcat basic_patch >>complex_patch &&\n+\tcat complex_message_body >expected &&\n+\tcat >>expected <<-\\EOF &&\n+\t\tAcked-by= Peff\n+\t\tBug #42\n+\tEOF\n+\tcat basic_patch >>expected &&\n+\tgit interpret-trailers --trim-empty --trailer \"ack: Peff\" \\\n+\t\t--trailer \"bug: 42\" <complex_patch >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"where = before\"' '\n+\tgit config trailer.bug.where \"before\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Peff\n+\t\tReviewed-by: Z\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"ack: Peff\" \\\n+\t\t--trailer \"bug: 42\" complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"where = before\" for a token in the middle of the message' '\n+\tgit config trailer.review.key \"Reviewed-by:\" &&\n+\tgit config trailer.review.where \"before\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:Johan\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"ack: Peff\" --trailer \"bug: 42\" \\\n+\t\t--trailer \"review: Johan\" <complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"where = before\" and --trim-empty' '\n+\tcat complex_message_body >expected &&\n+\tcat >>expected <<-\\EOF &&\n+\t\tBug #46\n+\t\tBug #42\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:Johan\n+\tEOF\n+\tgit interpret-trailers --trim-empty --trailer \"ack: Peff\" \\\n+\t\t--trailer \"bug: 42\" --trailer \"review: Johan\" \\\n+\t\t--trailer \"Bug: 46\" <complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'the default is \"ifExists = addIfDifferent\"' '\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"ack: Peff\" --trailer \"review:\" \\\n+\t\t--trailer \"bug: 42\" --trailer \"ack: Peff\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"ifExists = addIfDifferent\"' '\n+\tgit config trailer.review.ifExists \"addIfDifferent\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"ack: Peff\" --trailer \"review:\" \\\n+\t\t--trailer \"bug: 42\" --trailer \"ack: Peff\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"ifExists = addIfDifferentNeighbor\"' '\n+\tgit config trailer.ack.ifExists \"addIfDifferentNeighbor\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Peff\n+\t\tAcked-by= Junio\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"ack: Peff\" --trailer \"review:\" \\\n+\t\t--trailer \"ack: Junio\" --trailer \"bug: 42\" \\\n+\t\t--trailer \"ack: Peff\" <complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"ifExists = addIfDifferentNeighbor\" and --trim-empty' '\n+\tgit config trailer.ack.ifExists \"addIfDifferentNeighbor\" &&\n+\tcat complex_message_body >expected &&\n+\tcat >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tAcked-by= Peff\n+\t\tAcked-by= Junio\n+\t\tAcked-by= Peff\n+\tEOF\n+\tgit interpret-trailers --trim-empty --trailer \"ack: Peff\" \\\n+\t\t--trailer \"Acked-by= Peff\" --trailer \"review:\" \\\n+\t\t--trailer \"ack: Junio\" --trailer \"bug: 42\" \\\n+\t\t--trailer \"ack: Peff\" <complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"ifExists = add\"' '\n+\tgit config trailer.ack.ifExists \"add\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Peff\n+\t\tAcked-by= Peff\n+\t\tAcked-by= Junio\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"ack: Peff\" \\\n+\t\t--trailer \"Acked-by= Peff\" --trailer \"review:\" \\\n+\t\t--trailer \"ack: Junio\" --trailer \"bug: 42\" \\\n+\t\t--trailer \"ack: Peff\" <complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"ifExists = overwrite\"' '\n+\tgit config trailer.fix.key \"Fixes: \" &&\n+\tgit config trailer.fix.ifExists \"overwrite\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: 22\n+\t\tAcked-by= Z\n+\t\tAcked-by= Junio\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" \\\n+\t\t--trailer \"fix=53\" --trailer \"ack: Junio\" --trailer \"fix=22\" \\\n+\t\t--trailer \"bug: 42\" --trailer \"ack: Peff\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"ifExists = doNothing\"' '\n+\tgit config trailer.fix.ifExists \"doNothing\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Junio\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=53\" \\\n+\t\t--trailer \"ack: Junio\" --trailer \"fix=22\" \\\n+\t\t--trailer \"bug: 42\" --trailer \"ack: Peff\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'the default is \"ifMissing = add\"' '\n+\tgit config trailer.cc.key \"Cc: \" &&\n+\tgit config trailer.cc.where \"before\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tCc: Linus\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Junio\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=53\" \\\n+\t\t--trailer \"cc=Linus\" --trailer \"ack: Junio\" \\\n+\t\t--trailer \"fix=22\" --trailer \"bug: 42\" --trailer \"ack: Peff\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"ifMissing = add\"' '\n+\tgit config trailer.cc.ifMissing \"add\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tCc: Linus\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Junio\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=53\" \\\n+\t\t--trailer \"ack: Junio\" --trailer \"fix=22\" \\\n+\t\t--trailer \"bug: 42\" --trailer \"cc=Linus\" --trailer \"ack: Peff\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'using \"ifMissing = doNothing\"' '\n+\tgit config trailer.cc.ifMissing \"doNothing\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tBug #42\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tAcked-by= Junio\n+\t\tAcked-by= Peff\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=53\" \\\n+\t\t--trailer \"cc=Linus\" --trailer \"ack: Junio\" \\\n+\t\t--trailer \"fix=22\" --trailer \"bug: 42\" --trailer \"ack: Peff\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_done\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242655","messageId":"20140525053223.5329.74452.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 09/11] trailer: execute command from 'trailer.<name>.command'","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:20Z","receivedAt":"2014-05-25T05:32:20Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Let the user specify a command that will give on its standard output\nthe value to use for the specified trailer.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n trailer.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 65 insertions(+)\n\ndiff --git a/trailer.c b/trailer.c\nindex d648939..eaf692b 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -1,5 +1,7 @@\n #include \"cache.h\"\n #include \"string-list.h\"\n+#include \"run-command.h\"\n+#include \"string-list.h\"\n #include \"trailer.h\"\n /*\n  * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>\n@@ -14,11 +16,14 @@ struct conf_info {\n \tchar *name;\n \tchar *key;\n \tchar *command;\n+\tunsigned command_uses_arg : 1;\n \tenum action_where where;\n \tenum action_if_exists if_exists;\n \tenum action_if_missing if_missing;\n };\n \n+#define TRAILER_ARG_STRING \"$ARG\"\n+\n struct trailer_item {\n \tstruct trailer_item *previous;\n \tstruct trailer_item *next;\n@@ -60,6 +65,13 @@ static inline int contains_only_spaces(const char *str)\n \treturn !*s;\n }\n \n+static inline void strbuf_replace(struct strbuf *sb, const char *a, const char *b)\n+{\n+\tconst char *ptr = strstr(sb->buf, a);\n+\tif (ptr)\n+\t\tstrbuf_splice(sb, ptr - sb->buf, strlen(a), b, strlen(b));\n+}\n+\n static void free_trailer_item(struct trailer_item *item)\n {\n \tfree(item->conf.name);\n@@ -401,6 +413,7 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)\n \t\tif (conf->command)\n \t\t\twarning(_(\"more than one %s\"), conf_key);\n \t\tconf->command = xstrdup(value);\n+\t\tconf->command_uses_arg = !!strstr(conf->command, TRAILER_ARG_STRING);\n \t\tbreak;\n \tcase TRAILER_WHERE:\n \t\tif (set_where(conf, value))\n@@ -437,6 +450,45 @@ static int parse_trailer(struct strbuf *tok, struct strbuf *val, const char *tra\n \treturn 0;\n }\n \n+static int read_from_command(struct child_process *cp, struct strbuf *buf)\n+{\n+\tif (run_command(cp))\n+\t\treturn error(\"running trailer command '%s' failed\", cp->argv[0]);\n+\tif (strbuf_read(buf, cp->out, 1024) < 1)\n+\t\treturn error(\"reading from trailer command '%s' failed\", cp->argv[0]);\n+\tstrbuf_trim(buf);\n+\treturn 0;\n+}\n+\n+static const char *apply_command(const char *command, const char *arg)\n+{\n+\tstruct strbuf cmd = STRBUF_INIT;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct child_process cp;\n+\tconst char *argv[] = {NULL, NULL};\n+\tconst char *result;\n+\n+\tstrbuf_addstr(&cmd, command);\n+\tif (arg)\n+\t\tstrbuf_replace(&cmd, TRAILER_ARG_STRING, arg);\n+\n+\targv[0] = cmd.buf;\n+\tmemset(&cp, 0, sizeof(cp));\n+\tcp.argv = argv;\n+\tcp.env = local_repo_env;\n+\tcp.no_stdin = 1;\n+\tcp.out = -1;\n+\tcp.use_shell = 1;\n+\n+\tif (read_from_command(&cp, &buf)) {\n+\t\tstrbuf_release(&buf);\n+\t\tresult = xstrdup(\"\");\n+\t} else\n+\t\tresult = strbuf_detach(&buf, NULL);\n+\n+\tstrbuf_release(&cmd);\n+\treturn result;\n+}\n \n static void duplicate_conf(struct conf_info *dst, struct conf_info *src)\n {\n@@ -467,6 +519,10 @@ static struct trailer_item *new_trailer_item(struct trailer_item *conf_item,\n \t\tduplicate_conf(&new->conf, &conf_item->conf);\n \t\tnew->token = xstrdup(token_from_item(conf_item));\n \t\tfree(tok);\n+\t\tif (conf_item->conf.command_uses_arg || !val) {\n+\t\t\tnew->value = apply_command(conf_item->conf.command, val);\n+\t\t\tfree(val);\n+\t\t}\n \t} else\n \t\tnew->token = tok;\n \n@@ -528,12 +584,21 @@ static struct trailer_item *process_command_line_args(struct string_list *traile\n \tstruct trailer_item *arg_tok_first = NULL;\n \tstruct trailer_item *arg_tok_last = NULL;\n \tstruct string_list_item *tr;\n+\tstruct trailer_item *item;\n \n \tfor_each_string_list_item(tr, trailers) {\n \t\tstruct trailer_item *new = create_trailer_item(tr->string);\n \t\tadd_trailer_item(&arg_tok_first, &arg_tok_last, new);\n \t}\n \n+\t/* Add conf commands that don't use $ARG */\n+\tfor (item = first_conf_item; item; item = item->next) {\n+\t\tif (item->conf.command && !item->conf.command_uses_arg) {\n+\t\t\tstruct trailer_item *new = new_trailer_item(item, NULL, NULL);\n+\t\t\tadd_trailer_item(&arg_tok_first, &arg_tok_last, new);\n+\t\t}\n+\t}\n+\n \treturn arg_tok_first;\n }\n \n-- \n1.9.rc0.17.g651113e\n"},{"id":"242648","messageId":"20140525053223.5329.41060.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 10/11] trailer: add tests for commands in config file","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:21Z","receivedAt":"2014-05-25T05:32:21Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"And add a few other tests for some special cases.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t7513-interpret-trailers.sh | 124 ++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 124 insertions(+)\n\ndiff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh\nindex 9911c7b..d1e4970 100755\n--- a/t/t7513-interpret-trailers.sh\n+++ b/t/t7513-interpret-trailers.sh\n@@ -441,4 +441,128 @@ test_expect_success 'using \"ifMissing = doNothing\"' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'with simple command' '\n+\tgit config trailer.sign.key \"Signed-off-by: \" &&\n+\tgit config trailer.sign.where \"after\" &&\n+\tgit config trailer.sign.ifExists \"addIfDifferentNeighbor\" &&\n+\tgit config trailer.sign.command \"echo \\\"A U Thor <author@example.com>\\\"\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\t\tSigned-off-by: A U Thor <author@example.com>\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=22\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with command using commiter information' '\n+\tgit config trailer.sign.ifExists \"addIfDifferent\" &&\n+\tgit config trailer.sign.command \"echo \\\"\\$GIT_COMMITTER_NAME <\\$GIT_COMMITTER_EMAIL>\\\"\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\t\tSigned-off-by: C O Mitter <committer@example.com>\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=22\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with command using author information' '\n+\tgit config trailer.sign.key \"Signed-off-by: \" &&\n+\tgit config trailer.sign.where \"after\" &&\n+\tgit config trailer.sign.ifExists \"addIfDifferentNeighbor\" &&\n+\tgit config trailer.sign.command \"echo \\\"\\$GIT_AUTHOR_NAME <\\$GIT_AUTHOR_EMAIL>\\\"\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\t\tSigned-off-by: A U Thor <author@example.com>\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=22\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'setup a commit' '\n+\techo \"Content of the first commit.\" > a.txt &&\n+\tgit add a.txt &&\n+\tgit commit -m \"Add file a.txt\"\n+'\n+\n+test_expect_success 'with command using $ARG' '\n+\tgit config trailer.fix.ifExists \"overwrite\" &&\n+\tgit config trailer.fix.command \"git log -1 --oneline --format=\\\"%h (%s)\\\" --abbrev-commit --abbrev=14 \\$ARG\" &&\n+\tFIXED=$(git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 HEAD) &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-EOF &&\n+\t\tFixes: $FIXED\n+\t\tAcked-by= Z\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\t\tSigned-off-by: A U Thor <author@example.com>\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=HEAD\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with failing command using $ARG' '\n+\tgit config trailer.fix.ifExists \"overwrite\" &&\n+\tgit config trailer.fix.command \"false \\$ARG\" &&\n+\tcat complex_message_body >expected &&\n+\tsed -e \"s/ Z\\$/ /\" >>expected <<-EOF &&\n+\t\tFixes: Z\n+\t\tAcked-by= Z\n+\t\tReviewed-by:\n+\t\tSigned-off-by: Z\n+\t\tSigned-off-by: A U Thor <author@example.com>\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:\" --trailer \"fix=HEAD\" \\\n+\t\t<complex_message >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with empty tokens' '\n+\tcat >expected <<-EOF &&\n+\n+\t\tSigned-off-by: A U Thor <author@example.com>\n+\tEOF\n+\tgit interpret-trailers --trailer \":\" --trailer \":test\" >actual <<-EOF &&\n+\tEOF\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with command but no key' '\n+\tgit config --unset trailer.sign.key &&\n+\tcat >expected <<-EOF &&\n+\n+\t\tsign: A U Thor <author@example.com>\n+\tEOF\n+\tgit interpret-trailers >actual <<-EOF &&\n+\tEOF\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'with no command and no key' '\n+\tgit config --unset trailer.review.key &&\n+\tcat >expected <<-EOF &&\n+\n+\t\treview: Junio\n+\t\tsign: A U Thor <author@example.com>\n+\tEOF\n+\tgit interpret-trailers --trailer \"review:Junio\" >actual <<-EOF &&\n+\tEOF\n+\ttest_cmp expected actual\n+'\n+\n test_done\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242647","messageId":"20140525053223.5329.28002.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"20140525051254.5329.66539.chriscool@tuxfamily.org","subject":"[PATCH v12 11/11] Documentation: add documentation for 'git interpret-trailers'","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-05-25T05:32:22Z","receivedAt":"2014-05-25T05:32:22Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"While at it add git-interpret-trailers to \"command-list.txt\".\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-interpret-trailers.txt | 264 +++++++++++++++++++++++++++++++\n command-list.txt                         |   1 +\n 2 files changed, 265 insertions(+)\n create mode 100644 Documentation/git-interpret-trailers.txt\n\ndiff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt\nnew file mode 100644\nindex 0000000..45f1ed4\n--- /dev/null\n+++ b/Documentation/git-interpret-trailers.txt\n@@ -0,0 +1,264 @@\n+git-interpret-trailers(1)\n+=========================\n+\n+NAME\n+----\n+git-interpret-trailers - help add stuctured information into commit messages\n+\n+SYNOPSIS\n+--------\n+[verse]\n+'git interpret-trailers' [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]\n+\n+DESCRIPTION\n+-----------\n+Help adding 'trailers' lines, that look similar to RFC 822 e-mail\n+headers, at the end of the otherwise free-form part of a commit\n+message.\n+\n+This command reads some patches or commit messages from either the\n+<file> arguments or the standard input if no <file> is specified. Then\n+this command applies the arguments passed using the `--trailer`\n+option, if any, to the commit message part of each input file. The\n+result is emitted on the standard output.\n+\n+Some configuration variables control the way the `--trailer` arguments\n+are applied to each commit message and the way any existing trailer in\n+the commit message is changed. They also make it possible to\n+automatically add some trailers.\n+\n+By default, a '<token>=<value>' or '<token>:<value>' argument given\n+using `--trailer` will be added only if no trailer with the same\n+(<token>, <value>) pair is already in the message. The <token> and\n+<value> parts will be trimmed to remove starting and trailing\n+whitespace, and the resulting trimmed <token> and <value> will appear\n+in the message like this:\n+\n+------------------------------------------------\n+token: value\n+------------------------------------------------\n+\n+This means that the trimmed <token> and <value> will be separated by\n+`': '` (one colon followed by one space).\n+\n+By default, if there are already trailers with the same <token>, the\n+new trailer will appear just after the last trailer with the same\n+<token>. Otherwise it will appear at the end of the commit message\n+part of the ouput.\n+\n+The trailers are recognized in the input message using the following\n+rules:\n+\n+* only lines that contains a ':' (colon) are considered trailers,\n+\n+* the trailer lines must all be next to each other,\n+\n+* after them it's only possible to have some lines that contain only\n+  spaces, and then a patch; the patch part is recognized using the\n+  fact that its first line starts with '---' (three minus signs),\n+\n+* before them there must be at least one line with only spaces.\n+\n+Note that 'trailers' do not follow and are not intended to follow many\n+rules for RFC 822 headers. For example they do not follow the line\n+folding rules, the encoding rules and probably many other rules.\n+\n+OPTIONS\n+-------\n+--trim-empty::\n+\tIf the <value> part of any trailer contains only whitespace,\n+\tthe whole trailer will be removed from the resulting message.\n+\tThis apply to existing trailers as well as new trailers.\n+\n+--trailer <token>[(=|:)<value>]::\n+\tSpecify a (<token>, <value>) pair that should be applied as a\n+\ttrailer to the input messages. See the description of this\n+\tcommand.\n+\n+CONFIGURATION VARIABLES\n+-----------------------\n+\n+trailer.<token>.key::\n+\tThis `key` will be used instead of <token> in the\n+\ttrailer. After the last alphanumeric character, this variable\n+\tcan contain some non alphanumeric characters, like for example\n+\t`'%'` (one percent sign), `' = '` (one space followed by one\n+\tequal sign and then one space), `' #'` (one space followed by\n+\tone number sign) or even just `' '` (one space), that will be\n+\tused to separate the <token> from the <value> in the\n+\ttrailer. The default separator, `': '` (one colon followed by\n+\tone space), which is the usual standard, is added only if the\n+\tlast character in `key` is alphanumeric, so watch out for\n+\tunwanted trailing spaces in this variable.\n+\n+trailer.<token>.where::\n+\tThis can be either `after`, which is the default, or\n+\t`before`. If it is `before`, then a trailer with the specified\n+\t<token>, will appear before, instead of after, other trailers\n+\twith the same <token>, or otherwise at the beginning, instead\n+\tof at the end, of all the trailers.\n+\n+trailer.<token>.ifexist::\n+\tThis option makes it possible to choose what action will be\n+\tperformed when there is already at least one trailer with the\n+\tsame <token> in the message.\n++\n+The valid values for this option are: `addIfDifferent` (this is the\n+default), `addIfDifferentNeighbor`, `add`, `overwrite` or `doNothing`.\n++\n+With `addIfDifferent`, a new trailer will be added only if no trailer\n+with the same (<token>, <value>) pair is already in the message.\n++\n+With `addIfDifferentNeighbor`, a new trailer will be added only if no\n+trailer with the same (<token>, <value>) pair is above or below the line\n+where the new trailer will be added.\n++\n+With `add`, a new trailer will be added, even if some trailers with\n+the same (<token>, <value>) pair are already in the message.\n++\n+With `overwrite`, the new trailer will overwrite an existing trailer\n+with the same <token>.\n++\n+With `doNothing`, nothing will be done; that is no new trailer will be\n+added if there is already one with the same <token> in the message.\n+\n+trailer.<token>.ifmissing::\n+\tThis option makes it possible to choose what action will be\n+\tperformed when there is not yet any trailer with the same\n+\t<token> in the message.\n++\n+The valid values for this option are: `add` (this is the default) and\n+`doNothing`.\n++\n+With `add`, a new trailer will be added.\n++\n+With `doNothing`, nothing will be done.\n+\n+trailer.<token>.command::\n+\tThis option can be used to specify a shell command that will\n+\tbe used to automatically add or modify a trailer with the\n+\tspecified <token>.\n++\n+When this option is specified, the behavior is as if a special\n+'<token>=<value>' argument were added at the end of the command line,\n+where <value> is taken to be the standard output of the specified\n+command with any leading and trailing whitespace trimmed off.\n++\n+If the command contains the `$ARG` string, this string will be\n+replaced with the <value> part of an existing trailer with the same\n+<token>, if any, before the command is launched.\n+\n+EXAMPLES\n+--------\n+\n+* Configure a 'sign' trailer with a 'Signed-off-by' key, and then\n+  add two of these trailers to a message:\n++\n+------------\n+$ git config trailer.sign.key \"Signed-off-by\"\n+$ cat msg.txt\n+subject\n+\n+message\n+$ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'\n+subject\n+\n+message\n+\n+Signed-off-by: Alice <alice@example.com>\n+Signed-off-by: Bob <bob@example.com>\n+------------\n+\n+* Extract the last commit as a patch, and add a 'Cc' and a\n+  'Reviewed-by' trailer to it:\n++\n+------------\n+$ git format-patch -1\n+0001-foo.patch\n+$ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch\n+------------\n+\n+* Configure a 'sign' trailer with a command to automatically add a\n+  'Signed-off-by: ' with the author information only if there is no\n+  'Signed-off-by: ' already, and show how it works:\n++\n+------------\n+$ git config trailer.sign.key \"Signed-off-by: \"\n+$ git config trailer.sign.ifmissing add\n+$ git config trailer.sign.ifexists doNothing\n+$ git config trailer.sign.command 'echo \"$(git config user.name) <$(git config user.email)>\"'\n+$ git interpret-trailers <<EOF\n+> EOF\n+\n+Signed-off-by: Bob <bob@example.com>\n+$ git interpret-trailers <<EOF\n+> Signed-off-by: Alice <alice@example.com>\n+> EOF\n+\n+Signed-off-by: Alice <alice@example.com>\n+------------\n+\n+* Configure a 'fix' trailer with a key that contains a '#' and no\n+  space after this character, and show how it works:\n++\n+------------\n+$ git config trailer.fix.key \"Fix #\"\n+$ echo \"subject\" | git interpret-trailers --trailer fix=42\n+subject\n+\n+Fix #42\n+------------\n+\n+* Configure a 'see' trailer with a command to show the subject of a\n+  commit that is related, and show how it works:\n++\n+------------\n+$ git config trailer.see.key \"See-also: \"\n+$ git config trailer.see.ifExists \"overwrite\"\n+$ git config trailer.see.command \"git log -1 --oneline --format=\\\"%h (%s)\\\" --abbrev-commit --abbrev=14 \\$ARG\"\n+$ git interpret-trailers <<EOF\n+> subject\n+> \n+> message\n+> \n+> see: HEAD~2\n+> EOF\n+subject\n+\n+message\n+\n+See-also: fe3187489d69c4 (subject of related commit)\n+------------\n+\n+* Configure a commit template with some trailers with empty values,\n+  then configure a commit-msg hook that uses 'git interpret-trailers'\n+  to remove trailers with empty values and to add a 'git-version'\n+  trailer:\n++\n+------------\n+$ cat >commit_template.txt <<EOF\n+> ***subject***\n+> \n+> ***message***\n+> \n+> Fixes: \n+> Cc: \n+> Reviewed-by: \n+> Signed-off-by: \n+> EOF\n+$ git config commit.template commit_template.txt\n+$ cat >.git/hooks/commit-msg <<EOF\n+#!/bin/sh\n+git interpret-trailers --trim-empty --trailer \"git-version: \\$(git describe)\" \"\\$1\" > \"\\$1.new\"\n+mv \"\\$1.new\" \"\\$1\"\n+EOF\n+$ chmod +x .git/hooks/commit-msg\n+------------\n+\n+SEE ALSO\n+--------\n+linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/command-list.txt b/command-list.txt\nindex cf36c3d..d5e0bed 100644\n--- a/command-list.txt\n+++ b/command-list.txt\n@@ -62,6 +62,7 @@ git-imap-send                           foreignscminterface\n git-index-pack                          plumbingmanipulators\n git-init                                mainporcelain common\n git-instaweb                            ancillaryinterrogators\n+git-interpret-trailers                  purehelpers\n gitk                                    mainporcelain\n git-log                                 mainporcelain common\n git-ls-files                            plumbinginterrogators\n-- \n1.9.rc0.17.g651113e\n"},{"id":"242893","messageId":"xmqqioopd7oe.fsf@gitster.dls.corp.google.com","threadId":"36749","inReplyTo":"20140525053223.5329.36492.chriscool@tuxfamily.org","subject":"Re: [PATCH v12 08/11] trailer: add tests for \"git interpret-trailers\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-28T19:28:33Z","receivedAt":"2014-05-28T19:28:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> +test_expect_success 'using \"where = before\" for a token in the middle of the message' '\n> +\tgit config trailer.review.key \"Reviewed-by:\" &&\n\nDon't you want to adjust this to have trailing SP, just like you\nadjusted other ones like \"Fixes: \" in this round?\n"},{"id":"242895","messageId":"xmqqegzdd7cm.fsf@gitster.dls.corp.google.com","threadId":"36749","inReplyTo":"20140525053223.5329.28002.chriscool@tuxfamily.org","subject":"Re: [PATCH v12 11/11] Documentation: add documentation for 'git interpret-trailers'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-28T19:35:37Z","receivedAt":"2014-05-28T19:35:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> +The trailers are recognized in the input message using the following\n> +rules:\n> +\n> +* only lines that contains a ':' (colon) are considered trailers,\n> +\n> +* the trailer lines must all be next to each other,\n> +\n> +* after them it's only possible to have some lines that contain only\n> +  spaces, and then a patch; the patch part is recognized using the\n> +  fact that its first line starts with '---' (three minus signs),\n> +\n> +* before them there must be at least one line with only spaces.\n\nWhile I agree with Michael on the other thread that we should limit\nthe syntax and start with ':' only, if you really want to allow\nrandom syntax like \"Bug #12345\" and \"Acked-by= Peff\", for which you\nhave demonstrations in the tests in the other patch, the above rule\nshould be updated to also allow prefix matches to possible set of\nkeys defined by the user, so that an existing line that is produced\nby your tool, e.g. \"Acked-by= Peff\", can be picked up as matching\nwith some token having a key \"Acked-by= \".  Otherwise, the input\nside of your tool is inconsistent with the output side of your own\ntool, and that will make the flexiblity of the output side useless.\n"},{"id":"242896","messageId":"xmqqa9a1d6xn.fsf@gitster.dls.corp.google.com","threadId":"36749","inReplyTo":"20140525053223.5329.28002.chriscool@tuxfamily.org","subject":"Re: [PATCH v12 11/11] Documentation: add documentation for 'git interpret-trailers'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-28T19:44:36Z","receivedAt":"2014-05-28T19:44:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> +trailer.<token>.key::\n> +\tThis `key` will be used instead of <token> in the\n> +\ttrailer. After the last alphanumeric character, this variable\n> +\tcan contain some non alphanumeric characters, like for example\n> +\t`'%'` (one percent sign), `' = '` (one space followed by one\n> +\tequal sign and then one space), `' #'` (one space followed by\n> +\tone number sign) or even just `' '` (one space), that will be\n> +\tused to separate the <token> from the <value> in the\n> +\ttrailer. The default separator, `': '` (one colon followed by\n> +\tone space), which is the usual standard, is added only if the\n> +\tlast character in `key` is alphanumeric, so watch out for\n> +\tunwanted trailing spaces in this variable.\n\nPerhaps corollary to the other review comment to this patch, I think\nthis is overly complex without giving more value to the users than\nit causes confusion.\n\nIf the goal is to allow random syntax on the output side, why do you\neven need to list percent, pound, etc., when you can just say \"The\nkey is emitted and then your value\" and the user will get exactly\nwhat they specified to be emitted?\n\nAny magic applied on top (namely, we would add \": \" only in certain\ncircumstances) only makes things unnecessarily complex; I think your\nhaving to say \"so watch out for...\" is a clear indication of that.\n\nIf we use the \"separator\", so that we can recognise a line with an\nunseen key as a trailer we do not know about, we should stick to\njust a single standard one ':' and I think it is OK to add a missing\n\": \" by magic if that is the direction we are going to take, though.\n"},{"id":"245153","messageId":"20140629.113731.1129545703421115235.chriscool@tuxfamily.org","threadId":"36749","inReplyTo":"xmqqegzdd7cm.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v12 11/11] Documentation: add documentation for 'git interpret-trailers'","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2014-06-29T09:37:31Z","receivedAt":"2014-06-29T09:37:31Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\n> Christian Couder <chriscool@tuxfamily.org> writes:\n> \n>> +The trailers are recognized in the input message using the following\n>> +rules:\n>> +\n>> +* only lines that contains a ':' (colon) are considered trailers,\n>> +\n>> +* the trailer lines must all be next to each other,\n>> +\n>> +* after them it's only possible to have some lines that contain only\n>> +  spaces, and then a patch; the patch part is recognized using the\n>> +  fact that its first line starts with '---' (three minus signs),\n>> +\n>> +* before them there must be at least one line with only spaces.\n> \n> While I agree with Michael on the other thread that we should limit\n> the syntax and start with ':' only, if you really want to allow\n> random syntax like \"Bug #12345\" and \"Acked-by= Peff\", for which you\n> have demonstrations in the tests in the other patch, the above rule\n> should be updated to also allow prefix matches to possible set of\n> keys defined by the user, so that an existing line that is produced\n> by your tool, e.g. \"Acked-by= Peff\", can be picked up as matching\n> with some token having a key \"Acked-by= \".  Otherwise, the input\n> side of your tool is inconsistent with the output side of your own\n> tool, and that will make the flexiblity of the output side useless.\n\nI don't think that the flexibility of the output side would be\nuseless.\n\nWe already emit stuff like:\n\n(cherry picked from commit f72baf07969242882128aff4c95ec8059e7fd054)\n\nand we don't care about any input side when we do that.\n\nSo being able to emit lot of different stuff is valuable even if we\nare not yet able to parse it.\n\nFor example what if people wanted cherry-pick messages written like:\n\nCherry picked from f72baf0796 (\"do this and that\", 2014-01-01)\n\nwe just cannot let them have the above if we decide that ':' has to\nalways be used as the separator.\n\nWe also emit stuff like \"Merge commit '71260bf'\" or \"Merge tag\n'mystuff'\" or Merge branch 'dev' and we don't let people customize\nthis and we don't care about any input side.\n\nAnd when there is a merge conflict we emit:\n\nConflicts:\n\tfile1\n\tfile2\n...\n\ninstead of:\n\nConflicts: file1\nConflicts: file2\n...        \n\nOf course at least for cherry-pick it would have been nice if since\nthe beginning we would have written something in a canonical trailer\nway like:\n\nCherry-picked-from: f72baf0796\n\nThis way we could now use \"git interpret-trailers\" to both emit the\nabove and to read it. But it is still be better to just be able to\nemit it than to not be able to do anything about it.\n\nBecause if we are able to emit it with \"git interpret-trailers\", then\nwe can let people customize how it is emitted, and this might be\nenough for many people. Also now those who are ok to output it using\nthe canonical way, could now configure that.\n\nAnd this is not just for us, something like:\n\nfixes #42 (\"do this and that\", 2014-01-01)\n\nfor example could be nice for both Github and human beings.\n\nThanks,\nChristian.\n"},{"id":"245172","messageId":"xmqqmwcuzyqx.fsf@gitster.dls.corp.google.com","threadId":"36749","inReplyTo":"20140629.113731.1129545703421115235.chriscool@tuxfamily.org","subject":"Re: [PATCH v12 11/11] Documentation: add documentation for 'git interpret-trailers'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-06-30T06:40:22Z","receivedAt":"2014-06-30T06:40:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n>> While I agree with Michael on the other thread that we should limit\n>> the syntax and start with ':' only, if you really want to allow\n>> random syntax like \"Bug #12345\" and \"Acked-by= Peff\", for which you\n>> have demonstrations in the tests in the other patch, the above rule\n>> should be updated to also allow prefix matches to possible set of\n>> keys defined by the user, so that an existing line that is produced\n>> by your tool, e.g. \"Acked-by= Peff\", can be picked up as matching\n>> with some token having a key \"Acked-by= \".  Otherwise, the input\n>> side of your tool is inconsistent with the output side of your own\n>> tool, and that will make the flexiblity of the output side useless.\n>\n> I don't think that the flexibility of the output side would be\n> useless.\n\nFlexibility is useful, only if you can control it.\n\n> We already emit stuff like:\n>\n> (cherry picked from commit f72baf07969242882128aff4c95ec8059e7fd054)\n>\n> and we don't care about any input side when we do that.\n\nThat is something you may want to _fix_, not take as an excuse to\nmake things worse, no?\n"},{"id":"245179","messageId":"53B150B4.1030303@gmail.com","threadId":"36749","inReplyTo":"20140525053223.5329.28002.chriscool@tuxfamily.org","subject":"Re: [PATCH v12 11/11] Documentation: add documentation for 'git interpret-trailers'","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2014-06-30T11:57:40Z","receivedAt":"2014-06-30T11:57:40Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Christian Couder wrote:\n\n> +------------\n> +\n> +* Configure a 'sign' trailer with a command to automatically add a\n> +  'Signed-off-by: ' with the author information only if there is no\n> +  'Signed-off-by: ' already, and show how it works:\n> ++\n> +------------\n> +$ git config trailer.sign.key \"Signed-off-by: \"\n> +$ git config trailer.sign.ifmissing add\n> +$ git config trailer.sign.ifexists doNothing\n> +$ git config trailer.sign.command 'echo \"$(git config user.name) <$(git config user.email)>\"'\n> +$ git interpret-trailers <<EOF\n> +> EOF\n\nHow to configure git-interpret-trailers command so that it follow\ncurrent rules for DCO:\n* Signed-off-by: is always at bottom; we can have\n   signoff+signoff+ack+signoff\n* Signed-off-by: can repeat itself with the same author;\n   this denotes steps in coming up with current version of the patch.\n* but we shouldn't repeat the same signoff one after another\n\nSo we want to allow this:\n\n   Signed-off-by: A U Thor <author@example.com>\n   Signed-off-by: Joe R. Hacker <joe@hacker.com>\n   Acked-by: D E Veloper <developer@example.com>\n   Signed-off-by: C O Mitter <committer@example.com>\n\nbut prevent this\n\n   Signed-off-by: C O Mitter <committer@example.com>\n   Signed-off-by: C O Mitter <committer@example.com>\n\n\nIIRC\n-- \nJakub Narębski\n"},{"id":"245230","messageId":"CAP8UFD3QhOaepNzDwdxdV5hyjV4L7qvqREULZZYXBiiVbZZ9Ow@mail.gmail.com","threadId":"36749","inReplyTo":"53B150B4.1030303@gmail.com","subject":"Re: [PATCH v12 11/11] Documentation: add documentation for 'git interpret-trailers'","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2014-07-01T13:34:50Z","receivedAt":"2014-07-01T13:34:50Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Mon, Jun 30, 2014 at 1:57 PM, Jakub Narębski <jnareb@gmail.com> wrote:\n> Christian Couder wrote:\n>\n>> +------------\n>> +\n>> +* Configure a 'sign' trailer with a command to automatically add a\n>> +  'Signed-off-by: ' with the author information only if there is no\n>> +  'Signed-off-by: ' already, and show how it works:\n>> ++\n>> +------------\n>> +$ git config trailer.sign.key \"Signed-off-by: \"\n>> +$ git config trailer.sign.ifmissing add\n>> +$ git config trailer.sign.ifexists doNothing\n>> +$ git config trailer.sign.command 'echo \"$(git config user.name) <$(git\n>> config user.email)>\"'\n>> +$ git interpret-trailers <<EOF\n>> +> EOF\n>\n>\n> How to configure git-interpret-trailers command so that it follow\n> current rules for DCO:\n> * Signed-off-by: is always at bottom; we can have\n>   signoff+signoff+ack+signoff\n> * Signed-off-by: can repeat itself with the same author;\n>   this denotes steps in coming up with current version of the patch.\n> * but we shouldn't repeat the same signoff one after another\n\nRight now something like: signoff+signoff+ack+signoff is not supported.\n\nIt could be, if someone implements more options for the\n\"trailer.<token>.where\" config variable. Right now the only options\nare \"after\" and \"before\", but it could be possible to have \"end\" and\n\"start\" too. And maybe \"end\" should be the default instead of \"after\".\n\nWhen I first worked on this series I was under the impression that\npeople wanted to group all the trailers with the same token together.\n\n> So we want to allow this:\n>\n>   Signed-off-by: A U Thor <author@example.com>\n>   Signed-off-by: Joe R. Hacker <joe@hacker.com>\n>   Acked-by: D E Veloper <developer@example.com>\n>   Signed-off-by: C O Mitter <committer@example.com>\n>\n> but prevent this\n>\n>   Signed-off-by: C O Mitter <committer@example.com>\n>   Signed-off-by: C O Mitter <committer@example.com>\n\nThis can be prevented by using \"addIfDifferentNeighbor\", for example like this:\n\n$ git config trailer.sign.ifexists addIfDifferentNeighbor\n\nSo I think the full config for what you want would be something like:\n\n$ git config trailer.sign.key \"Signed-off-by: \"\n$ git config trailer.sign.ifmissing add\n$ git config trailer.sign.ifexists addIfDifferentNeighbor\n$ git config trailer.sign.where end\n$ git config trailer.sign.command 'echo \"$(git config user.name)\n<$(git config user.email)>\"'\n\n$ git config trailer.ack.key \"Acked-by: \"\n$ git config trailer.ack.ifmissing add\n$ git config trailer.ack.ifexists addIfDifferentNeighbor\n$ git config trailer.ack.where end\n\nBest,\nChristian.\n"}]}