From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 9/9] read-cache.c: write index v4 format
Date: Tue, 3 Apr 2012 15:53:16 -0700 [thread overview]
Message-ID: <1333493596-14202-10-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1333493596-14202-1-git-send-email-gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/update-index.c | 2 ++
cache.h | 4 ++++
config.c | 11 ++++++++++
environment.c | 1 +
read-cache.c | 56 ++++++++++++++++++++++++++++++++++++++++--------
5 files changed, 65 insertions(+), 9 deletions(-)
diff --git a/builtin/update-index.c b/builtin/update-index.c
index a6a23fa..b663f45 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -791,6 +791,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
"(for porcelains) forget saved unresolved conflicts",
PARSE_OPT_NOARG | PARSE_OPT_NONEG,
resolve_undo_clear_callback},
+ OPT_INTEGER(0, "index-format", &preferred_index_format,
+ "write index in this format"),
OPT_END()
};
diff --git a/cache.h b/cache.h
index 65a7aba..bdec32c 100644
--- a/cache.h
+++ b/cache.h
@@ -105,6 +105,9 @@ struct cache_header {
unsigned int hdr_entries;
};
+#define SUPPORTED_INDEX_FORMAT_LB 2
+#define SUPPORTED_INDEX_FORMAT_UB 4
+
/*
* The "cache_time" is just the low 32 bits of the
* time. It doesn't matter if it overflows - we only
@@ -537,6 +540,7 @@ extern int has_symlinks;
extern int minimum_abbrev, default_abbrev;
extern int ignore_case;
extern int assume_unchanged;
+extern int preferred_index_format;
extern int prefer_symlink_refs;
extern int log_all_ref_updates;
extern int warn_ambiguous_refs;
diff --git a/config.c b/config.c
index 68d3294..0244a85 100644
--- a/config.c
+++ b/config.c
@@ -564,6 +564,17 @@ static int git_default_core_config(const char *var, const char *value)
return 0;
}
+ if (!strcmp(var, "core.indexformat")) {
+ int val = git_config_int(var, value);
+ if (val < SUPPORTED_INDEX_FORMAT_LB ||
+ SUPPORTED_INDEX_FORMAT_UB < val)
+ return error("%s not in supported range: %d..%d",
+ var, SUPPORTED_INDEX_FORMAT_LB,
+ SUPPORTED_INDEX_FORMAT_UB);
+ preferred_index_format = val;
+ return 0;
+ }
+
if (!strcmp(var, "core.quotepath")) {
quote_path_fully = git_config_bool(var, value);
return 0;
diff --git a/environment.c b/environment.c
index c93b8f4..4ecf8e6 100644
--- a/environment.c
+++ b/environment.c
@@ -20,6 +20,7 @@ int has_symlinks = 1;
int minimum_abbrev = 4, default_abbrev = 7;
int ignore_case;
int assume_unchanged;
+int preferred_index_format;
int prefer_symlink_refs;
int is_bare_repository_cfg = -1; /* unspecified */
int log_all_ref_updates = -1; /* unspecified */
diff --git a/read-cache.c b/read-cache.c
index 1c173f7..fdac89a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1676,15 +1676,45 @@ static char *copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,
}
}
-static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
+static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce,
+ struct strbuf *previous_name)
{
- int size = ondisk_ce_size(ce);
- struct ondisk_cache_entry *ondisk = xcalloc(1, size);
+ int size;
+ struct ondisk_cache_entry *ondisk;
char *name;
int result;
- name = copy_cache_entry_to_ondisk(ondisk, ce);
- memcpy(name, ce->name, ce_namelen(ce));
+ if (!previous_name) {
+ size = ondisk_ce_size(ce);
+ ondisk = xcalloc(1, size);
+ name = copy_cache_entry_to_ondisk(ondisk, ce);
+ memcpy(name, ce->name, ce_namelen(ce));
+ } else {
+ int common, to_remove, prefix_size;
+ unsigned char to_remove_vi[16];
+ for (common = 0;
+ (ce->name[common] &&
+ common < previous_name->len &&
+ ce->name[common] == previous_name->buf[common]);
+ common++)
+ ; /* still matching */
+ to_remove = previous_name->len - common;
+ prefix_size = encode_varint(to_remove, to_remove_vi);
+
+ if (ce->ce_flags & CE_EXTENDED)
+ size = offsetof(struct ondisk_cache_entry_extended, name);
+ else
+ size = offsetof(struct ondisk_cache_entry, name);
+ size += prefix_size + (ce_namelen(ce) - common + 1);
+
+ ondisk = xcalloc(1, size);
+ name = copy_cache_entry_to_ondisk(ondisk, ce);
+ memcpy(name, to_remove_vi, prefix_size);
+ memcpy(name + prefix_size, ce->name + common, ce_namelen(ce) - common);
+
+ strbuf_splice(previous_name, common, to_remove,
+ ce->name + common, ce_namelen(ce) - common);
+ }
result = ce_write(c, fd, ondisk, size);
free(ondisk);
@@ -1720,10 +1750,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, err, removed, extended, hdr_version;
struct cache_entry **cache = istate->cache;
int entries = istate->cache_nr;
struct stat st;
+ struct strbuf previous_name_buf = STRBUF_INIT, *previous_name;
for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
@@ -1737,24 +1768,31 @@ int write_index(struct index_state *istate, int newfd)
}
}
+ if (preferred_index_format)
+ hdr_version = preferred_index_format;
+ else
+ hdr_version = extended ? 3 : 2;
+
+
hdr.hdr_signature = htonl(CACHE_SIGNATURE);
- /* for extended format, increase version so older git won't try to read it */
- hdr.hdr_version = htonl(extended ? 3 : 2);
+ hdr.hdr_version = htonl(hdr_version);
hdr.hdr_entries = htonl(entries - removed);
git_SHA1_Init(&c);
if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
return -1;
+ previous_name = (hdr_version == 4) ? &previous_name_buf : NULL;
for (i = 0; i < entries; i++) {
struct cache_entry *ce = cache[i];
if (ce->ce_flags & CE_REMOVE)
continue;
if (!ce_uptodate(ce) && is_racy_timestamp(istate, ce))
ce_smudge_racily_clean_entry(ce);
- if (ce_write_entry(&c, newfd, ce) < 0)
+ if (ce_write_entry(&c, newfd, ce, previous_name) < 0)
return -1;
}
+ strbuf_release(&previous_name_buf);
/* Write extension data here */
if (istate->cache_tree) {
--
1.7.10.rc4.54.g1d5dd3
next prev parent reply other threads:[~2012-04-03 22:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-03 22:53 [PATCH 0/9] Prefix-compress on-disk index entries Junio C Hamano
2012-04-03 22:53 ` [PATCH 1/9] varint: make it available outside the context of pack Junio C Hamano
2012-04-03 22:53 ` [PATCH 2/9] cache.h: hide on-disk index details Junio C Hamano
2012-04-03 22:53 ` [PATCH 3/9] read-cache.c: allow unaligned mapping of the index file Junio C Hamano
2012-04-03 22:53 ` [PATCH 4/9] read-cache.c: make create_from_disk() report number of bytes it consumed Junio C Hamano
2012-04-03 22:53 ` [PATCH 5/9] read-cache.c: report the header version we do not understand Junio C Hamano
2012-04-03 22:53 ` [PATCH 6/9] read-cache.c: move code to copy ondisk to incore cache to a helper function Junio C Hamano
2012-04-03 22:53 ` [PATCH 7/9] read-cache.c: move code to copy incore to ondisk " Junio C Hamano
2012-04-03 22:53 ` [PATCH 8/9] read-cache.c: read prefix-compressed names in index on-disk version v4 Junio C Hamano
2012-04-03 22:53 ` Junio C Hamano [this message]
2012-04-04 1:44 ` [PATCH 0/9] Prefix-compress on-disk index entries David Barr
2012-04-04 15:33 ` Junio C Hamano
2012-04-04 16:57 ` Junio C Hamano
2012-04-04 16:58 ` [PATCH 2/2] update-index: upgrade/downgrade on-disk index version Junio C Hamano
2012-04-04 12:34 ` [PATCH 0/9] Prefix-compress on-disk index entries Nguyen Thai Ngoc Duy
2012-04-04 18:44 ` Junio C Hamano
2012-04-06 8:41 ` David Barr
2012-05-02 1:58 ` Nguyen Thai Ngoc Duy
2012-05-02 4:26 ` David Barr
2012-04-27 22:58 ` [PATCH 1/2] unpack-trees: preserve the index file version of original Junio C Hamano
2012-04-27 23:02 ` [PATCH 2/2] index-v4: document the entry format Junio C Hamano
2012-04-30 17:20 ` Thomas Rast
2012-05-01 4:00 ` Junio C Hamano
2012-05-01 21:43 ` Thomas Rast
2012-05-02 15:12 ` Shawn Pearce
2012-05-02 17:04 ` Junio C Hamano
2012-05-02 17:13 ` Shawn Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1333493596-14202-10-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).