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

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

From
Christian Couder <chriscool@tuxfamily.org>
Date
Apr 25, 2014, 19:06 UTC
Message-ID
<20140425190703.28550.29908.chriscool@tuxfamily.org>
In-Reply-To
<20140425185719.28550.27059.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 | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 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 0000000..db93a63
--- /dev/null
+++ b/trailer.c
@@ -0,0 +1,49 @@
+#include "cache.h"
+/*
+ * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>
+ */
+
+enum action_where { WHERE_AFTER, WHERE_BEFORE };
+enum action_if_exists { EXISTS_ADD_IF_DIFFERENT, EXISTS_ADD_IF_DIFFERENT_NEIGHBOR,
+			EXISTS_ADD, EXISTS_OVERWRITE, 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;
+};
+
+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 - 1]))
+		len--;
+	return len;
+}
-- 
1.9.1.636.g20d5f34
Previous: Christian CouderNext: Christian Couder
Message 2 of 13 in “Add interpret-trailers builtin”
  1. 00/11 Add interpret-trailers builtinChristian Couder, Apr 25, 2014
  2. 01/11 trailer: add data structures and basic functionsChristian Couder, Apr 25, 2014
  3. 02/11 trailer: process trailers from input message and argumentsChristian Couder, Apr 25, 2014
  4. 03/11 trailer: read and process config informationChristian Couder, Apr 25, 2014
  5. 04/11 trailer: process command line trailer argumentsChristian Couder, Apr 25, 2014
  6. 05/11 trailer: parse trailers from file or stdinChristian Couder, Apr 25, 2014
  7. 06/11 trailer: put all the processing together and printChristian Couder, Apr 25, 2014
  8. 07/11 trailer: add interpret-trailers commandChristian Couder, Apr 25, 2014
  9. 08/11 trailer: add tests for "git interpret-trailers"Christian Couder, Apr 25, 2014
  10. 09/11 trailer: execute command from 'trailer.<name>.command'Christian Couder, Apr 25, 2014
  11. 10/11 trailer: add tests for commands in config fileChristian Couder, Apr 25, 2014
  12. 11/11 Documentation: add documentation for 'git interpret-trailers'Christian Couder, Apr 25, 2014
  13. Junio C HamanoApr 29, 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.