On Thu, Jan 30, 2014 at 1:49 AM, Christian Couder
<[email protected]> wrote:
> 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 <[email protected]>
> ---
> diff --git a/trailer.c b/trailer.c
> index e9ccfa5..d979a0f 100644
> --- a/trailer.c
> +++ b/trailer.c
> @@ -235,3 +237,128 @@ static void process_trailers_lists(struct trailer_item
> **infile_tok_first,
> +static struct trailer_item *get_conf_item(char *name)
Should this be 'const char *'?
> +{
> + 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)
> + warning(_("more than one %s"), orig_conf_key);
> + conf->command = xstrdup(value);
> + } else if (type == TRAILER_WHERE) {
> + if (set_where(conf, value))
> + warning(_("unknown value '%s' for key '%s'"),
> value, orig_conf_key);
> + } else if (type == TRAILER_IF_EXIST) {
> + if (set_if_exist(conf, value))
> + warning(_("unknown value '%s' for key '%s'"),
> value, orig_conf_key);
> + } else if (type == TRAILER_IF_MISSING) {
> + if (set_if_missing(conf, value))
> + warning(_("unknown value '%s' for key '%s'"),
> value, orig_conf_key);
> + } else
> + die("internal bug in trailer.c");
A 'switch' statement might be more idiomatic and easier to read.
> + }
> + return 0;
> +}
> --
> 1.8.5.2.201.gacc5987
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html