From: Thomas Gummerer <t.gummerer@gmail.com>
To: git@vger.kernel.org
Cc: Duy Nguyen <pclouds@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Jaime Soriano Pastor <jsorianopastor@gmail.com>,
Thomas Gummerer <t.gummerer@gmail.com>
Subject: [PATCH] read-cache: tighten checks for do_read_index
Date: Tue, 24 Mar 2015 18:00:29 +0100 [thread overview]
Message-ID: <1427216429-15569-1-git-send-email-t.gummerer@gmail.com> (raw)
In-Reply-To: <CACsJy8CYi+hYu8zwOy=m7zZk3-8fr+Jq9uT4kEf8fLCOcjHJzw@mail.gmail.com>
03f15a7 read-cache: fix reading of split index moved the checks for the
correct order of index entries out of do_read_index. This loosens the
checks more than necessary. Re-introduce the checks for the order, but
don't error out when we have multiple stage-0 entries in the index.
Return a flag for the caller instead, if we have multiple stage-0
entries and let the caller decide if we need to error out.
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
This is a patch on top of my previous patch, as that one has already
been merged to next.
cache.h | 2 +-
read-cache.c | 54 ++++++++++++++++++++++++++++++++-----------------
test-dump-split-index.c | 2 +-
3 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/cache.h b/cache.h
index e7b24a2..3eaa258 100644
--- a/cache.h
+++ b/cache.h
@@ -487,7 +487,7 @@ struct lock_file;
extern int read_index(struct index_state *);
extern int read_index_preload(struct index_state *, const struct pathspec *pathspec);
extern int do_read_index(struct index_state *istate, const char *path,
- int must_exist); /* for testting only! */
+ int must_exist, int *multiple_stage_entries); /* for testting only! */
extern int read_index_from(struct index_state *, const char *path);
extern int is_index_unborn(struct index_state *);
extern int read_index_unmerged(struct index_state *);
diff --git a/read-cache.c b/read-cache.c
index 36ff89f..2ba67ce 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1488,30 +1488,39 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
return ce;
}
-static void check_ce_order(struct index_state *istate)
+static int check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce,
+ int gentle_multiple_stage)
{
- unsigned int i;
-
- for (i = 1; i < istate->cache_nr; i++) {
- struct cache_entry *ce = istate->cache[i - 1];
- struct cache_entry *next_ce = istate->cache[i];
- int name_compare = strcmp(ce->name, next_ce->name);
+ int name_compare = strcmp(ce->name, next_ce->name);
- if (0 < name_compare)
- die("unordered stage entries in index");
- if (!name_compare) {
- if (!ce_stage(ce))
+ if (0 < name_compare)
+ die("unordered stage entries in index");
+ if (!name_compare) {
+ if (!ce_stage(ce)) {
+ if (gentle_multiple_stage)
+ return 1;
+ else
die("multiple stage entries for merged file '%s'",
ce->name);
- if (ce_stage(ce) > ce_stage(next_ce))
- die("unordered stage entries for '%s'",
- ce->name);
}
+ if (ce_stage(ce) > ce_stage(next_ce))
+ die("unordered stage entries for '%s'",
+ ce->name);
}
+ return 0;
+}
+
+static void check_istate_order(struct index_state *istate)
+{
+ unsigned int i;
+
+ for (i = 1; i < istate->cache_nr; i++)
+ check_ce_order(istate->cache[i - 1], istate->cache[i], 0);
}
/* remember to discard_cache() before reading a different cache! */
-int do_read_index(struct index_state *istate, const char *path, int must_exist)
+int do_read_index(struct index_state *istate, const char *path, int must_exist,
+ int *multiple_stage_entries)
{
int fd, i;
struct stat st;
@@ -1571,6 +1580,11 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
ce = create_from_disk(disk_ce, &consumed, previous_name);
set_index_entry(istate, i, ce);
+ if (i > 0)
+ if (check_ce_order(istate->cache[i - 1], ce, 1) > 0 &&
+ multiple_stage_entries)
+ *multiple_stage_entries |= 1;
+
src_offset += consumed;
}
strbuf_release(&previous_name_buf);
@@ -1607,15 +1621,17 @@ int read_index_from(struct index_state *istate, const char *path)
{
struct split_index *split_index;
int ret;
+ int multiple_stage_entries = 0;
/* istate->initialized covers both .git/index and .git/sharedindex.xxx */
if (istate->initialized)
return istate->cache_nr;
- ret = do_read_index(istate, path, 0);
+ ret = do_read_index(istate, path, 0, &multiple_stage_entries);
split_index = istate->split_index;
if (!split_index || is_null_sha1(split_index->base_sha1)) {
- check_ce_order(istate);
+ if (multiple_stage_entries)
+ check_istate_order(istate);
return ret;
}
@@ -1625,7 +1641,7 @@ int read_index_from(struct index_state *istate, const char *path)
split_index->base = xcalloc(1, sizeof(*split_index->base));
ret = do_read_index(split_index->base,
git_path("sharedindex.%s",
- sha1_to_hex(split_index->base_sha1)), 1);
+ sha1_to_hex(split_index->base_sha1)), 1, NULL);
if (hashcmp(split_index->base_sha1, split_index->base->sha1))
die("broken index, expect %s in %s, got %s",
sha1_to_hex(split_index->base_sha1),
@@ -1633,7 +1649,7 @@ int read_index_from(struct index_state *istate, const char *path)
sha1_to_hex(split_index->base_sha1)),
sha1_to_hex(split_index->base->sha1));
merge_base_index(istate);
- check_ce_order(istate);
+ check_istate_order(istate);
return ret;
}
diff --git a/test-dump-split-index.c b/test-dump-split-index.c
index 9cf3112..fc9ced7 100644
--- a/test-dump-split-index.c
+++ b/test-dump-split-index.c
@@ -12,7 +12,7 @@ int main(int ac, char **av)
struct split_index *si;
int i;
- do_read_index(&the_index, av[1], 1);
+ do_read_index(&the_index, av[1], 1, NULL);
printf("own %s\n", sha1_to_hex(the_index.sha1));
si = the_index.split_index;
if (!si) {
--
2.1.0.264.g0463184.dirty
next prev parent reply other threads:[~2015-03-24 17:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-20 15:09 [PATCH] t1700: make test pass with index-v4 Thomas Gummerer
2015-03-20 17:23 ` Junio C Hamano
2015-03-20 17:37 ` Thomas Gummerer
2015-03-20 18:06 ` Junio C Hamano
2015-03-20 18:20 ` [PATCH v2] " Thomas Gummerer
2015-03-20 19:38 ` Junio C Hamano
2015-03-20 19:59 ` Thomas Gummerer
2015-03-20 21:43 ` [PATCH 0/2] fix test suite with split index Thomas Gummerer
2015-03-20 21:43 ` [PATCH 1/2] test-lib: allow using split index in the test suite Thomas Gummerer
2015-03-20 21:55 ` Junio C Hamano
2015-03-20 22:12 ` Thomas Gummerer
2015-03-20 21:43 ` [PATCH 2/2] read-cache: fix reading of split index Thomas Gummerer
2015-03-24 13:02 ` Duy Nguyen
2015-03-24 17:00 ` Thomas Gummerer [this message]
2015-03-24 21:33 ` [PATCH] read-cache: tighten checks for do_read_index Junio C Hamano
2015-03-24 21:51 ` Thomas Gummerer
2015-03-24 17:07 ` [PATCH 2/2] read-cache: fix reading of split index Thomas Gummerer
2015-03-24 17:19 ` Junio C Hamano
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=1427216429-15569-1-git-send-email-t.gummerer@gmail.com \
--to=t.gummerer@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jsorianopastor@gmail.com \
--cc=pclouds@gmail.com \
/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).