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

Re: feature request: git add--interactive --patch on regex-matched hunks only

From
Jeff King <peff@peff.net>
Date
Jul 26, 2011, 06:09 UTC
Message-ID
<20110726060903.GA29486@sigill.intra.peff.net>
In-Reply-To
<CACsJy8Ay1wPXAx61_rGymHDJ=YGywAy=9epiXRfJ9e68np8x6g@mail.gmail.com>
On Tue, Jul 26, 2011 at 12:57:46PM +0700, Nguyen Thai Ngoc Duy wrote:
> It's my itch. I'm more than happy if you take care of the Perl part,
> I'll do the rest. While you're doing the Perl part, should we have
> both --match and --no-match? One filters in. The other filters out. I
> guess people may find filter-in case more helpful than the other.

Yeah. Also, what about grep options like case-insensitivity? I don't want to go too overboard with adding options that are unlikely to be used. It is perl, so technically you can do "(?i:foo)" to match "foo" case-insensitively. I don't think there's a way to do --no-match style negation in the regex itself, though.

Speaking of which: the name "--match" is way too generic for "git add". Something like "--hunk-match" would be better. It also is obviously only useful with "--patch". Should it imply "--patch"? Should it actually be "--patch=..."?

> I thought of this way initially, but I needed to split hunks in
> parse_diff and was stuck because I was not familiar with data
> structure used in git-add--interactive.

Oh yeah, you mentioned splitting before. I'm not sure how that would interact with this feature. In some cases, you'd want to split as much as possible, and in other cases, you'd want a bigger hunk. So I actually think it is an orthogonal feature to "autosplit" hunks before we show them to the user. I.e., something like:

  git add -p --autosplit-hunks --hunk-match=...

(where maybe the names could be better, but hopefully you get the point).

-Peff
Previous: Nguyen Thai Ngoc DuyNext: Nguyen Thai Ngoc Duy
Message 8 of 19 in “feature request: git add--interactive --patch on regex-matched hunks only”
  1. Nguyen Thai Ngoc DuyJul 24, 2011
  2. Jeff KingJul 25, 2011
  3. Junio C HamanoJul 25, 2011
  4. Jeff KingJul 26, 2011
  5. Nguyen Thai Ngoc DuyJul 26, 2011
  6. Jeff KingJul 26, 2011
  7. Nguyen Thai Ngoc DuyJul 26, 2011
  8. Jeff KingJul 26, 2011
  9. Nguyen Thai Ngoc DuyJul 26, 2011
  10. Nguyen Thai Ngoc DuyJul 26, 2011
  11. Jeff KingJul 27, 2011
  12. Nguyen Thai Ngoc DuyJul 27, 2011
  13. Jeff KingJul 27, 2011
  14. Jeff KingJul 27, 2011
  15. 1/5 add--interactive: refactor patch mode argument processingJeff King, Jul 27, 2011
  16. 2/5 add--interactive: factor out regex error handlingJeff King, Jul 27, 2011
  17. 3/5 add--interactive: allow hunk filtering on command lineJeff King, Jul 27, 2011
  18. 4/5 add--interactive: allow negatation of hunk filtersJeff King, Jul 27, 2011
  19. 5/5 add--interactive: add option to autosplit hunksJeff King, Jul 27, 2011

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.