From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Daniel <friedan@muon.rutgers.edu>, git@vger.kernel.org
Subject: Re: 'git commit --short' without touching index?
Date: Tue, 6 Jul 2010 08:10:22 -0400 [thread overview]
Message-ID: <20100706121022.GB15413@sigill.intra.peff.net> (raw)
In-Reply-To: <7vk4p9wrdb.fsf@alter.siamese.dyndns.org>
On Mon, Jul 05, 2010 at 02:28:16PM -0700, Junio C Hamano wrote:
> > Apparently not:
> >
> > $ stat .git/index | grep -i modify
> > Modify: 2010-07-05 16:52:11.000000000 -0400
> > $ git status
> > # On branch master
> > nothing to commit
> > $ stat .git/index | grep -i modify
> > Modify: 2010-07-05 16:53:09.000000000 -0400
> >
> > and it is not just updating some stat-dirtiness. Doing it over and over
> > will keep updating the index. It looks like we unconditionally do the
> > lock and write in cmd_status, but I haven't looked further.
>
> Something like this, plus possibly a similar fix to "git commit $path"
> codepath, perhaps?
Yeah, that looks sane, though the one for "git status" is actually:
diff --git a/builtin/commit.c b/builtin/commit.c
index 8258a16..5e578af 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1090,9 +1090,11 @@ int cmd_status(int argc, const char **argv, const char *prefix)
fd = hold_locked_index(&index_lock, 0);
if (0 <= fd) {
- if (!write_cache(fd, active_cache, active_nr))
+ if (active_cache_changed &&
+ !write_cache(fd, active_cache, active_nr))
commit_locked_index(&index_lock);
- rollback_lock_file(&index_lock);
+ else
+ rollback_lock_file(&index_lock);
}
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
and I did confirm that it works (does not touch the index when nothing
changes, and does write out the index even for a stat-dirty entry).
> We may want to audit all uses of write_cache() and write_index() that are
> not protected with active_cache_changed (or istate->cache_changed); I am
> reluctant to suggest placing that logic into write_index() at this point,
> though, as we may be updating the index in bulk, without marking
> active_cache_changed bit, exactly because we know we will unconditionally
> write the result out.
I don't think changing write_index() is a good idea. There are a lot of
calls, and I would rather have each one opt into this optimization than
break them in a mass change.
I was thinking that we might be able to simplify all of these lines into
a "lock, write, and commit" function that would either rollback or die
on failure, depending on a parameter. But there's often more complex
logic going on between those functions, so I don't think it would really
save us much.
-Peff
prev parent reply other threads:[~2010-07-06 12:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-03 8:30 'git commit --short' without touching index? Daniel
2010-07-03 9:17 ` Jeff King
2010-07-03 10:08 ` friedan
2010-07-05 20:10 ` Junio C Hamano
2010-07-05 20:56 ` Jeff King
2010-07-05 21:28 ` Junio C Hamano
2010-07-06 12:10 ` Jeff King [this message]
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=20100706121022.GB15413@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=friedan@muon.rutgers.edu \
--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).