From: <trast@student.ethz.ch>
To: <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Carlos Martín Nieto" <cmn@elego.de>,
"Thomas Rast" <trast@student.ethz.ch>
Subject: [PATCH] commit: write out cache-tree information
Date: Tue, 2 Aug 2011 18:36:34 +0200 [thread overview]
Message-ID: <9f5e031045b55c4738de8bc9aae290827e128cd3.1312302862.git.trast@student.ethz.ch> (raw)
From: Thomas Rast <trast@student.ethz.ch>
While write-tree has code to write out the cache-tree information
(since we have to compute it anyway if the cache is stale), commit
lost this capability when it became a builtin and moved away from
using write-tree.
Add the necessary code to write out the cache. This is extremely
similar to what write_cache_as_tree() does.
Reported-by: Carlos Martín Nieto <cmn@elego.de>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Reported on IRC.
There's a similar disparity between read-tree and checkout, but I
first have to understand the exact conditions in or around
unpack_trees() [checkout.c:417] where the read-tree reasoning applies.
builtin/commit.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index e1af9b1..47b0eea 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -637,6 +637,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
const char *hook_arg2 = NULL;
int ident_shown = 0;
int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
+ int fd;
+ struct lock_file *lock_file;
if (!no_verify && run_hook(index_file, "pre-commit", NULL))
return 0;
@@ -861,6 +863,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
* the editor and after we invoke run_status above.
*/
discard_cache();
+ lock_file = xcalloc(1, sizeof(struct lock_file));
+ fd = hold_lock_file_for_update(lock_file, index_file, LOCK_DIE_ON_ERROR);
read_cache_from(index_file);
if (!active_cache_tree)
active_cache_tree = cache_tree();
@@ -869,6 +873,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
error(_("Error building trees"));
return 0;
}
+ if (0 <= fd) {
+ if (write_cache(fd, active_cache, active_nr) ||
+ commit_lock_file(lock_file))
+ rollback_lock_file(lock_file);
+ }
if (run_hook(index_file, "prepare-commit-msg",
git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
--
1.7.6.668.g17b0a
next reply other threads:[~2011-08-02 16:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 16:36 trast [this message]
2011-08-02 18:13 ` [PATCH] commit: write out cache-tree information Junio C Hamano
2011-08-02 21:15 ` Junio C Hamano
2011-08-02 22:01 ` 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=9f5e031045b55c4738de8bc9aae290827e128cd3.1312302862.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).