* 'git commit --short' without touching index? @ 2010-07-03 8:30 Daniel 2010-07-03 9:17 ` Jeff King 0 siblings, 1 reply; 7+ messages in thread From: Daniel @ 2010-07-03 8:30 UTC (permalink / raw) To: git 'git commit --short' touches .git/index ('--short' implies '--dry-run'). Is there any equivalent command that does not touch .git/index? I'm using 'git commit --short' in a script to check if the repository needs attention. At present, it touches .git/index, which causes unnecessary activity in another script running rsync. thanks, Daniel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git commit --short' without touching index? 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 0 siblings, 2 replies; 7+ messages in thread From: Jeff King @ 2010-07-03 9:17 UTC (permalink / raw) To: Daniel; +Cc: git On Sat, Jul 03, 2010 at 08:30:31AM +0000, Daniel wrote: > 'git commit --short' touches .git/index ('--short' implies '--dry-run'). > > Is there any equivalent command that does not touch .git/index? > > I'm using 'git commit --short' in a script to check if the repository needs > attention. At present, it touches .git/index, which causes > unnecessary activity in another script running rsync. If you are just calling "git commit --short" without arguments (i.e., you care about the current state, not about "what would happen if I commit with these arguments"), then you probably want "git status". Also, you probably should use "git status --porcelain", which is the same as --short but is guaranteed not to change in the future. However, both "status" and "commit --dry-run" will opportunistically refresh the index. If you don't want to touch the index at all, you can use a combination of: # show changes between HEAD and index git diff-index HEAD # show changes between index and working tree git diff-files # show untracked files git ls-files --exclude-standard -o One thing you will find, though, is that not refreshing the index means that stat-dirty files (e.g., ones which have no content changed but which have had their timestamps changed) will appear the diff-files above. I don't think there is a simple way to tell "git status" to refresh the index internally, but not to write it out. It will do this if it doesn't have write permissions, but chmod'ing your index before running the script seems like an awful hack. You could refresh to a temporary index, but that also seems like a hack. It would be nice if the index-refreshing code only wrote to the index if there was something worth writing. I'm not sure how hard that would be to implement, though. -Peff ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git commit --short' without touching index? 2010-07-03 9:17 ` Jeff King @ 2010-07-03 10:08 ` friedan 2010-07-05 20:10 ` Junio C Hamano 1 sibling, 0 replies; 7+ messages in thread From: friedan @ 2010-07-03 10:08 UTC (permalink / raw) To: Jeff King; +Cc: git Thanks. Your suggestion seems to work. Much appreciated. Daniel On 2010.07.03 9:17 AM, Jeff King wrote: > However, both "status" and "commit --dry-run" will opportunistically > refresh the index. If you don't want to touch the index at all, you can > use a combination of: > > # show changes between HEAD and index > git diff-index HEAD > > # show changes between index and working tree > git diff-files > > # show untracked files > git ls-files --exclude-standard -o > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git commit --short' without touching index? 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 1 sibling, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2010-07-05 20:10 UTC (permalink / raw) To: Jeff King; +Cc: Daniel, git Jeff King <peff@peff.net> writes: > It would be nice if the index-refreshing code only wrote to the index if > there was something worth writing. I'm not sure how hard that would be > to implement, though. Hmm, don't we already do that with "istate->cache_changed"? In any case, we should diagnose "commit --short" (and "--procelain") as an error, perhaps by splitting option parsers for commit and status further. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git commit --short' without touching index? 2010-07-05 20:10 ` Junio C Hamano @ 2010-07-05 20:56 ` Jeff King 2010-07-05 21:28 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Jeff King @ 2010-07-05 20:56 UTC (permalink / raw) To: Junio C Hamano; +Cc: Daniel, git On Mon, Jul 05, 2010 at 01:10:43PM -0700, Junio C Hamano wrote: > Jeff King <peff@peff.net> writes: > > > It would be nice if the index-refreshing code only wrote to the index if > > there was something worth writing. I'm not sure how hard that would be > > to implement, though. > > Hmm, don't we already do that with "istate->cache_changed"? 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. > In any case, we should diagnose "commit --short" (and "--procelain") as an > error, perhaps by splitting option parsers for commit and status further. I don't think it's an error. "commit --short" implies "commit --dry-run --short", which is actually a useful thing (well, _I_ don't find it useful, but I believe it was kept intentionally during the "status is no longer commit --dry-run" conversion). -Peff ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git commit --short' without touching index? 2010-07-05 20:56 ` Jeff King @ 2010-07-05 21:28 ` Junio C Hamano 2010-07-06 12:10 ` Jeff King 0 siblings, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2010-07-05 21:28 UTC (permalink / raw) To: Jeff King; +Cc: Junio C Hamano, Daniel, git Jeff King <peff@peff.net> writes: > On Mon, Jul 05, 2010 at 01:10:43PM -0700, Junio C Hamano wrote: > >> Jeff King <peff@peff.net> writes: >> >> > It would be nice if the index-refreshing code only wrote to the index if >> > there was something worth writing. I'm not sure how hard that would be >> > to implement, though. >> >> Hmm, don't we already do that with "istate->cache_changed"? > > 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? 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. builtin/commit.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index c101f00..86d3926 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -343,9 +343,13 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int if (!pathspec || !*pathspec) { fd = hold_locked_index(&index_lock, 1); refresh_cache_or_die(refresh_flags); - if (write_cache(fd, active_cache, active_nr) || - commit_locked_index(&index_lock)) - die("unable to write new_index file"); + if (active_cache_changed) { + if (write_cache(fd, active_cache, active_nr) || + commit_locked_index(&index_lock)) + die("unable to write new_index file"); + } else { + rollback_lock_file(&index_lock); + } commit_style = COMMIT_AS_IS; return get_index_file(); } ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: 'git commit --short' without touching index? 2010-07-05 21:28 ` Junio C Hamano @ 2010-07-06 12:10 ` Jeff King 0 siblings, 0 replies; 7+ messages in thread From: Jeff King @ 2010-07-06 12:10 UTC (permalink / raw) To: Junio C Hamano; +Cc: Daniel, git 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 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-07-06 12:10 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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).