git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: Mina Almasry <almasry.mina@hotmail.com>
Cc: <git@vger.kernel.org>
Subject: Re: Feature request - discard hunk in add --patch mode
Date: Wed, 15 Aug 2012 11:39:38 +0200	[thread overview]
Message-ID: <87txw41okl.fsf@thomas.inf.ethz.ch> (raw)
In-Reply-To: <BLU0-SMTP37070ADBEC060E1EA15944693B60@phx.gbl> (Mina Almasry's message of "Wed, 15 Aug 2012 04:36:22 -0400")

Mina Almasry <almasry.mina@hotmail.com> writes:

> I frequently stage files using git add --patch command and I almost 
> always come across debug code I want to discard, but there is no option 
> for that in the prompt. The result is that I have to run an extra 
> command after the dialogue ends.
>
> I would like to add a feature to allow users to discard hunks using a 
> command like r! or d!

This has come up before, and actually led to the introduction of
'checkout -p' and 'reset -p':

  http://thread.gmane.org/gmane.comp.version-control.git/123854

Judging by the '!' above, you are already aware that this is a dangerous
option that needs some safeguards.  I imagine that would largely account
for Junio's safety concerns.  So you could pick up from the general
direction of Pierre's post, and try to work out something.

However, life has become rather more complicated since 2009.  Whatever
you do also needs to fit nicely with checkout/reset/stash -p.  The first
two also take commit arguments, resulting in a total of seven modes of
operation, defined in %patch_modes.

I imagine one good angle of attack would be to proceed as follows:

* Optionally make add--interactive.perl more aware of what the patches
  say.  Ideally there would be a way to reverse the direction of a diff
  (or otherwise manipulate it) in the program itself, instead of having
  to decide this when fetching the patches.

* Change things so that the actions in %patch_modes are a hunk property
  instead of a global state.  Of course the actual mode still needs to
  be global state.  Not all actions should be possible in all modes;
  figure out a clean way to implement this.

* Design commands in some modes that switch to another mode, and/or set
  another action than the default in the current mode.

Note that r! commands need to also work in singlekey mode, where the 'r'
is read immediately and you would have to read for another
(confirmation) key to get the '!'.

Good luck!

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

  reply	other threads:[~2012-08-15  9:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-15  8:36 Feature request - discard hunk in add --patch mode Mina Almasry
2012-08-15  9:39 ` Thomas Rast [this message]
2012-08-15 18:11   ` Junio C Hamano
2012-08-15 18:46     ` Junio C Hamano
2012-08-15 20:58       ` Mina Almasry
2012-08-15 21:51         ` Junio C Hamano
2012-08-23  3:32         ` Mina Almasry

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

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

  git send-email \
    --in-reply-to=87txw41okl.fsf@thomas.inf.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=almasry.mina@hotmail.com \
    --cc=git@vger.kernel.org \
    /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.
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).