git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v16 01/11] trailer: add data structures and basic functions

From
Christian Couder <chriscool@tuxfamily.org>
Date
Oct 13, 2014, 18:16 UTC
Message-ID
<20141013181634.27329.82925.chriscool@tuxfamily.org>
In-Reply-To
<20141013181428.27329.86081.chriscool@tuxfamily.org>

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 <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Makefile  |  1 +
 trailer.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100644 trailer.c
diff --git a/Makefile b/Makefile
index 63a210d..ef82972 100644
--- a/Makefile
+++ b/Makefile
@@ -888,6 +888,7 @@ LIB_OBJS += submodule-config.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 0000000..ac323b1
--- /dev/null
+++ b/trailer.c
@@ -0,0 +1,69 @@
+#include "cache.h"
+/*
+ * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>
+ */
+
+enum action_where { WHERE_END, WHERE_AFTER, WHERE_BEFORE, WHERE_START };
+enum action_if_exists { EXISTS_ADD_IF_DIFFERENT_NEIGHBOR, EXISTS_ADD_IF_DIFFERENT,
+			EXISTS_ADD, EXISTS_REPLACE, EXISTS_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_exists if_exists;
+	enum action_if_missing if_missing;
+};
+
+static struct conf_info default_conf_info;
+
+struct trailer_item {
+	struct trailer_item *previous;
+	struct trailer_item *next;
+	const char *token;
+	const char *value;
+	struct conf_info conf;
+};
+
+static struct trailer_item *first_conf_item;
+
+static char *separators = ":";
+
+static int after_or_end(enum action_where where)
+{
+	return (where == WHERE_AFTER) || (where == WHERE_END);
+}
+
+/*
+ * Return the length of the string not including any final
+ * punctuation. E.g., the input "Signed-off-by:" would return
+ * 13, stripping the trailing punctuation but retaining
+ * internal punctuation.
+ */
+static size_t token_len_without_separator(const char *token, size_t len)
+{
+	while (len > 0 && !isalnum(token[len - 1]))
+		len--;
+	return len;
+}
+
+static int same_token(struct trailer_item *a, struct trailer_item *b)
+{
+	size_t a_len = token_len_without_separator(a->token, strlen(a->token));
+	size_t b_len = token_len_without_separator(b->token, strlen(b->token));
+	size_t min_len = (a_len > b_len) ? b_len : a_len;
+
+	return !strncasecmp(a->token, b->token, min_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)
+{
+	return same_token(a, b) && same_value(a, b);
+}
-- 
2.1.0.rc0.248.gb91fdbc
Previous: Christian CouderNext: Christian Couder
Message 2 of 12 in “Add interpret-trailers builtin”
  1. 00/11 Add interpret-trailers builtinChristian Couder, Oct 13, 2014
  2. 01/11 trailer: add data structures and basic functionsChristian Couder, Oct 13, 2014
  3. 02/11 trailer: process trailers from input message and argumentsChristian Couder, Oct 13, 2014
  4. 03/11 trailer: read and process config informationChristian Couder, Oct 13, 2014
  5. 04/11 trailer: process command line trailer argumentsChristian Couder, Oct 13, 2014
  6. 05/11 trailer: parse trailers from file or stdinChristian Couder, Oct 13, 2014
  7. 06/11 trailer: put all the processing together and printChristian Couder, Oct 13, 2014
  8. 07/11 trailer: add interpret-trailers commandChristian Couder, Oct 13, 2014
  9. 08/11 trailer: add tests for "git interpret-trailers"Christian Couder, Oct 13, 2014
  10. 09/11 trailer: execute command from 'trailer.<name>.command'Christian Couder, Oct 13, 2014
  11. 10/11 trailer: add tests for commands in config fileChristian Couder, Oct 13, 2014
  12. 11/11 Documentation: add documentation for 'git interpret-trailers'Christian Couder, Oct 13, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.