From: Thomas Gummerer <t.gummerer@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Jaime Soriano Pastor" <jsorianopastor@gmail.com>,
"Thomas Gummerer" <t.gummerer@gmail.com>
Subject: [PATCH 2/2] read-cache: fix reading of split index
Date: Fri, 20 Mar 2015 22:43:14 +0100 [thread overview]
Message-ID: <1426887794-9655-3-git-send-email-t.gummerer@gmail.com> (raw)
In-Reply-To: <1426887794-9655-1-git-send-email-t.gummerer@gmail.com>
The split index extension uses ewah bitmaps to mark index entries as
deleted, instead of removing them from the index directly. This can
result in an on-disk index, in which entries of stage #0 and higher
stages appear, which are removed later when the index bases are merged.
15999d0 read_index_from(): catch out of order entries when reading an
index file introduces a check which checks if the entries are in order
after each index entry is read in do_read_index. This check may however
fail when a split index is read.
Fix this by moving checking the index after we know there is no split
index or after the split index bases are successfully merged instead.
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
read-cache.c | 42 +++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 8d71860..1bf78a4 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1486,18 +1486,25 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
return ce;
}
-static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce)
-{
- 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))
- 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);
+static void check_ce_order(struct index_state *istate)
+{
+ 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);
+
+ if (0 < name_compare)
+ die("unordered stage entries in index");
+ if (!name_compare) {
+ if (!ce_stage(ce))
+ 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);
+ }
}
}
@@ -1562,9 +1569,6 @@ 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)
- check_ce_order(istate->cache[i - 1], ce);
-
src_offset += consumed;
}
strbuf_release(&previous_name_buf);
@@ -1608,11 +1612,10 @@ int read_index_from(struct index_state *istate, const char *path)
ret = do_read_index(istate, path, 0);
split_index = istate->split_index;
- if (!split_index)
- return ret;
-
- if (is_null_sha1(split_index->base_sha1))
+ if (!split_index || is_null_sha1(split_index->base_sha1)) {
+ check_ce_order(istate);
return ret;
+ }
if (split_index->base)
discard_index(split_index->base);
@@ -1628,6 +1631,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);
return ret;
}
--
2.1.0.264.g0463184.dirty
next prev parent reply other threads:[~2015-03-20 21:43 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 ` Thomas Gummerer [this message]
2015-03-24 13:02 ` [PATCH 2/2] read-cache: fix reading of split index Duy Nguyen
2015-03-24 17:00 ` [PATCH] read-cache: tighten checks for do_read_index Thomas Gummerer
2015-03-24 21:33 ` 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=1426887794-9655-3-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).