git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Pratyush Yadav <me@yadavpratyush.com>
Cc: git@vger.kernel.org
Subject: Re: How to reset selected lines?
Date: Wed, 14 Aug 2019 10:52:20 -0400	[thread overview]
Message-ID: <20190814145219.GA12093@sigill.intra.peff.net> (raw)
In-Reply-To: <20190814114844.gvb5znje7cpzehkd@localhost.localdomain>

On Wed, Aug 14, 2019 at 05:18:44PM +0530, Pratyush Yadav wrote:

> > So "git add -p", for example, also works by creating diffs, modifying
> > them, and feeding the result to "apply". You can see the implementation
> > in git-add--interactive.perl, where it literally calls diff and apply
> > commands.
> > 
> > And that leads us to the answer to the first question. That script
> > implements "add -p", but also "checkout -p" (which is what you want),
> > "reset -p", "stash -p", etc. They differ only in what we diff and how we
> > apply the result; the main engine of slicing and dicing the diff through
> > user interaction is the same. See the %patch_modes hash for the list.
> 
> Ah, so that means I do have to dive into generating diffs. Too bad, I 
> was hoping for a cleaner (read: easier) way.
> 
> On that note, I don't suppose there is a way to use 
> git-add--interactive's diff engine from a script, is there?  That'd 
> allow me to not write potentially buggy code and solve problems someone 
> already solved.

The actual diffing is all done by lower-level commands. So I'm not sure
there's much "engine" to reuse from the script. It takes care of asking
the user about which lines to look at, how to split the diff, etc, but
that's the part you'd want a totally different interface for.

The one thing you _might_ want to pick up is the line recounting bits.
We used to just call "apply --recount", but I think there were some
corner cases that it couldn't handle well. The details are in 2b8ea7f3c7
(add -p: calculate offset delta for edited patches, 2018-03-05) and
3a8522f41f (add -p: don't rely on apply's '--recount' option,
2018-03-05), and probably some mailing list around those.

You could probably start with just not handling those corner cases,
though (either relying on "apply --recount", or just using whatever
git-gui already does now for staging).

-Peff

  reply	other threads:[~2019-08-14 14:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-13 14:18 How to reset selected lines? Pratyush Yadav
2019-08-13 15:42 ` Jeff King
2019-08-13 17:32   ` Junio C Hamano
2019-08-14 11:48   ` Pratyush Yadav
2019-08-14 14:52     ` Jeff King [this message]
2019-08-13 22:07 ` Johannes Sixt
2019-08-14 11:11   ` Pratyush Yadav

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=20190814145219.GA12093@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=me@yadavpratyush.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).