git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
	Git Mailing List <git@vger.kernel.org>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH v2 0/1] Make 'git commit' not accidentally lose staged content
Date: Mon, 17 Sep 2018 20:41:36 +0200	[thread overview]
Message-ID: <CACsJy8CFf7mVMbxWO9ASfVKE_PLdiLmxSN3CuMC=_sEsL_5pmQ@mail.gmail.com> (raw)
In-Reply-To: <20180917181511.GA3894@sigill.intra.peff.net>

On Mon, Sep 17, 2018 at 8:15 PM Jeff King <peff@peff.net> wrote:
> On Mon, Sep 17, 2018 at 07:29:26PM +0200, Duy Nguyen wrote:
> > I don't see a good way to get to recover this situation. I could go
> > back to the "index log" idea, where we keep a log of index changes (or
> > just "interesting" changes). That way there's no behavior change at
> > all. The user who accidentally updates/deletes something can always
> > retrieve the old content back (assuming that they realize quickly
> > since we can't keep very long log).
>
> FWIW, I like that approach much better, since:
>
>   1. It does not bother or restrict anybody in their workflow; instead,
>      they pay the complexity price only when they know they have made a
>      mistake.
>
>   2. It covers many more cases (e.g., just doing the wrong thing via
>      "add -p").
>
> A naive index log would be pretty cheap in CPU, at least for POSIX-ish
> systems. You could just hard link "index" to "index.N" before renaming
> "index.lock" over "index". But I guess if you have a gigantic index,
> that's less appealing. So maybe storing the equivalent of a "--raw" diff
> between the two index states would make more sense (and after all, you
> don't really need the stat-cache or cache-tree). It would cost more to
> reconstruct the index on the fly, but then the point is that you would
> create these logs a lot more than you access them.

Yeah. The problem though is extracting the information out of these
index.N files.

> > I've been thinking about allowing to undo worktree changes too (e.g.
> > accidental "git reset --hard") and this log can cover it as well.
>
> I like that, too. It's a little more costly just because it may involve
> object-db writes, but I think in most cases it would be fine. I almost
> always "git stash" away discarded changes these days instead of "git
> reset --hard", because it effectively provides this kind of log.

Yeah the added cost is pretty much given. You want safety, you pay extra :)

> > The only downside is we need a new command for the UI (or perhaps I
> > can just add "git add --log" or something like that).
>
> I think the reflog approach has been successful: give these intermediate
> states a name. So in theory I could do something like:
>
>   git checkout -p :@{2.minutes.ago}
>
> though it would probably be useful to be able to walk the states, too,
> just like we have "log --reflog-walk".
>
> The syntax above is off-the-cuff (and based on the ":<stage>" index
> syntax). I guess if we had a separate log for "stuff in the worktree
> that got thrown away by reset" we might need a separate syntax.

I'm leaning towards reflog too. Not because of the syntax but because
of reusing the current code base. I don't have to worry about pruning,
walking, gc-ing... because it's pretty much already there. And the UI
is not so urgent since reflog file is very readable, early adopters
can just open the file and get the hash.

This also lets me handle logging worktree changes in the future
(keeping track of untracked files is impossible with the "index.N"
approach)

I'm trying to quickly make something that writes to
"$GIT_DIR/logs/index" and see how it goes. But yeah I'll probably drop
this patch. The ":@{2.minutes.ago}" just makes me like this direction
more, even though I don't know if I could even make that work.
-- 
Duy

  reply	other threads:[~2018-09-17 18:42 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-20 15:41 [PATCH/RFC] commit: new option to abort -a something is already staged Nguyễn Thái Ngọc Duy
2018-08-20 15:55 ` Junio C Hamano
2018-08-20 17:48 ` Eric Sunshine
2018-08-20 19:30 ` Jonathan Nieder
2018-08-21 14:43   ` Duy Nguyen
2018-08-23  2:11     ` Jonathan Nieder
2018-08-23  2:15       ` Jonathan Nieder
2018-08-23 14:49         ` Duy Nguyen
2018-08-23 15:28           ` Junio C Hamano
2018-08-24  3:02             ` Jacob Keller
2018-08-24 14:42               ` Duy Nguyen
2018-08-24 23:23                 ` Jacob Keller
2018-08-24  2:59 ` Jacob Keller
2018-09-16  6:31 ` [PATCH v2 0/1] Make 'git commit' not accidentally lose staged content Nguyễn Thái Ngọc Duy
2018-09-16  6:31   ` [PATCH v2 1/1] commit: do not clobber the index Nguyễn Thái Ngọc Duy
2018-09-17 17:09   ` [PATCH v2 0/1] Make 'git commit' not accidentally lose staged content Junio C Hamano
2018-09-17 17:29     ` Duy Nguyen
2018-09-17 18:15       ` Jeff King
2018-09-17 18:41         ` Duy Nguyen [this message]
2018-09-18 17:35           ` Jeff King
2018-09-18 19:36         ` Jacob Keller
2018-09-18 23:19           ` Jeff King
2018-09-19 16:12             ` Duy Nguyen
2018-09-19 16:16               ` Jeff King
2018-09-17 19:26       ` Junio C Hamano
2018-09-18 19:41         ` Jacob Keller
2018-09-18 21:11           ` Eckhard Maaß
2018-09-18 19:33     ` Jacob Keller

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='CACsJy8CFf7mVMbxWO9ASfVKE_PLdiLmxSN3CuMC=_sEsL_5pmQ@mail.gmail.com' \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.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).