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

[PATCH RFC 3/5] cache: Added index extension "NORM".

From
Henrik Grubbström (Grubba) <grubba@grubba.org>
Date
Apr 16, 2010, 16:10 UTC
Message-ID
<ced9c9c5e0a40223f71b64187e9049d3d367f66c.1271432034.git.grubba@grubba.org>
In-Reply-To
<cover.1271432034.git.grubba@grubba.org>
The index can now store and retrieve the ce_norm_sha1 data.
Signed-off-by: Henrik Grubbström <grubba@grubba.org>
---
 cache.h      |    7 +++++++
 read-cache.c |   49 +++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/cache.h b/cache.h
index 536697d..0cb3110 100644
--- a/cache.h
+++ b/cache.h
@@ -157,6 +157,13 @@ struct cache_entry {
 	char name[FLEX_ARRAY]; /* more */
 };
 
+struct ondisk_norm_sha1 {
+	unsigned int entry_no;
+	unsigned int norm_flags;
+	unsigned int norm_size;
+	unsigned char norm_sha1[20];
+};
+
 #define NORM_CONV_CRLF	0x0001
 #define NORM_CONV_GUESS	0x0002
 #define NORM_CONV_IDENT	0x0004
diff --git a/read-cache.c b/read-cache.c
index f1f789b..002160e 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -27,6 +27,7 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall
 #define CACHE_EXT(s) ( (s[0]<<24)|(s[1]<<16)|(s[2]<<8)|(s[3]) )
 #define CACHE_EXT_TREE 0x54524545	/* "TREE" */
 #define CACHE_EXT_RESOLVE_UNDO 0x52455543 /* "REUC" */
+#define CACHE_EXT_NORM_SHA1 0x4e4f524d	/* "NORM" */
 
 struct index_state the_index;
 
@@ -1178,6 +1179,21 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
 	return 0;
 }
 
+static int norm_sha1_read(struct cache_entry **cache, unsigned int entries,
+			  const struct ondisk_norm_sha1 *data, unsigned long sz)
+{
+	while (sz >= sizeof(*data)) {
+		unsigned int entry_no = ntohl(data->entry_no);
+		if (entry_no < entries) {
+			cache[entry_no]->norm_flags = ntohl(data->norm_flags);
+			memcpy(cache[entry_no]->norm_sha1, data->norm_sha1, 20);
+		}
+		sz -= sizeof(*data);
+		data++;
+	}
+	return 0;
+}
+
 static int read_index_extension(struct index_state *istate,
 				const char *ext, void *data, unsigned long sz)
 {
@@ -1188,6 +1204,9 @@ static int read_index_extension(struct index_state *istate,
 	case CACHE_EXT_RESOLVE_UNDO:
 		istate->resolve_undo = resolve_undo_read(data, sz);
 		break;
+	case CACHE_EXT_NORM_SHA1:
+		return norm_sha1_read(istate->cache, istate->cache_nr, data, sz);
+		break;
 	default:
 		if (*ext < 'A' || 'Z' < *ext)
 			return error("index uses %.4s extension, which we do not understand",
@@ -1511,6 +1530,16 @@ static void ce_smudge_racily_clean_entry(struct cache_entry *ce)
 	}
 }
 
+static void norm_sha1_write(struct strbuf *sb, const struct cache_entry *ce,
+			    int entry_no)
+{
+	struct ondisk_norm_sha1 entry;
+	entry.entry_no = htonl(entry_no);
+	entry.norm_flags = htonl(ce->norm_flags);
+	memcpy(entry.norm_sha1, ce->norm_sha1, 20);
+	strbuf_add(sb, &entry, sizeof(entry));
+}
+
 static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
 {
 	int size = ondisk_ce_size(ce);
@@ -1546,10 +1575,11 @@ int write_index(struct index_state *istate, int newfd)
 {
 	git_SHA_CTX c;
 	struct cache_header hdr;
-	int i, err, removed, extended;
+	int i, j, err, removed, extended;
 	struct cache_entry **cache = istate->cache;
 	int entries = istate->cache_nr;
 	struct stat st;
+	struct strbuf sb = STRBUF_INIT;
 
 	for (i = removed = extended = 0; i < entries; i++) {
 		if (cache[i]->ce_flags & CE_REMOVE)
@@ -1572,7 +1602,7 @@ int write_index(struct index_state *istate, int newfd)
 	if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
 		return -1;
 
-	for (i = 0; i < entries; i++) {
+	for (i = j = 0; i < entries; i++) {
 		struct cache_entry *ce = cache[i];
 		if (ce->ce_flags & CE_REMOVE)
 			continue;
@@ -1580,12 +1610,21 @@ int write_index(struct index_state *istate, int newfd)
 			ce_smudge_racily_clean_entry(ce);
 		if (ce_write_entry(&c, newfd, ce) < 0)
 			return -1;
+		if (ce->norm_flags)
+			norm_sha1_write(&sb, ce, j);
+		j++;
 	}
 
 	/* Write extension data here */
+	if (sb.len) {
+		err = write_index_ext_header(&c, newfd, CACHE_EXT_NORM_SHA1,
+					     sb.len) < 0
+			|| ce_write(&c, newfd, sb.buf, sb.len) < 0;
+		strbuf_release(&sb);
+		if (err)
+			return -1;
+	}
 	if (istate->cache_tree) {
-		struct strbuf sb = STRBUF_INIT;
-
 		cache_tree_write(&sb, istate->cache_tree);
 		err = write_index_ext_header(&c, newfd, CACHE_EXT_TREE, sb.len) < 0
 			|| ce_write(&c, newfd, sb.buf, sb.len) < 0;
@@ -1594,8 +1633,6 @@ int write_index(struct index_state *istate, int newfd)
 			return -1;
 	}
 	if (istate->resolve_undo) {
-		struct strbuf sb = STRBUF_INIT;
-
 		resolve_undo_write(&sb, istate->resolve_undo);
 		err = write_index_ext_header(&c, newfd, CACHE_EXT_RESOLVE_UNDO,
 					     sb.len) < 0
-- 
1.7.0.4.369.g81e89
Previous: Henrik Grubbström (Grubba)Next: Henrik Grubbström (Grubba)
Message 4 of 18 in “Patches to avoid reporting conversion changes.”
  1. 0/5 Patches to avoid reporting conversion changes.Henrik Grubbström (Grubba), Apr 16, 2010
  2. 1/5 sha1_file: Added index_blob().Henrik Grubbström (Grubba), Apr 16, 2010
  3. 2/5 cache: Added ce_norm_sha1() and related cache_entry fields.Henrik Grubbström (Grubba), Apr 16, 2010
  4. 3/5 cache: Added index extension "NORM".Henrik Grubbström (Grubba), Apr 16, 2010
  5. 4/5 reachable: Made the gc aware of the ce_norm_sha1.Henrik Grubbström (Grubba), Apr 16, 2010
  6. 5/5 cache: Use ce_norm_sha1().Henrik Grubbström (Grubba), Apr 16, 2010
  7. Junio C HamanoApr 20, 2010
  8. Henrik GrubbströmApr 20, 2010
  9. Junio C HamanoApr 20, 2010
  10. Henrik GrubbströmApr 25, 2010
  11. Jari AaltoApr 16, 2010
  12. Randal L. SchwartzApr 16, 2010
  13. Jari AaltoApr 17, 2010
  14. Randal L. SchwartzApr 17, 2010
  15. Sverre RabbelierApr 17, 2010
  16. Jakub NarebskiApr 17, 2010
  17. Sverre RabbelierApr 17, 2010
  18. Randal L. SchwartzApr 17, 2010

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.