From: Thomas Gummerer <t.gummerer@gmail.com> To: git@vger.kernel.org Cc: trast@inf.ethz.ch, mhagger@alum.mit.edu, gitster@pobox.com, pclouds@gmail.com, robin.rosenberg@dewire.com, t.gummerer@gmail.com Subject: [PATCH 06/22] make sure partially read index is not changed Date: Sun, 7 Jul 2013 10:11:44 +0200 Message-ID: <1373184720-29767-7-git-send-email-t.gummerer@gmail.com> (raw) In-Reply-To: <1373184720-29767-1-git-send-email-t.gummerer@gmail.com> A partially read index file currently cannot be written to disk. Make sure that never happens, by re-reading the index file if the index file wasn't read completely before changing the in-memory index. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> --- builtin/update-index.c | 4 ++++ cache.h | 4 +++- read-cache-v2.c | 3 +++ read-cache.c | 8 ++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 5c7762e..03f6426 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -49,6 +49,8 @@ static int mark_ce_flags(const char *path, int flag, int mark) int namelen = strlen(path); int pos = cache_name_pos(path, namelen); if (0 <= pos) { + if (active_cache_partially_read) + cache_change_filter_opts(NULL); if (mark) active_cache[pos]->ce_flags |= flag; else @@ -253,6 +255,8 @@ static void chmod_path(int flip, const char *path) pos = cache_name_pos(path, strlen(path)); if (pos < 0) goto fail; + if (active_cache_partially_read) + cache_change_filter_opts(NULL); ce = active_cache[pos]; mode = ce->ce_mode; if (!S_ISREG(mode)) diff --git a/cache.h b/cache.h index d38dfbd..f6c3407 100644 --- a/cache.h +++ b/cache.h @@ -293,7 +293,8 @@ struct index_state { struct cache_tree *cache_tree; struct cache_time timestamp; unsigned name_hash_initialized : 1, - initialized : 1; + initialized : 1, + partially_read : 1; struct hash_table name_hash; struct hash_table dir_hash; struct index_ops *ops; @@ -315,6 +316,7 @@ extern void free_name_hash(struct index_state *istate); #define active_alloc (the_index.cache_alloc) #define active_cache_changed (the_index.cache_changed) #define active_cache_tree (the_index.cache_tree) +#define active_cache_partially_read (the_index.partially_read) #define read_cache() read_index(&the_index) #define read_cache_from(path) read_index_from(&the_index, (path)) diff --git a/read-cache-v2.c b/read-cache-v2.c index 1ed640d..2cc792d 100644 --- a/read-cache-v2.c +++ b/read-cache-v2.c @@ -273,6 +273,7 @@ static int read_index_v2(struct index_state *istate, void *mmap, src_offset += 8; src_offset += extsize; } + istate->partially_read = 0; return 0; unmap: munmap(mmap, mmap_size); @@ -495,6 +496,8 @@ static int write_index_v2(struct index_state *istate, int newfd) struct stat st; struct strbuf previous_name_buf = STRBUF_INIT, *previous_name; + if (istate->partially_read) + die("BUG: index: cannot write a partially read index"); for (i = removed = extended = 0; i < entries; i++) { if (cache[i]->ce_flags & CE_REMOVE) removed++; diff --git a/read-cache.c b/read-cache.c index b30ee75..4529fab 100644 --- a/read-cache.c +++ b/read-cache.c @@ -30,6 +30,8 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache { struct cache_entry *old = istate->cache[nr]; + if (istate->partially_read) + index_change_filter_opts(istate, NULL); remove_name_hash(istate, old); set_index_entry(istate, nr, ce); istate->cache_changed = 1; @@ -467,6 +469,8 @@ int remove_index_entry_at(struct index_state *istate, int pos) { struct cache_entry *ce = istate->cache[pos]; + if (istate->partially_read) + index_change_filter_opts(istate, NULL); record_resolve_undo(istate, ce); remove_name_hash(istate, ce); istate->cache_changed = 1; @@ -978,6 +982,8 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti { int pos; + if (istate->partially_read) + index_change_filter_opts(istate, NULL); if (option & ADD_CACHE_JUST_APPEND) pos = istate->cache_nr; else { @@ -1184,6 +1190,8 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p /* If we are doing --really-refresh that * means the index is not valid anymore. */ + if (istate->partially_read) + index_change_filter_opts(istate, NULL); ce->ce_flags &= ~CE_VALID; istate->cache_changed = 1; } -- 1.8.3.453.g1dfc63d
next prev parent reply other threads:[~2013-07-07 8:13 UTC|newest] Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-07-07 8:11 [PATCH 00/22] Index v5 Thomas Gummerer 2013-07-07 8:11 ` [PATCH 01/22] t2104: Don't fail for index versions other than [23] Thomas Gummerer 2013-07-07 8:11 ` [PATCH 02/22] read-cache: split index file version specific functionality Thomas Gummerer 2013-07-07 8:11 ` [PATCH 03/22] read-cache: move index v2 specific functions to their own file Thomas Gummerer 2013-07-07 8:11 ` [PATCH 04/22] read-cache: Re-read index if index file changed Thomas Gummerer 2013-07-07 8:11 ` [PATCH 05/22] read-cache: add index reading api Thomas Gummerer 2013-07-08 2:01 ` Duy Nguyen 2013-07-08 11:40 ` Thomas Gummerer 2013-07-08 2:19 ` Duy Nguyen 2013-07-08 11:20 ` Thomas Gummerer 2013-07-08 12:45 ` Duy Nguyen 2013-07-08 13:37 ` Thomas Gummerer 2013-07-08 20:54 ` [PATCH 5.5/22] Add documentation for the index api Thomas Gummerer 2013-07-09 15:42 ` Duy Nguyen 2013-07-09 20:10 ` Thomas Gummerer 2013-07-10 5:28 ` Duy Nguyen 2013-07-11 11:30 ` Thomas Gummerer 2013-07-11 11:42 ` Duy Nguyen 2013-07-11 12:27 ` Duy Nguyen 2013-07-08 16:36 ` [PATCH 05/22] read-cache: add index reading api Junio C Hamano 2013-07-08 20:10 ` Thomas Gummerer 2013-07-08 23:09 ` Junio C Hamano 2013-07-09 20:13 ` Thomas Gummerer 2013-07-07 8:11 ` Thomas Gummerer [this message] 2013-07-08 16:31 ` [PATCH 06/22] make sure partially read index is not changed Junio C Hamano 2013-07-08 18:33 ` Thomas Gummerer 2013-07-07 8:11 ` [PATCH 07/22] dir.c: use index api Thomas Gummerer 2013-07-07 8:11 ` [PATCH 08/22] tree.c: " Thomas Gummerer 2013-07-07 8:11 ` [PATCH 09/22] name-hash.c: " Thomas Gummerer 2013-07-07 8:11 ` [PATCH 10/22] grep.c: Use " Thomas Gummerer 2013-07-07 8:11 ` [PATCH 11/22] ls-files.c: use the " Thomas Gummerer 2013-07-07 8:11 ` [PATCH 12/22] read-cache: make read_blob_data_from_index use " Thomas Gummerer 2013-07-07 8:11 ` [PATCH 13/22] documentation: add documentation of the index-v5 file format Thomas Gummerer 2013-07-11 10:39 ` Duy Nguyen 2013-07-11 11:39 ` Thomas Gummerer 2013-07-11 11:47 ` Duy Nguyen 2013-07-11 12:26 ` Thomas Gummerer 2013-07-11 12:50 ` Duy Nguyen 2013-07-07 8:11 ` [PATCH 14/22] read-cache: make in-memory format aware of stat_crc Thomas Gummerer 2013-07-07 8:11 ` [PATCH 15/22] read-cache: read index-v5 Thomas Gummerer 2013-07-07 20:18 ` Eric Sunshine 2013-07-08 11:40 ` Thomas Gummerer 2013-07-07 8:11 ` [PATCH 16/22] read-cache: read resolve-undo data Thomas Gummerer 2013-07-07 8:11 ` [PATCH 17/22] read-cache: read cache-tree in index-v5 Thomas Gummerer 2013-07-07 20:41 ` Eric Sunshine 2013-07-07 8:11 ` [PATCH 18/22] read-cache: write index-v5 Thomas Gummerer 2013-07-07 20:43 ` Eric Sunshine 2013-07-07 8:11 ` [PATCH 19/22] read-cache: write index-v5 cache-tree data Thomas Gummerer 2013-07-07 8:11 ` [PATCH 20/22] read-cache: write resolve-undo data for index-v5 Thomas Gummerer 2013-07-07 8:11 ` [PATCH 21/22] update-index.c: rewrite index when index-version is given Thomas Gummerer 2013-07-07 8:12 ` [PATCH 22/22] p0003-index.sh: add perf test for the index formats Thomas Gummerer
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 List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1373184720-29767-7-git-send-email-t.gummerer@gmail.com \ --to=t.gummerer@gmail.com \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=mhagger@alum.mit.edu \ --cc=pclouds@gmail.com \ --cc=robin.rosenberg@dewire.com \ --cc=trast@inf.ethz.ch \ /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
git@vger.kernel.org list mirror (unofficial, one of many) This inbox may be cloned and mirrored by anyone: git clone --mirror https://public-inbox.org/git git clone --mirror http://ou63pmih66umazou.onion/git git clone --mirror http://czquwvybam4bgbro.onion/git git clone --mirror http://hjrcffqmbrq6wope.onion/git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 git git/ https://public-inbox.org/git \ git@vger.kernel.org public-inbox-index git Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.version-control.git nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git nntp://news.gmane.io/gmane.comp.version-control.git note: .onion URLs require Tor: https://www.torproject.org/ code repositories for the project(s) associated with this inbox: https://80x24.org/mirrors/git.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git