git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Yuri <yuri@rawbw.com>, Git Mailing List <git@vger.kernel.org>
Subject: Re: 'git stash push' isn't atomic when Ctrl-C is pressed
Date: Thu, 27 Jan 2022 10:05:54 -0800	[thread overview]
Message-ID: <xmqq4k5p3vgd.fsf@gitster.g> (raw)
In-Reply-To: <220127.86zgnhdhft.gmgdl@evledraar.gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Thu, 27 Jan 2022 03:36:21 +0100")

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> Of course it's possible that I'm just missing something, do you see a
> reason for why having a signal handler be responsible for rolling back a
> reference transaction wouldn't work?

It is not an issue between would and would not work.  It is what is
practical and reasonable to support, and end-user expectation
management.

Besides, if you did

	open the reference transaction
	create a new commit to represent a stash entry
	revert local modifications from working tree files
	update the stash ref with the new commit
	commit the reference transaction

with the auto-rollback of the ref transaction as an atexit handler,
it would help rolling back the reference update (i.e. update to
refs/stash to append a reflog entry), but it would not help at all
rolling back updates to working tree files.

In fact, if you instead did them in this order instead:

	open the reference transaction
	create a new commit to represent a stash entry
	update the stash ref with the new commit
	commit the reference transaction
	revert local modifications from working tree files

it will safely record the local modifications in the stash *and* in
the refstore _before_ it starts to modify the working tree files, so

 (1) killing the process before the ref change is committed will
     truly be a no-op at the end-user level.  There may have been
     unreferenced objects added to the object store, but that won't
     hurt anything.

 (2) killing the process after the ref change is committed, before
     we completely revert all local modifications from the working
     tree files, will still leave crufts in the working tree.  But

     (2-a) you can "git reset --hard" to go to a known good state,
           i.e. the state you would have been in if "git stash push"
           were allowed to finish without interruption.

     (2-b) you can do (2-a) followed by "git stash pop" to go to
           another known good state, namely, the state before you
           ran "git stash push".

If you do not commit the ref transaction before starting to muck
with working tree files, such a recovery, which is transparent and
easy to understand what is going on, would not be possible.  You'd
lose the local changes and be left with a working tree with local
changes partially reverted.




  reply	other threads:[~2022-01-27 18:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-25 17:13 'git stash push' isn't atomic when Ctrl-C is pressed Yuri
2022-01-26 13:41 ` Ævar Arnfjörð Bjarmason
2022-01-26 16:09   ` John Cai
2022-01-26 17:30     ` Ævar Arnfjörð Bjarmason
2022-01-26 19:58   ` Junio C Hamano
2022-01-26 20:47     ` Ævar Arnfjörð Bjarmason
2022-01-26 23:15       ` Junio C Hamano
2022-01-27  2:36         ` Ævar Arnfjörð Bjarmason
2022-01-27 18:05           ` Junio C Hamano [this message]
2022-01-27  1:53       ` John Cai
2022-01-26 20:23 ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4k5p3vgd.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=yuri@rawbw.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).