Re: [PATCH 7/7] Implement git commit as a builtin command.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Junio C Hamano <gitster@...>
Cc: <git@...>
Date: Friday, September 21, 2007 - 1:18 pm

On Wed, 2007-09-19 at 18:27 -0700, Junio C Hamano wrote:

Ok.  I see you removed them in the pu commit, thanks.


Yes, the order matters.  I made sure the C version has the same
precedence as the shell script.  I'll add a comment in parse-options.h.


I'll split it out in parse-options.[ch].  I still don't understand why
using getopt is better; parse-options.c is a 75 line file and it's
simple code.  It does more work that getopt, since for most options it
automatically writes back the option argument into a global.  All I have
to do then is validate that no illegal combination of options was
passed.


Yeah.


Yes, oops, not sure what that was about.


Yeah, I'll fix that.


I didn't have refresh_cache() in there originally, there was some test
case that didn't pass until I added it.  The git-commit.sh shell script
calls git update-index --refresh after the prepare_index() part, which
is where I got it from.  Will investigate.


Not yet.


Oh... hmm, if 'all' is set there are no paths, but yes, that is
confusing.


Uhm, yes, good points.


Yes, we talked about this in IRC a few weeks back, and agreed that just
read_tree() should be fine.  I'll just remove that FIXME.


This is the case where we add the files on the command line
to .git/index, but commit from a clean index file corresponding to HEAD
with the files from the command line added (partial commit?).  The first
add_files_to_cache() updates .git/index, then we do read_tree() to build
a tmp index from HEAD and then we add the files again.  The tmp index is
written to a tmp index file.


Ugh, yeah, that's a bit ugly... it gets closed in add_files_to_cache()
once we've written the index.  The patch I have here uses the
add_files_to_cache() from builtin-add.c which doesn't close the fd or
write the index.  That now happens in prepare_index(), so it's a little
clearer what's going on.


As described above, we need to add the files to the user index and the
temporary index we're committing from.  As for just using an in-memory
index, I wanted to do it that way originally, but you have to write it
to disk after all for the pre-commit hook.  Maybe doing it in-memory is
better after all, and then only write it to disk if we actually have a
pre-commit hook.


Yep, that was the other reason.  I suppose a short term fix for this
would be to make run_status() take a struct index_state and write it to
a temp file and run against that.  We can then clean that up to not use
a temp file in a second patch.


This is working in the current version.  I use hold_locked_index() in
the beginning of prepare_index() and calls commit_locked_index() to
write the new index at the end of cmd_commit() once the commit is done.


prepare_index() does this, that's the case you pointed out above, where
I'm calling add_files_to_cache() twice.


This is also in prepare_index() - the 'if (all)' and 'if (also)' cases
in the beginning of the function does that, except commiting the the
updated real index, that's done at the end of cmd_commit(), share among
all cases.


Yes, but isn't that what the code is doing now?  I write out the tree in
cmd_commit(), not in prepare_index(), but prepare_index() is also used
in cmd_status().  It seems better to only write the tree if we're going
to do a commit.  Other than that, the flow of the code follows your
description pretty much step by step.


That looks nicer, the add_files_to_index() function is a pretty clean
solution.  But again, we can't write the tree in prepare_index(); we
need the temporary index for the pre-commit hook, and prepare_index() is
used in cmd_status().  But we can just return an struct index_state
pointer from prepare_index().

Thanks for reviewing,
Kristian


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 6/7] Export rerere() and launch_editor()., Kristian Høgsberg, (Mon Sep 17, 8:06 pm)
Re: [PATCH 6/7] Export rerere() and launch_editor()., Junio C Hamano, (Wed Sep 19, 7:52 pm)
Re: [PATCH 6/7] Export rerere() and launch_editor()., Johannes Schindelin, (Tue Sep 18, 9:14 am)
[PATCH 7/7] Implement git commit as a builtin command., Kristian Høgsberg, (Mon Sep 17, 8:06 pm)
Re: [PATCH 7/7] Implement git commit as a builtin command., Junio C Hamano, (Wed Sep 19, 9:27 pm)
Re: [PATCH 7/7] Implement git commit as a builtin command., Kristian , (Fri Sep 21, 1:18 pm)
Re: [PATCH 7/7] Implement git commit as a builtin command., Junio C Hamano, (Fri Sep 21, 3:32 pm)
Re: [PATCH 7/7] Implement git commit as a builtin command., Johannes Schindelin, (Tue Sep 18, 9:58 am)