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

[PATCH 2/4] Introduce optional "keywords" on tag objects

From
Johan Herland <johan@herland.net>
Date
Jun 10, 2007, 11:50 UTC
Message-ID
<200706101350.00271.johan@herland.net>
In-Reply-To
<200706101347.57023.johan@herland.net>

This patch introduces a new optional header line to the tag object, called "keywords". The "keywords" line may contain a comma-separated list of custom keywords associated with the tag object. There are two "special" keywords, however: "tag" and "note": When the "keywords" header is missing, its default value is set to "tag" if a "tag" header is present; else the default "keywords" value is set to "note". The "keywords" header is meant to be used by porcelains for classifying different types of tag objects. This classification may then be used to filter tag objects in the presentation layer (e.g. by implementing extra filter options to --decorate, etc.).

The encoding rules for keywords are identical to those of tag names.
Signed-off-by: Johan Herland <johan@herland.net>
---
 mktag.c |   30 ++++++++++++++++++++++++++----
 tag.c   |   30 +++++++++++++++++++++++++-----
 tag.h   |    1 +
 3 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/mktag.c b/mktag.c
index 5e80d3d..37e10c6 100644
--- a/mktag.c
+++ b/mktag.c
@@ -2,9 +2,10 @@
 #include "tag.h"
 
 /*
- * A signature file has a very simple format: 3-4 lines
+ * A signature file has a very simple format: 3-5 lines
  * of "object <sha1>" + "type <typename>" + "tag <tagname>" (optional) +
- * "tagger <committer>", followed by a blank line, a free-form tag
+ * "keywords <keywords>" (optional) + "tagger <committer>",
+ * followed by a blank line, a free-form tag
  * message and a signature block that git itself doesn't care about,
  * but that can be verified with gpg or similar.
  *
@@ -49,7 +50,7 @@ static int verify_tag(char *buffer, unsigned long size)
 	int typelen;
 	char type[20];
 	unsigned char sha1[20];
-	const char *object, *type_line, *tag_line, *tagger_line;
+	const char *object, *type_line, *tag_line, *keywords_line, *tagger_line;
 
 	if (size < 58)
 		return error("wanna fool me ? you obviously got the size wrong !");
@@ -104,8 +105,29 @@ static int verify_tag(char *buffer, unsigned long size)
 		}
 	}
 
+	/* Verify the keywords: disallow ctrl chars, spaces and double commas */
+	keywords_line = tag_line;
+
+	if (!memcmp(tag_line, "keywords ", 9)) {
+		if (tag_line[9] == '\n')
+			return error("char" PD_FMT ": no \"keywords \" found",
+					keywords_line - buffer);
+		keywords_line += 9;
+		for (;;) {
+			unsigned char c = *keywords_line++;
+			if (c == '\n')
+				break;
+			if (c == ',' && *keywords_line == ',')
+				/* double commas. fall through to error() */;
+			else if (c > ' ')
+				continue;
+			return error("char" PD_FMT ": could not verify keywords",
+					keywords_line - buffer);
+		}
+	}
+
 	/* Verify the tagger line */
-	tagger_line = tag_line;
+	tagger_line = keywords_line;
 
 	if (memcmp(tagger_line, "tagger", 6) || (tagger_line[6] == '\n'))
 		return error("char" PD_FMT ": could not find \"tagger\"", tagger_line - buffer);
diff --git a/tag.c b/tag.c
index a7a3454..b74f09f 100644
--- a/tag.c
+++ b/tag.c
@@ -35,9 +35,9 @@ struct tag *lookup_tag(const unsigned char *sha1)
 
 int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
 {
-	int typelen, taglen;
+	int typelen, taglen, keywordslen;
 	unsigned char sha1[20];
-	const char *type_line, *tag_line, *sig_line;
+	const char *type_line, *tag_line, *keywords_line, *sig_line;
 	char type[20];
 
         if (item->object.parsed)
@@ -58,25 +58,45 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
 		return -1;
 
 	if (!memcmp("tag ", ++tag_line, 4)) {
-		sig_line = strchr(tag_line, '\n');
+		keywords_line = strchr(tag_line, '\n');
+		if (!keywords_line)
+			return -1;
+		keywords_line++;
+	}
+	else
+		keywords_line = tag_line;
+
+	if (!memcmp("keywords ", keywords_line, 9)) {
+		sig_line = strchr(keywords_line, '\n');
 		if (!sig_line)
 			return -1;
 		sig_line++;
 	}
 	else
-		sig_line = tag_line;
+		sig_line = keywords_line;
 
 	typelen = tag_line - type_line - strlen("type \n");
 	if (typelen >= 20)
 		return -1;
 	memcpy(type, type_line + 5, typelen);
 	type[typelen] = '\0';
-	taglen = sig_line - tag_line - strlen("tag \n");
+	taglen = keywords_line - tag_line - strlen("tag \n");
 	if (taglen < 0) /* missing tag name */
 		taglen = 0;
 	item->tag = xmalloc(taglen + 1);
 	memcpy(item->tag, tag_line + 4, taglen);
 	item->tag[taglen] = '\0';
+	keywordslen = sig_line - keywords_line - strlen("keywords \n");
+	if (keywordslen > 0)
+		keywords_line += strlen("keywords ");
+	else { /* missing keywords */
+		if (taglen) /* tag name given */
+			keywords_line = "tag";
+		else
+			keywords_line = "note";
+		keywordslen = strlen(keywords_line);
+	}
+	item->keywords = xstrndup(keywords_line, keywordslen);
 
 	if (!strcmp(type, blob_type)) {
 		item->tagged = &lookup_blob(sha1)->object;
diff --git a/tag.h b/tag.h
index 7e0abbe..6e687b2 100644
--- a/tag.h
+++ b/tag.h
@@ -9,6 +9,7 @@ struct tag {
 	struct object object;
 	struct object *tagged;
 	char *tag;       /* optional, may be empty ("") */
+	char *keywords;  /* optional, defaults to (tag ? "tag" : "note") */
 	char *signature; /* not actually implemented */
 };
 
-- 
1.5.2.1.144.gabc40
Previous: Junio C HamanoNext: Johannes Schindelin
Message 27 of 90 in “error: char103: premature end of data”
  1. Johannes SchindelinJun 7, 2007
  2. Johan HerlandJun 7, 2007
  3. Johannes SchindelinJun 7, 2007
  4. Johan HerlandJun 7, 2007
  5. Johannes SchindelinJun 7, 2007
  6. Fix failed tag parsing when tag object has no body/message (and thus ends with a single '\n')Johan Herland, Jun 8, 2007
  7. Junio C HamanoJun 8, 2007
  8. Johan HerlandJun 8, 2007
  9. Junio C HamanoJun 8, 2007
  10. 0/21 Refactor the tag object (take 2)Johan Herland, Jun 9, 2007
  11. 01/21 Remove unnecessary code and comments on non-existing 8kB tag object restrictionJohan Herland, Jun 9, 2007
  12. 02/21 Return error messages when parsing fails.Johan Herland, Jun 9, 2007
  13. Junio C HamanoJun 9, 2007
  14. Johan HerlandJun 9, 2007
  15. Silence error messages unless 'thorough_verify' is setJohan Herland, Jun 9, 2007
  16. Johannes SchindelinJun 10, 2007
  17. Junio C HamanoJun 10, 2007
  18. Johannes SchindelinJun 10, 2007
  19. Johan HerlandJun 10, 2007
  20. Johannes SchindelinJun 10, 2007
  21. Johan HerlandJun 10, 2007
  22. 0/4 Restructure the tag objectJohan Herland, Jun 10, 2007
  23. 1/4 Make tag names (i.e. the tag object's "tag" line) optionalJohan Herland, Jun 10, 2007
  24. Junio C HamanoJun 10, 2007
  25. Johan HerlandJun 10, 2007
  26. Junio C HamanoJun 11, 2007
  27. 2/4 Introduce optional "keywords" on tag objectsJohan Herland, Jun 10, 2007
  28. Johannes SchindelinJun 10, 2007
  29. Johan HerlandJun 10, 2007
  30. Junio C HamanoJun 10, 2007
  31. Johan HerlandJun 10, 2007
  32. Junio C HamanoJun 11, 2007
  33. 3/4 Documentation/git-mktag: Document the changes in tag object structureJohan Herland, Jun 10, 2007
  34. 4/4 git-mktag tests: Expand on mktag selftests according to the new tag object structureJohan Herland, Jun 10, 2007
  35. Johannes SchindelinJun 10, 2007
  36. 03/21 Refactoring to make verify_tag() and parse_tag_buffer() more similarJohan Herland, Jun 9, 2007
  37. Johannes SchindelinJun 9, 2007
  38. Johan HerlandJun 9, 2007
  39. 04/21 Refactor verification of "tagger" line to be more similar to verification of "type" and "tagger" linesJohan Herland, Jun 9, 2007
  40. Junio C HamanoJun 9, 2007
  41. Johannes SchindelinJun 10, 2007
  42. 05/21 Make parse_tag_buffer_internal() handle item == NULLJohan Herland, Jun 9, 2007
  43. Junio C HamanoJun 9, 2007
  44. Move check for already parsed tag object to parse_tag_buffer() wrapper functionJohan Herland, Jun 10, 2007
  45. Johannes SchindelinJun 10, 2007
  46. 06/21 Refactor tag name verification loop to use index 'i' instead of incrementing pointer 'tag_line'Johan Herland, Jun 9, 2007
  47. Alex RiesenJun 9, 2007
  48. Johan HerlandJun 9, 2007
  49. Johannes SchindelinJun 10, 2007
  50. Johannes SchindelinJun 10, 2007
  51. 07/21 Copy the remaining differences from verify_tag() to parse_tag_buffer_internal()Johan Herland, Jun 9, 2007
  52. Alex RiesenJun 9, 2007
  53. Johan HerlandJun 9, 2007
  54. Johannes SchindelinJun 10, 2007
  55. 08/21 Switch from verify_tag() to parse_and_verify_tag_buffer() for verifying tag objects in git-mktagJohan Herland, Jun 9, 2007
  56. 09/21 Remove unneeded code from mktag.cJohan Herland, Jun 9, 2007
  57. Alex RiesenJun 9, 2007
  58. Johan HerlandJun 9, 2007
  59. 10/21 Free mktag's buffer before dyingJohan Herland, Jun 9, 2007
  60. Alex RiesenJun 9, 2007
  61. Johan HerlandJun 9, 2007
  62. Alex RiesenJun 9, 2007
  63. Johan HerlandJun 9, 2007
  64. Johannes SchindelinJun 10, 2007
  65. 11/21 Rewrite error messages; fix up line lengthsJohan Herland, Jun 9, 2007
  66. Johannes SchindelinJun 10, 2007
  67. 12/21 Use prefixcmp() instead of memcmp() for cleaner code with less magic numbersJohan Herland, Jun 9, 2007
  68. Alex RiesenJun 9, 2007
  69. Johan HerlandJun 9, 2007
  70. Johannes SchindelinJun 10, 2007
  71. 13/21 Collect skipping of header field names and calculation of line lengths in one placeJohan Herland, Jun 9, 2007
  72. Johannes SchindelinJun 10, 2007
  73. 14/21 Add proper parsing of "tagger" line, but only when thorough_verify is setJohan Herland, Jun 9, 2007
  74. Johannes SchindelinJun 10, 2007
  75. Johannes SchindelinJun 10, 2007
  76. 15/21 Make tag names (i.e. the tag object's "tag" line) optionalJohan Herland, Jun 9, 2007
  77. Johannes SchindelinJun 10, 2007
  78. 16/21 Introduce optional "keywords" on tag objectsJohan Herland, Jun 9, 2007
  79. Alex RiesenJun 9, 2007
  80. Johan HerlandJun 9, 2007
  81. Use xstrndup() instead of xmalloc() and memcpy(); fix buglet with generating default item->keywords.Johan Herland, Jun 9, 2007
  82. Junio C HamanoJun 10, 2007
  83. Fail if tag name and keywords is not within "printable ASCII"Johan Herland, Jun 10, 2007
  84. Junio C HamanoJun 10, 2007
  85. 17/21 Update comments on tag objects in mktag.cJohan Herland, Jun 9, 2007
  86. 18/21 git-fsck: Do thorough verification of tag objectsJohan Herland, Jun 9, 2007
  87. 19/21 Documentation/git-mktag: Document the changes in tag object structureJohan Herland, Jun 9, 2007
  88. 20/21 git-mktag tests: Expand on mktag selftests according to the new tag object structureJohan Herland, Jun 9, 2007
  89. 21/21 Add fsck_verify_ref_to_tag_object() to verify that refname matches name stored in tag objectJohan Herland, Jun 9, 2007
  90. Johannes SchindelinJun 7, 2007

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.