[PATCH 5/9] strbuf: add strbuf_isspace()
This helper function checks if a strbuf contains only space chars or not. Signed-off-by: Christian Couder --- strbuf.c | 7 +++ strbuf.h | 1 + 2 files changed, 8 insertions(+) diff --git a/strbuf.c b/strbuf.c index 83caf4a..2124bb8 100644 --- a/strbuf.c +++ b/strbuf.c @@ -124,6 +124,13 @@ void strbuf_ltrim(struct strbuf *sb) sb->buf[sb->len] = '\0'; } +int strbuf_isspace(struct strbuf *sb) +{ + char *b; + for (b = sb->buf; *b && isspace(*b); b++); + return !*b; +} + struct strbuf **strbuf_split_buf(const char *str, size_t slen, int terminator, int max) { diff --git a/strbuf.h b/strbuf.h index 73e80ce..02bff3a 100644 --- a/strbuf.h +++ b/strbuf.h @@ -42,6 +42,7 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) { extern void strbuf_trim(struct strbuf *); extern void strbuf_rtrim(struct strbuf *); extern void strbuf_ltrim(struct strbuf *); +extern int strbuf_isspace(struct strbuf *); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); /* -- 1.8.4.1.616.g07f5c81 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/9] trailer: process trailers from file and arguments
This patch implements the logic that process trailers from file and arguments. At the beginning trailers from file are in their own infile_tok doubly linked list, and trailers from arguments are in their own arg_tok doubly linked list. The lists are traversed and when an arg_tok should be "applied", it is removed from its list and inserted into the infile_tok list. Signed-off-by: Christian Couder --- trailer.c | 189 ++ 1 file changed, 189 insertions(+) diff --git a/trailer.c b/trailer.c index ccbcfb0..bd6595d 100644 --- a/trailer.c +++ b/trailer.c @@ -45,3 +45,192 @@ static size_t alnum_len(const char *buf, size_t len) { while (--len >= 0 && !isalnum(buf[len])); return len + 1; } + +static void add_arg_to_infile(struct trailer_item *infile_tok, + struct trailer_item *arg_tok) +{ + if (arg_tok->conf->where == AFTER) { + arg_tok->next = infile_tok->next; + infile_tok->next = arg_tok; + arg_tok->previous = infile_tok; + if (arg_tok->next) + arg_tok->next->previous = arg_tok; + } else { + arg_tok->previous = infile_tok->previous; + infile_tok->previous = arg_tok; + arg_tok->next = infile_tok; + if (arg_tok->previous) + arg_tok->previous->next = arg_tok; + } +} + +static int check_if_different(struct trailer_item *infile_tok, + struct trailer_item *arg_tok, + int alnum_len, int check_all) +{ + enum action_where where = arg_tok->conf->where; + do { + if (!infile_tok) + return 1; + if (same_trailer(infile_tok, arg_tok, alnum_len)) + return 0; + /* +* if we want to add a trailer after another one, +* we have to check those before this one +*/ + infile_tok = (where == AFTER) ? infile_tok->previous : infile_tok->next; + } while (check_all); + return 1; +} + +static void apply_arg_if_exist(struct trailer_item *infile_tok, + struct trailer_item *arg_tok, + int alnum_len) +{ + switch(arg_tok->conf->if_exist) { + case EXIST_DO_NOTHING: + free(arg_tok); + break; + case EXIST_OVERWRITE: + free((char *)infile_tok->value); + infile_tok->value = xstrdup(arg_tok->value); + free(arg_tok); + break; + case EXIST_ADD: + add_arg_to_infile(infile_tok, arg_tok); + break; + case EXIST_ADD_IF_DIFFERENT: + if (check_if_different(infile_tok, arg_tok, alnum_len, 1)) + add_arg_to_infile(infile_tok, arg_tok); + else + free(arg_tok); + break; + case EXIST_ADD_IF_DIFFERENT_NEIGHBOR: + if (check_if_different(infile_tok, arg_tok, alnum_len, 0)) + add_arg_to_infile(infile_tok, arg_tok); + else + free(arg_tok); + break; + } +} + +static void remove_from_list(struct trailer_item *item, +struct trailer_item **first) +{ + if (item->next) + item->next->previous = item->previous; + if (item->previous) + item->previous->next = item->next; + else + *first = item->next; +} + +static struct trailer_item *remove_first(struct trailer_item **first) +{ + struct trailer_item *item = *first; + *first = item->next; + if (item->next) { + item->next->previous = NULL; + item->next = NULL; + } + return item; +} + +static void process_infile_tok(struct trailer_item *infile_tok, + struct trailer_item **arg_tok_first, + enum action_where where) +{ + struct trailer_item *arg_tok; + struct trailer_item *next_arg; + + int tok_alnum_len = alnum_len(infile_tok->token, strlen(infile_tok->token)); + for (arg_tok = *arg_tok_first; arg_tok; arg_tok = next_arg) { + next_arg = arg_tok->next; + if (same_token(infile_tok, arg_tok, tok_alnum_len) && + arg_tok->conf->where == where) { + /* Remove arg_tok from list */ + remove_from_list(arg_tok, arg_tok_first); + /* Apply arg */ + apply_arg_if_exist(infile_tok, arg_tok, tok_alnum_len); + /* +* If arg has been added to infile, +* then we need to process it too now. +*/ + if ((where =
[PATCH 7/9] trailer: put all the processing together and print
This patch adds the process_trailers() function that calls all the previously added processing functions and then prints the results on the standard output. Signed-off-by: Christian Couder --- trailer.c | 40 1 file changed, 40 insertions(+) diff --git a/trailer.c b/trailer.c index 22d3ea3..33aa907 100644 --- a/trailer.c +++ b/trailer.c @@ -48,6 +48,26 @@ static size_t alnum_len(const char *buf, size_t len) { return len + 1; } +static void print_tok_val(const char *tok, const char *val) +{ + char c = tok[strlen(tok) - 1]; + if (isalnum(c)) + printf("%s: %s\n", tok, val); + else if (isspace(c) || c == '#') + printf("%s%s\n", tok, val); + else + printf("%s %s\n", tok, val); +} + +static void print_all(struct trailer_item *first, int trim_empty) +{ + struct trailer_item *item; + for (item = first; item; item = item->next) { + if (!trim_empty || strlen(item->value) > 0) + print_tok_val(item->token, item->value); + } +} + static void add_arg_to_infile(struct trailer_item *infile_tok, struct trailer_item *arg_tok) { @@ -502,3 +522,23 @@ static void process_input_file(const char *infile, add_trailer_item(infile_tok_first, infile_tok_last, new); } } + +void process_trailers(const char *infile, int trim_empty, int argc, const char **argv) +{ + struct trailer_item *infile_tok_first = NULL; + struct trailer_item *infile_tok_last = NULL; + struct trailer_item *arg_tok_first; + + git_config(git_trailer_config, NULL); + + /* Print the non trailer part of infile */ + if (infile) { + process_input_file(infile, &infile_tok_first, &infile_tok_last); + } + + arg_tok_first = process_command_line_args(argc, argv); + + process_trailers_lists(&infile_tok_first, &infile_tok_last, &arg_tok_first); + + print_all(infile_tok_first, trim_empty); +} -- 1.8.4.1.616.g07f5c81 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/9] trailer: process command line trailer arguments
This patch parses the trailer command line arguments and put the result into an arg_tok doubly linked list. Signed-off-by: Christian Couder --- trailer.c | 77 +++ 1 file changed, 77 insertions(+) diff --git a/trailer.c b/trailer.c index 6aba40e..b572c44 100644 --- a/trailer.c +++ b/trailer.c @@ -363,3 +363,80 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb) } return 0; } + +static void parse_trailer(struct strbuf *tok, struct strbuf *val, const char *trailer) +{ + char *end = strchr(trailer, '='); + if (!end) + end = strchr(trailer, ':'); + if (end) { + strbuf_add(tok, trailer, end - trailer); + strbuf_trim(tok); + strbuf_addstr(val, end + 1); + strbuf_trim(val); + } else { + strbuf_addstr(tok, trailer); + strbuf_trim(tok); + } +} + +static struct trailer_item *create_trailer_item(const char *string) +{ + struct strbuf tok = STRBUF_INIT; + struct strbuf val = STRBUF_INIT; + struct trailer_item *new; + + parse_trailer(&tok, &val, string); + + int tok_alnum_len = alnum_len(tok.buf, tok.len); + + /* Lookup if the token matches something in the config */ + struct trailer_item *item; + for (item = first_conf_item; item; item = item->next) + { + if (!strncasecmp(tok.buf, item->conf->key, tok_alnum_len) || + !strncasecmp(tok.buf, item->conf->name, tok_alnum_len)) { + new = xcalloc(sizeof(struct trailer_item), 1); + new->conf = item->conf; + new->token = xstrdup(item->conf->key); + new->value = strbuf_detach(&val, NULL); + strbuf_release(&tok); + return new; + } + } + + new = xcalloc(sizeof(struct trailer_item), 1); + new->conf = xcalloc(sizeof(struct conf_info), 1); + new->token = strbuf_detach(&tok, NULL); + new->value = strbuf_detach(&val, NULL); + + return new; +} + +static void add_trailer_item(struct trailer_item **first, +struct trailer_item **last, +struct trailer_item *new) +{ + if (!*last) { + *first = new; + *last = new; + } else { + (*last)->next = new; + new->previous = *last; + *last = new; + } +} + +static struct trailer_item *process_command_line_args(int argc, const char **argv) +{ + int i; + struct trailer_item *arg_tok_first = NULL; + struct trailer_item *arg_tok_last = NULL; + + for (i = 0; i < argc; i++) { + struct trailer_item *new = create_trailer_item(argv[i]); + add_trailer_item(&arg_tok_first, &arg_tok_last, new); + } + + return arg_tok_first; +} -- 1.8.4.1.616.g07f5c81 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 6/9] trailer: parse trailers from input file
This patch reads trailers from an input file, parses them and puts the result into a doubly linked list. Signed-off-by: Christian Couder --- trailer.c | 62 ++ 1 file changed, 62 insertions(+) diff --git a/trailer.c b/trailer.c index b572c44..22d3ea3 100644 --- a/trailer.c +++ b/trailer.c @@ -440,3 +440,65 @@ static struct trailer_item *process_command_line_args(int argc, const char **arg return arg_tok_first; } + +static struct strbuf **read_input_file(const char *infile) +{ + struct strbuf sb = STRBUF_INIT; + + if (strbuf_read_file(&sb, infile, 0) < 0) + die_errno(_("could not read input file '%s'"), infile); + + return strbuf_split(&sb, '\n'); +} + +/* + * Return the the (0 based) index of the first trailer line + * or the line count if there are no trailers. + */ +static int find_trailer_start(struct strbuf **lines) +{ + int count, start, empty = 1; + + /* Get the line count */ + for (count = 0; lines[count]; count++); + + /* +* Get the start of the trailers by looking starting from the end +* for a line with only spaces before lines with one ':'. +*/ + for (start = count - 1; start >= 0; start--) { + if (strbuf_isspace(lines[start])) { + if (empty) + continue; + return start + 1; + } + if (strchr(lines[start]->buf, ':')) { + if (empty) + empty = 0; + continue; + } + return count; + } + + return empty ? count : start + 1; +} + +static void process_input_file(const char *infile, + struct trailer_item **infile_tok_first, + struct trailer_item **infile_tok_last) +{ + struct strbuf **lines = read_input_file(infile); + int start = find_trailer_start(lines); + int i; + + /* Print non trailer lines as is */ + for (i = 0; lines[i] && i < start; i++) { + printf("%s", lines[i]->buf); + } + + /* Parse trailer lines */ + for (i = start; lines[i]; i++) { + struct trailer_item *new = create_trailer_item(lines[i]->buf); + add_trailer_item(infile_tok_first, infile_tok_last, new); + } +} -- 1.8.4.1.616.g07f5c81 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/9] trailer: read and process config information
This patch implements reading the configuration to get trailer information, and then processing it and storing it in a doubly linked list. The config information is stored in the list whose first item is pointed to by: static struct trailer_item *first_conf_item; Signed-off-by: Christian Couder --- trailer.c | 129 ++ 1 file changed, 129 insertions(+) diff --git a/trailer.c b/trailer.c index bd6595d..6aba40e 100644 --- a/trailer.c +++ b/trailer.c @@ -25,6 +25,8 @@ struct trailer_item { struct conf_info *conf; }; +static struct trailer_item *first_conf_item; + static int same_token(struct trailer_item *a, struct trailer_item *b, int alnum_len) { return !strncasecmp(a->token, b->token, alnum_len); @@ -234,3 +236,130 @@ static void process_trailers_lists(struct trailer_item **infile_tok_first, apply_arg_if_missing(infile_tok_first, infile_tok_last, arg_tok); } } + +static int set_where(struct conf_info *item, const char *value) +{ + if (!strcasecmp("after", value)) { + item->where = AFTER; + } else if (!strcasecmp("before", value)) { + item->where = BEFORE; + } else + return 1; + return 0; +} + +static int set_if_exist(struct conf_info *item, const char *value) +{ + if (!strcasecmp("addIfDifferent", value)) { + item->if_exist = EXIST_ADD_IF_DIFFERENT; + } else if (!strcasecmp("addIfDifferentNeighbor", value)) { + item->if_exist = EXIST_ADD_IF_DIFFERENT_NEIGHBOR; + } else if (!strcasecmp("add", value)) { + item->if_exist = EXIST_ADD; + } else if (!strcasecmp("overwrite", value)) { + item->if_exist = EXIST_OVERWRITE; + } else if (!strcasecmp("doNothing", value)) { + item->if_exist = EXIST_DO_NOTHING; + } else + return 1; + return 0; +} + +static int set_if_missing(struct conf_info *item, const char *value) +{ + if (!strcasecmp("doNothing", value)) { + item->if_missing = MISSING_DO_NOTHING; + } else if (!strcasecmp("add", value)) { + item->if_missing = MISSING_ADD; + } else + return 1; + return 0; +} + +enum trailer_info_type { TRAILER_VALUE, TRAILER_COMMAND, TRAILER_WHERE, +TRAILER_IF_EXIST, TRAILER_IF_MISSING }; + +static int set_name_and_type(const char *conf_key, const char *suffix, +enum trailer_info_type type, +char **pname, enum trailer_info_type *ptype) +{ + int ret = ends_with(conf_key, suffix); + if (ret) { + *pname = xstrndup(conf_key, strlen(conf_key) - strlen(suffix)); + *ptype = type; + } + return ret; +} + +static struct trailer_item *get_conf_item(char *name) +{ + struct trailer_item *item; + struct trailer_item *previous; + + /* Look up item with same name */ + for (previous = NULL, item = first_conf_item; +item; +previous = item, item = item->next) + { + if (!strcasecmp(item->conf->name, name)) + return item; + } + + /* Item does not already exists, create it */ + item = xcalloc(sizeof(struct trailer_item), 1); + item->conf = xcalloc(sizeof(struct conf_info), 1); + item->conf->name = xstrdup(name); + + if (!previous) { + first_conf_item = item; + } else { + previous->next = item; + item->previous = previous; + } + + return item; +} + +static int git_trailer_config(const char *conf_key, const char *value, void *cb) +{ + if (starts_with(conf_key, "trailer.")) { + const char *orig_conf_key = conf_key; + struct trailer_item *item; + struct conf_info *conf; + char *name; + enum trailer_info_type type; + + conf_key += 8; + if (!set_name_and_type(conf_key, ".key", TRAILER_VALUE, &name, &type) && + !set_name_and_type(conf_key, ".command", TRAILER_COMMAND, &name, &type) && + !set_name_and_type(conf_key, ".where", TRAILER_WHERE, &name, &type) && + !set_name_and_type(conf_key, ".ifexist", TRAILER_IF_EXIST, &name, &type) && + !set_name_and_type(conf_key, ".ifmissing", TRAILER_IF_MISSING, &name, &type)) + return 0; + + item = get_conf_item(name); + conf = item->conf; + + if (type == TRAILER_VALUE) { + if (conf->key) + warning(_("more than one %s"), orig_conf_key); + conf->key = xstrdup(value); + } else if (type == TRAILER_COMMAND) { + if (conf->command) +
[PATCH 1/9] Add data structures and basic functions for commit trailers
We will use a doubly linked list to store all information about trailers and their configuration. This way we can easily remove or add trailers to or from trailer lists while traversing the lists in either direction. Signed-off-by: Christian Couder --- Makefile | 1 + trailer.c | 47 +++ 2 files changed, 48 insertions(+) create mode 100644 trailer.c diff --git a/Makefile b/Makefile index b4af1e2..ec90feb 100644 --- a/Makefile +++ b/Makefile @@ -871,6 +871,7 @@ LIB_OBJS += submodule.o LIB_OBJS += symlinks.o LIB_OBJS += tag.o LIB_OBJS += trace.o +LIB_OBJS += trailer.o LIB_OBJS += transport.o LIB_OBJS += transport-helper.o LIB_OBJS += tree-diff.o diff --git a/trailer.c b/trailer.c new file mode 100644 index 000..ccbcfb0 --- /dev/null +++ b/trailer.c @@ -0,0 +1,47 @@ +#include "cache.h" +/* + * Copyright (c) 2013 Christian Couder + */ + +enum action_where { AFTER, BEFORE }; +enum action_if_exist { EXIST_ADD_IF_DIFFERENT, EXIST_ADD_IF_DIFFERENT_NEIGHBOR, + EXIST_ADD, EXIST_OVERWRITE, EXIST_DO_NOTHING }; +enum action_if_missing { MISSING_ADD, MISSING_DO_NOTHING }; + +struct conf_info { + char *name; + char *key; + char *command; + enum action_where where; + enum action_if_exist if_exist; + enum action_if_missing if_missing; +}; + +struct trailer_item { + struct trailer_item *previous; + struct trailer_item *next; + const char *token; + const char *value; + struct conf_info *conf; +}; + +static int same_token(struct trailer_item *a, struct trailer_item *b, int alnum_len) +{ + return !strncasecmp(a->token, b->token, alnum_len); +} + +static int same_value(struct trailer_item *a, struct trailer_item *b) +{ + return !strcasecmp(a->value, b->value); +} + +static int same_trailer(struct trailer_item *a, struct trailer_item *b, int alnum_len) +{ + return same_token(a, b, alnum_len) && same_value(a, b); +} + +/* Get the length of buf from its beginning until its last alphanumeric character */ +static size_t alnum_len(const char *buf, size_t len) { + while (--len >= 0 && !isalnum(buf[len])); + return len + 1; +} -- 1.8.4.1.616.g07f5c81 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 8/9] trailer: add interpret-trailers command
This patch adds the "git interpret-trailers" command. This command uses the previously added process_trailers() function in trailer.c. Signed-off-by: Christian Couder --- .gitignore | 1 + Makefile | 1 + builtin.h| 1 + builtin/interpret-trailers.c | 36 git.c| 1 + trailer.h| 6 ++ 6 files changed, 46 insertions(+) create mode 100644 builtin/interpret-trailers.c create mode 100644 trailer.h diff --git a/.gitignore b/.gitignore index b5f9def..c870ada 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ /git-index-pack /git-init /git-init-db +/git-interpret-trailers /git-instaweb /git-log /git-ls-files diff --git a/Makefile b/Makefile index ec90feb..a91465e 100644 --- a/Makefile +++ b/Makefile @@ -935,6 +935,7 @@ BUILTIN_OBJS += builtin/hash-object.o BUILTIN_OBJS += builtin/help.o BUILTIN_OBJS += builtin/index-pack.o BUILTIN_OBJS += builtin/init-db.o +BUILTIN_OBJS += builtin/interpret-trailers.o BUILTIN_OBJS += builtin/log.o BUILTIN_OBJS += builtin/ls-files.o BUILTIN_OBJS += builtin/ls-remote.o diff --git a/builtin.h b/builtin.h index d4afbfe..30f4c30 100644 --- a/builtin.h +++ b/builtin.h @@ -71,6 +71,7 @@ extern int cmd_hash_object(int argc, const char **argv, const char *prefix); extern int cmd_help(int argc, const char **argv, const char *prefix); extern int cmd_index_pack(int argc, const char **argv, const char *prefix); extern int cmd_init_db(int argc, const char **argv, const char *prefix); +extern int cmd_interpret_trailers(int argc, const char **argv, const char *prefix); extern int cmd_log(int argc, const char **argv, const char *prefix); extern int cmd_log_reflog(int argc, const char **argv, const char *prefix); extern int cmd_ls_files(int argc, const char **argv, const char *prefix); diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c new file mode 100644 index 000..f79bffa --- /dev/null +++ b/builtin/interpret-trailers.c @@ -0,0 +1,36 @@ +/* + * Builtin "git interpret-trailers" + * + * Copyright (c) 2013 Christian Couder + * + */ + +#include "cache.h" +#include "builtin.h" +#include "parse-options.h" +#include "strbuf.h" +#include "trailer.h" + +static const char * const git_interpret_trailers_usage[] = { + N_("git interpret-trailers [--trim-empty] [--infile=file] [...]"), + NULL +}; + +int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) +{ + const char *infile = NULL; + int trim_empty = 0; + + struct option options[] = { + OPT_BOOL(0, "trim-empty", &trim_empty, N_("trim empty trailers")), + OPT_FILENAME(0, "infile", &infile, N_("use message from file")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, +git_interpret_trailers_usage, 0); + + process_trailers(infile, trim_empty, argc, argv); + + return 0; +} diff --git a/git.c b/git.c index 3799514..1420b58 100644 --- a/git.c +++ b/git.c @@ -383,6 +383,7 @@ static void handle_internal_command(int argc, const char **argv) { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY }, { "init", cmd_init_db }, { "init-db", cmd_init_db }, + { "interpret-trailers", cmd_interpret_trailers, RUN_SETUP }, { "log", cmd_log, RUN_SETUP }, { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, diff --git a/trailer.h b/trailer.h new file mode 100644 index 000..9db4459 --- /dev/null +++ b/trailer.h @@ -0,0 +1,6 @@ +#ifndef TRAILER_H +#define TRAILER_H + +void process_trailers(const char *infile, int trim_empty, int argc, const char **argv); + +#endif /* TRAILER_H */ -- 1.8.4.1.616.g07f5c81 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/9] Add interpret-trailers builtin
This patch series implements a new command: git interpret-trailers and an infrastructure to process trailers that can be reused, for example in "commit.c". 1) Rationale: This command should help with RFC 822 style headers, called "trailers", that are found at the end of commit messages. (Note that these headers do not follow and are not intended to follow many rules that are in RFC 822. For example they do not follow the line breaking rules, the encoding rules and probably many other rules.) For a long time, these trailers have become a de facto standard way to add helpful information into commit messages. Until now git commit has only supported the well known "Signed-off-by: " trailer, that is used by many projects like the Linux kernel and Git. It is better to implement features for these trailers first in a new command rather than in builtin/commit.c, because this way the prepare-commit-msg and commit-msg hooks can reuse this command. 2) Current state: Currently the usage string of this command is: git interpret-trailers [--trim-empty] [--infile=file] [...] The following features are implemented: - the result is printed on stdout - the [...] arguments are interpreted - a commit message passed using the "--infile=file" option is interpreted - the "trailer..key" options in the config are interpreted - the "trailer..where" options are interpreted - the "trailer..ifExist" options are interpreted - the "trailer..ifMissing" options are interpreted - there are a lot of tests The following features are planned but not yet implemented: - making "git interpret-trailers" a filter - some documentation - the "trailer..command" config option 3) Notes: * I chose "trailer..key" over "trailer..value" and "trailer..trailer", as I think it is clearer. * I focused on a cleaner and more complete implementation than the PATCH/RFC I sent previously. Happy end of year! Christian Couder (9): Add data structures and basic functions for commit trailers trailer: process trailers from file and arguments trailer: read and process config information trailer: process command line trailer arguments strbuf: add strbuf_isspace() trailer: parse trailers from input file trailer: put all the processing together and print trailer: add interpret-trailers command trailer: add tests for "git interpret-trailers" .gitignore| 1 + Makefile | 2 + builtin.h | 1 + builtin/interpret-trailers.c | 36 +++ git.c | 1 + strbuf.c | 7 + strbuf.h | 1 + t/t7513-interpret-trailers.sh | 206 trailer.c | 544 ++ trailer.h | 6 + 10 files changed, 805 insertions(+) create mode 100644 builtin/interpret-trailers.c create mode 100755 t/t7513-interpret-trailers.sh create mode 100644 trailer.c create mode 100644 trailer.h -- 1.8.4.1.616.g07f5c81 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 9/9] trailer: add tests for "git interpret-trailers"
Signed-off-by: Christian Couder --- t/t7513-interpret-trailers.sh | 206 ++ 1 file changed, 206 insertions(+) create mode 100755 t/t7513-interpret-trailers.sh diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh new file mode 100755 index 000..beb58fe --- /dev/null +++ b/t/t7513-interpret-trailers.sh @@ -0,0 +1,206 @@ +#!/bin/sh +# +# Copyright (c) 2013 Christian Couder +# + +test_description='git interpret-trailers' + +. ./test-lib.sh + +cat >basic_message <<'EOF' +subject + +body +EOF + +cat >complex_message_body <<'EOF' +my subject + +my body which is long +and contains some special +chars like : = ? ! + +EOF + +# Do not remove trailing spaces below! +cat >complex_message_trailers <<'EOF' +Fixes: +Acked-by: +Reviewed-by: +Signed-off-by: +EOF + +test_expect_success 'without config' ' + printf "ack: Peff\nReviewed-by: \nAcked-by: Johan\n" >expected && + git interpret-trailers "ack = Peff" "Reviewed-by" "Acked-by: Johan" >actual && + test_cmp expected actual +' + +test_expect_success '--trim-empty without config' ' + printf "ack: Peff\nAcked-by: Johan\n" >expected && + git interpret-trailers --trim-empty "ack = Peff" "Reviewed-by" "Acked-by: Johan" "sob:" >actual && + test_cmp expected actual +' + +test_expect_success 'with config setup' ' + git config trailer.ack.key "Acked-by: " && + printf "Acked-by: Peff\n" >expected && + git interpret-trailers --trim-empty "ack = Peff" >actual && + test_cmp expected actual && + git interpret-trailers --trim-empty "Acked-by = Peff" >actual && + test_cmp expected actual && + git interpret-trailers --trim-empty "Acked-by :Peff" >actual && + test_cmp expected actual +' + +test_expect_success 'with config setup and = sign' ' + git config trailer.ack.key "Acked-by= " && + printf "Acked-by= Peff\n" >expected && + git interpret-trailers --trim-empty "ack = Peff" >actual && + test_cmp expected actual && + git interpret-trailers --trim-empty "Acked-by= Peff" >actual && + test_cmp expected actual && + git interpret-trailers --trim-empty "Acked-by : Peff" >actual && + test_cmp expected actual +' + +test_expect_success 'with config setup and # sign' ' + git config trailer.bug.key "Bug #" && + printf "Bug #42\n" >expected && + git interpret-trailers --trim-empty "bug = 42" >actual && + test_cmp expected actual +' + +test_expect_success 'with commit basic message' ' + git interpret-trailers --infile basic_message >actual && + test_cmp basic_message actual +' + +test_expect_success 'with commit complex message' ' + cat complex_message_body complex_message_trailers >complex_message && + cat complex_message_body >expected && + printf "Fixes: \nAcked-by= \nReviewed-by: \nSigned-off-by: \n" >>expected && + git interpret-trailers --infile complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'with commit complex message and args' ' + cat complex_message_body >expected && + printf "Fixes: \nAcked-by= \nAcked-by= Peff\nReviewed-by: \nSigned-off-by: \nBug #42\n" >>expected && + git interpret-trailers --infile complex_message "ack: Peff" "bug: 42" >actual && + test_cmp expected actual +' + +test_expect_success 'with commit complex message, args and --trim-empty' ' + cat complex_message_body >expected && + printf "Acked-by= Peff\nBug #42\n" >>expected && + git interpret-trailers --trim-empty --infile complex_message "ack: Peff" "bug: 42" >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = before"' ' + git config trailer.bug.where "before" && + cat complex_message_body >expected && + printf "Bug #42\nFixes: \nAcked-by= \nAcked-by= Peff\nReviewed-by: \nSigned-off-by: \n" >>expected && + git interpret-trailers --infile complex_message "ack: Peff" "bug: 42" >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = before" for a token in the middle of infile' ' + git config trailer.review.key "Reviewed-by:" && + git config trailer.review.where "before" && + cat complex_message_body >expected && + printf "Bug #42\nFixes: \nAcked-by= \nAcked-by= Peff\nReviewed-by: Johan\nReviewed-by: \nSigned-off-by: \n" >>expected && + git interpret-trailers --infile complex_message "ack: Peff" "bug: 42" "review: Johan" >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = before" and --trim-empty' ' + cat complex_message_body >expected && + printf "Bug #46\nBug #42\nAcked-by= Peff\nReviewed-by: Johan\n" >>expected && + git interpret-trailers --infile complex_message --trim-empty "ack: Peff" "bug: 42" "review: Johan" "Bug: 46" >actual && + test_cmp expected actual +' + +test_expect_success 'the defau
Re: [PATCH] add: don't complain when adding empty project root
On Tue, Dec 24, 2013 at 12:48 AM, Torsten Bögershausen wrote: >> +test_expect_success 'git add -A on empty repo does not error out' ' >> + git init empty && ( cd empty && git add -A . ) >> +' >> + >> test_done >> > I am (a little bit) confused. > > This is what git does: > rm -rf test && mkdir test && cd test && git init && touch A && mkdir D && cd > D && touch B && git add . && git status > Initialized empty Git repository in /Users/tb/test/test/.git/ > On branch master > > Initial commit > > Changes to be committed: > (use "git rm --cached ..." to unstage) > > new file: B > > Untracked files: > (use "git add ..." to include in what will be committed) > > ../A > > And the behaviour is in line with > https://www.kernel.org/pub/software/scm/git/docs/git-add.html > > "." stands for the current directory somewhere in the worktree, > not only the "project root". Yes, except in this case "." is project root because current dir is. I could have done "git add -A" (without the dot) like reported, but that will be deprecated soon. Another way to make it clear about project root is use "git add -A :/". I'll send an update if it makes it clearer. > - > > Could it make sense to mention that replace > [PATCH] add: don't complain when adding empty project root > with > [PATCH] add: don't complain when adding empty directory. We don't complain about adding an empty directory before or after this patch. > > (and similar in the commit message) > /Torsten > -- Duy -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] remote-hg: test 'shared_path' in a moved clone
Since e71d1378 (remote-hg: fix 'shared path' path, 2013-12-07), Mercurial 'shared_path' file is correctly updated whenever a clone is moved. Make sure it keeps working, especially as this is depending on a private Mercurial file. Signed-off-by: Antoine Pelisse --- contrib/remote-helpers/test-hg.sh | 11 +++ 1 file changed, 11 insertions(+) diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh index 0b7df11..5d128a5 100755 --- a/contrib/remote-helpers/test-hg.sh +++ b/contrib/remote-helpers/test-hg.sh @@ -337,6 +337,17 @@ test_expect_success 'remote cloning' ' check gitrepo HEAD zero ' +test_expect_success 'moving remote clone' ' + test_when_finished "rm -rf gitrepo*" && + + ( + git clone "hg::hgrepo" gitrepo && + mv gitrepo gitrepo2 && + cd gitrepo2 && + git fetch + ) +' + test_expect_success 'remote update bookmark' ' test_when_finished "rm -rf gitrepo*" && -- 1.8.5.1.97.g8d784da.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] add: don't complain when adding empty project root
On 2013-12-23 10.02, Nguyễn Thái Ngọc Duy wrote: > This behavior was added in 07d7bed (add: don't complain when adding > empty project root - 2009-04-28) then broken by 84b8b5d (remove > match_pathspec() in favor of match_pathspec_depth() - > 2013-07-14). Reinstate it. > > Noticed-by: Thomas Ferris Nicolaisen > Signed-off-by: Nguyễn Thái Ngọc Duy > --- > builtin/add.c | 2 +- > t/t3700-add.sh | 4 > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/builtin/add.c b/builtin/add.c > index 226f758..fbd3f3a 100644 > --- a/builtin/add.c > +++ b/builtin/add.c > @@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char > *prefix) > > for (i = 0; i < pathspec.nr; i++) { > const char *path = pathspec.items[i].match; > - if (!seen[i] && > + if (!seen[i] && pathspec.items[i].match[0] && > ((pathspec.items[i].magic & > (PATHSPEC_GLOB | PATHSPEC_ICASE)) || >!file_exists(path))) { > diff --git a/t/t3700-add.sh b/t/t3700-add.sh > index aab86e8..1535d8f 100755 > --- a/t/t3700-add.sh > +++ b/t/t3700-add.sh > @@ -307,4 +307,8 @@ test_expect_success 'git add --dry-run --ignore-missing > of non-existing file out > test_i18ncmp expect.err actual.err > ' > > +test_expect_success 'git add -A on empty repo does not error out' ' > + git init empty && ( cd empty && git add -A . ) > +' > + > test_done > I am (a little bit) confused. This is what git does: rm -rf test && mkdir test && cd test && git init && touch A && mkdir D && cd D && touch B && git add . && git status Initialized empty Git repository in /Users/tb/test/test/.git/ On branch master Initial commit Changes to be committed: (use "git rm --cached ..." to unstage) new file: B Untracked files: (use "git add ..." to include in what will be committed) ../A And the behaviour is in line with https://www.kernel.org/pub/software/scm/git/docs/git-add.html "." stands for the current directory somewhere in the worktree, not only the "project root". - Could it make sense to mention that replace [PATCH] add: don't complain when adding empty project root with [PATCH] add: don't complain when adding empty directory. (and similar in the commit message) /Torsten -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Rationale behind 'extern' on protypes in .h files
Ravi Shekhar Jethani writes: > To check this I installed the libgit2-dev package which installed: > /usr/include/git2/*.h , /usr/lib/libgit2.so > Now, I exported all symbols using: > $ readelf -s /usr/lib/libgit2.so > and tried to match these with 'externed' prototypes in the Git source > directory..no matches. > I am confused!!!. libgit2 is an entirely different package from Git. If you look at the libgit2 sources (https://github.com/libgit2/libgit2), look in include/git2/common.h: /** Declare a public function exported for application use. */ #if __GNUC__ >= 4 # define GIT_EXTERN(type) extern \ __attribute__((visibility("default"))) \ type #elif defined(_MSC_VER) # define GIT_EXTERN(type) __declspec(dllexport) type #else # define GIT_EXTERN(type) extern type #endif I have always used __attribute__((visibility("default"))), but the gcc man page says extern declarations are not affected by -fvisibility, so a lot of code can be recompiled with -fvisibility=hidden with no modifications. However, this means that calls to "extern" functions with no explicit visibility use the PLT, so it is more effective to use "__attribute ((visibility))" and/or "#pragma GCC visibility" to tell the compiler which "extern" declarations should be treated as hidden. However, I don't understand what the first statement means (documentation bug?) since -fvisibility=hidden causes functions declared with 'extern' to be hidden. symbols.c: EXTERN int foo(void); int foo(void) {return 1;} $ gcc -fvisibility=hidden -DEXTERN=extern -shared -o libsymbols.so symbols.c $ nm -D libsymbols.so | grep foo $ meanwhile, $ gcc -fvisibility=hidden -DEXTERN='__attribute((visibility("default")))' -shared -o libsymbols.so symbols.c $ nm -D libsymbols.so | grep foo 055c T foo > Also I checked this: > $ ldd git > There is no 'gitish' .so in the output; it seems everything is packed > inside one executable. > So your second point 'skipping the PLT...' also doesn't seem to apply here. My comment applied to shared libraries in general, not specifically to Git (which isn't a shared library). pgpHYEPGwoA09.pgp Description: PGP signature
Re: Rationale behind 'extern' on protypes in .h files
2013/12/22 Jed Brown : > There is a difference for shared libraries if you would like to control > which symbols are exported. With gcc, for example, you might compile > using -fvisibility=hidden. Any functions explicitly declared with > extern, bearing __attribute__((visibility("default")), or using > visibility pragmas will be exported (similar to __declspec(dllexport) on > Windows). Other functions will be internal to the shared library so you > don't have to worry about callers depending on those symbols and > performance can be a bit better by skipping the PLT and avoiding symbol > relocations at load time. See Drepper's guide for more. > > http://www.akkadia.org/drepper/dsohowto.pdf To check this I installed the libgit2-dev package which installed: /usr/include/git2/*.h , /usr/lib/libgit2.so Now, I exported all symbols using: $ readelf -s /usr/lib/libgit2.so and tried to match these with 'externed' prototypes in the Git source directory..no matches. I am confused!!!. Also I checked this: $ ldd git There is no 'gitish' .so in the output; it seems everything is packed inside one executable. So your second point 'skipping the PLT...' also doesn't seem to apply here. Regards, Ravi Shekhar Jethani -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] add: don't complain when adding empty project root
This behavior was added in 07d7bed (add: don't complain when adding empty project root - 2009-04-28) then broken by 84b8b5d (remove match_pathspec() in favor of match_pathspec_depth() - 2013-07-14). Reinstate it. Noticed-by: Thomas Ferris Nicolaisen Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/add.c | 2 +- t/t3700-add.sh | 4 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin/add.c b/builtin/add.c index 226f758..fbd3f3a 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) for (i = 0; i < pathspec.nr; i++) { const char *path = pathspec.items[i].match; - if (!seen[i] && + if (!seen[i] && pathspec.items[i].match[0] && ((pathspec.items[i].magic & (PATHSPEC_GLOB | PATHSPEC_ICASE)) || !file_exists(path))) { diff --git a/t/t3700-add.sh b/t/t3700-add.sh index aab86e8..1535d8f 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -307,4 +307,8 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out test_i18ncmp expect.err actual.err ' +test_expect_success 'git add -A on empty repo does not error out' ' + git init empty && ( cd empty && git add -A . ) +' + test_done -- 1.8.5.2.240.g8478abd -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html