git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Carlos Martín Nieto" <cmn@elego.de>
Subject: [PATCH 4/5] commit: write cache-tree data when writing index anyway
Date: Tue, 6 Dec 2011 18:43:38 +0100	[thread overview]
Message-ID: <fcb51622a521eaf418c82bfd5ff83e8a0b79498b.1323191497.git.trast@student.ethz.ch> (raw)
In-Reply-To: <cover.1323191497.git.trast@student.ethz.ch>

In prepare_index(), we refresh the index, and then write it to disk if
this changed the index data.  After running hooks we re-read the index
and compute the root tree sha1 with the cache-tree machinery.

This gives us a mostly free opportunity to write up-to-date cache-tree
data: we can compute it in prepare_index() immediately before writing
the index to disk.

If we do this, we were going to write the index anyway, and the later
cache-tree update has no further work to do.  If we don't do it, we
don't do any extra work, though we still don't have have cache-tree
data after the commit.

The only case that suffers badly is when the pre-commit hook changes
many trees in the index.  I'm writing this off as highly unusual.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

Don't ask me why git thinks the index has been changed only when
already building upon an earlier commit.  I don't know.  I suspect
it's some raciness issue though.

 builtin/commit.c      |    2 ++
 t/t0090-cache-tree.sh |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 0163086..57d028e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -394,6 +394,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 		fd = hold_locked_index(&index_lock, 1);
 		add_files_to_cache(also ? prefix : NULL, pathspec, 0);
 		refresh_cache_or_die(refresh_flags);
+		update_main_cache_tree(1);
 		if (write_cache(fd, active_cache, active_nr) ||
 		    close_lock_file(&index_lock))
 			die(_("unable to write new_index file"));
@@ -414,6 +415,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 		fd = hold_locked_index(&index_lock, 1);
 		refresh_cache_or_die(refresh_flags);
 		if (active_cache_changed) {
+			update_main_cache_tree(1);
 			if (write_cache(fd, active_cache, active_nr) ||
 			    commit_locked_index(&index_lock))
 				die(_("unable to write new_index file"));
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index 3d0702a..a3527a5 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -70,7 +70,7 @@ test_expect_success 'test-scrap-cache-tree works' '
 	test_no_cache_tree
 '
 
-test_expect_failure 'second commit has cache-tree' '
+test_expect_success 'second commit has cache-tree' '
 	test_commit bar &&
 	test_shallow_cache_tree
 '
-- 
1.7.8.425.ga639d3

  parent reply	other threads:[~2011-12-06 17:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-06 17:43 [PATCH 0/5] cache-tree revisited Thomas Rast
2011-12-06 17:43 ` [PATCH 1/5] Add test-scrap-cache-tree Thomas Rast
2011-12-06 22:51   ` Junio C Hamano
2011-12-06 17:43 ` [PATCH 2/5] Test the current state of the cache-tree optimization Thomas Rast
2011-12-06 17:43 ` [PATCH 3/5] Refactor cache_tree_update idiom from commit Thomas Rast
2011-12-06 17:43 ` Thomas Rast [this message]
2011-12-06 17:43 ` [PATCH 5/5] reset: update cache-tree data when appropriate Thomas Rast
2011-12-06 23:13   ` Junio C Hamano
2011-12-07  7:53     ` Thomas Rast
2011-12-08 14:15 ` [PATCH 0/5] cache-tree revisited Thomas Rast

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=fcb51622a521eaf418c82bfd5ff83e8a0b79498b.1323191497.git.trast@student.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=cmn@elego.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).