git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Comparing rebase --am with --interactive via p3400

From
Alban Gruin <alban.gruin@gmail.com>
Date
Apr 1, 2020, 11:33 UTC
Message-ID
<b380123e-dbcd-7e92-67ab-e6cbf0cec061@gmail.com>
In-Reply-To
<nycvar.QRO.7.76.6.2001312216410.46@tvgsbejvaqbjf.bet>
Hi Johannes,
Sorry for the late answer, I was really busy for the last months.
Le 31/01/2020 à 22:23, Johannes Schindelin a écrit :
Show 15 quoted lines
> Hi Alban,
>  -%<-
> 
> Indeed. I offered these insights in #git-devel (slightly edited):
> 
> This `discard_index()` is in an awfully central location. I am rather
> certain that it would cause problems to just remove it.
> 
> Looking at `do_merge()`: it explicitly discards and re-reads the index if
> we had to spawn a `git merge` process (which we do if a strategy other
> than `recursive` was specified, or if it is an octopus merge). But I am
> wary of other code paths that might not be as careful.
> 
> I see that `do_exec()` is similarly careful.
> 

I have to admit that the index is not my area of expertise in git, so sorry if my question is stupid: isn't there a less heavy way to find unstaged or uncommitted changes than discarding and then reloading the index?

Show 30 quoted lines
> One thing I cannot fail to notice: we do not re-read a changed index
> after running the `prepare-commit-msg` hook, or for that matter, any other
> hook. That could even be an old regression from the conversion of the
> interactive rebase to using the sequencer rather than a shell script.
> 
> Further, `reset_merge()` seems to spawn `git reset --merge` without
> bothering to re-read the possibly modified index. Its callees are
> `rollback_single_pick()`, `skip_single_pick()` and `sequencer_rollback()`,
> none of which seem to be careful, either, about checking whether the index
> was modified in the meantime.
> 
> Technically, the in-memory index should also be discarded
> in `apply_autostash()`, but so far, we do not have any callers of that
> function, I don't think, that wants to do anything but release resources
> and exit.
> 
> The `run_git_checkout()` function discards, as intended. I
> am not quite sure whether it needs to, though, unless the `.git/index`
> file _was_ modified (it _is_ possible, after all, to run `git rebase -i
> HEAD`, and I do have a use case for that where one of my scripts generates
> a todo script, sort of a `git cherry-pick --rebase-merges`, because
> `cherry-pick` does not support that mode).
> 
> The `continue_single_pick()` function spawns a `git
> commit` which could potentially modify the index through a hook, but the
> first call site does not care and the second one guards against that
> (erroring out...).
> 
> My biggest concern is with the `run_git_commit()` function: it does not
> re-read a potentially-modified index (think of hooks).
Thank you for your analysis.
Show 11 quoted lines
> 
> We will need to be very careful with this `discard_index()`, I think, and
> in my opinion there is a great opportunity here for cleaning up a little:
> rather than discarding and re-reading the in-memory index without seeing
> whether the on-disk index has changed at all appears a bit wasteful to me.
> 
> This could be refactored into a function that only discards and re-reads
> the index if the mtime of `.git/index` changed. That function could then
> also be taught to detect when the in-memory index has unwritten changes:
> that would constitute a bug.
> 
Hmm, checking if the mtime of the index to see if it changed isn't racy?
 Sub-second changes should happen, and to quote a comment in
is_racy_stat(), "nanosecond timestamped files can also be racy" -- even
if it should not really happen in the case of rebase…
> Ciao,
> Dscho
> 
Alban
Previous: Johannes SchindelinNext: Phillip Wood
Message 9 of 11 in “Comparing rebase --am with --interactive via p3400”
  1. Johannes SchindelinFeb 1, 2019
  2. Johannes SchindelinFeb 1, 2019
  3. Elijah NewrenFeb 1, 2019
  4. Alban GruinDec 27, 2019
  5. Elijah NewrenDec 27, 2019
  6. Alban GruinDec 29, 2019
  7. Johannes SchindelinJan 2, 2020
  8. Johannes SchindelinJan 31, 2020
  9. Alban GruinApr 1, 2020
  10. Phillip WoodApr 1, 2020
  11. Johannes SchindelinApr 4, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.