The index can now store and retrieve the ce_norm_sha1 data. Signed-off-by: Henrik Grubbström <grubba@xxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html