{"thread":{"id":"43982","subject":"git add -p—splitting hunks, limit is too large","startedAt":"2016-09-02T14:37:04Z","lastAt":"2016-09-04T08:10:46Z","messageCount":5,"participants":["Beau Martinez","Jeff King","Christian Neukirchen","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"300887","messageId":"CAEtDOuV+0CKRSu9mJa27+yQKJ-QRyNmwecrZKaaCh0St+VagZg@mail.gmail.com","threadId":"43982","inReplyTo":null,"subject":"git add -p—splitting hunks, limit is too large","fromName":"Beau Martinez","fromEmail":"beau@beaumartinez.com","sentAt":"2016-09-02T14:36:58Z","receivedAt":"2016-09-02T14:37:04Z","isPatch":false,"sender":{"key":"beau@beaumartinez.com","avatar":null},"body":"Hi git developers and community,\n\nI'd like to inquire as to why `git add -p` can only split hunks so\nmuch. The limit is too large; why can't you split until each hunk is\nonly a line? I often have to run `edit` and split them manually\nmyself.\n\nI'd like to contribute a patch to change it, although my C is rusty.\nAre there resources that will help me to do this?\n\nThank you for your time.\n\nBeau\n"},{"id":"300903","messageId":"20160902191425.ki7nfhlqgnihoqpw@sigill.intra.peff.net","threadId":"43982","inReplyTo":"CAEtDOuV+0CKRSu9mJa27+yQKJ-QRyNmwecrZKaaCh0St+VagZg@mail.gmail.com","subject":"Re: git add -p—splitting hunks, limit is too large","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-09-02T19:14:25Z","receivedAt":"2016-09-02T19:17:27Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Sep 02, 2016 at 03:36:58PM +0100, Beau Martinez wrote:\n\n> I'd like to inquire as to why `git add -p` can only split hunks so\n> much. The limit is too large; why can't you split until each hunk is\n> only a line? I often have to run `edit` and split them manually\n> myself.\n\nThere's some previous discussion in this thread:\n\n  http://public-inbox.org/git/200805232221.45406.trast@student.ethz.ch/t/#u\n\nand further back, this message:\n\n  http://public-inbox.org/git/7vbq8v7cdx.fsf@gitster.siamese.dyndns.org/\n\nI think one problem is that in a given contiguous hunk, not all of the\nlines are independent, because edits are represented as a pair of -/+\nlines. E.g., if the preimage is:\n\n  one\n  two\n  four\n\nand the postimage is:\n\n  one\n  two modified\n  three\n  four\n\nyour diff will be:\n\n   one\n  -two\n  +two modified\n  +three\n   four\n\nThe ideal split is two groups:\n\n  -two\n  +two modified\n\n  +three\n\nSo you could possibly achieve that by specifying the exact line to split\nat. But let's imagine \"two\" was the missing item, and we modified\n\"three\". Then your diff is:\n\n   one\n  -three\n  +two\n  +three modified\n   four\n\nNow the related lines are non-adjacent! I don't think there's a general\nsolution, and of course it can get arbitrarily complicated, with many\ninterleaved pairs. I don't think we can rely on figuring out which lines\nform a pair. In this toy example it's obvious, but in real diffs the\nlines might not bear any resemblance.\n\nSplitting to single lines means you need to remember to add the matched\npairs, which might be arbitrarily far apart.  That's not really any\ndifferent than dumping the hunk in your editor, but I find there that\nit's easy to rearrange and group things as appropriate.\n\n> I'd like to contribute a patch to change it, although my C is rusty.\n> Are there resources that will help me to do this?\n\nThe good news (or maybe the bad) is that \"add -p\" is implemented\nentirely in Perl. :) It's in git-add--interactive.perl.\n\n-Peff\n"},{"id":"300908","messageId":"87mvjqjd48.fsf@juno.home.vuxu.org","threadId":"43982","inReplyTo":"20160902191425.ki7nfhlqgnihoqpw@sigill.intra.peff.net","subject":"Re: git add -p—splitting hunks, limit is too large","fromName":"Christian Neukirchen","fromEmail":"chneukirchen@gmail.com","sentAt":"2016-09-02T19:49:43Z","receivedAt":"2016-09-02T19:50:03Z","isPatch":false,"sender":{"key":"chneukirchen@gmail.com","avatar":"https://avatars.githubusercontent.com/u/139?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Splitting to single lines means you need to remember to add the matched\n> pairs, which might be arbitrarily far apart.  That's not really any\n> different than dumping the hunk in your editor, but I find there that\n> it's easy to rearrange and group things as appropriate.\n\nMy main use case for this would be to split a plain addition into\nseveral small additions.  Which would be much easier with the\nmenu-driven approach.\n\n(Mostly I just use magit, but sometimes I want to do this on machines\nwithout emacs set up.)\n\n-- \nChristian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org\n\n"},{"id":"300974","messageId":"alpine.DEB.2.20.1609041000420.129229@virtualbox","threadId":"43982","inReplyTo":"CAEtDOuV+0CKRSu9mJa27+yQKJ-QRyNmwecrZKaaCh0St+VagZg@mail.gmail.com","subject":"Re: git add -p—splitting hunks, limit is too large","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-09-04T08:01:36Z","receivedAt":"2016-09-04T08:01:45Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Beau,\n\nOn Fri, 2 Sep 2016, Beau Martinez wrote:\n\n> Hi git developers and community,\n> \n> I'd like to inquire as to why `git add -p` can only split hunks so\n> much. The limit is too large; why can't you split until each hunk is\n> only a line? I often have to run `edit` and split them manually\n> myself.\n\nPlease note that git gui lets you stage lines individually.\n\nCiao,\nJohannes\n"},{"id":"300976","messageId":"alpine.DEB.2.20.1609041001421.129229@virtualbox","threadId":"43982","inReplyTo":"20160902191425.ki7nfhlqgnihoqpw@sigill.intra.peff.net","subject":"Re: git add -p—splitting hunks, limit is too large","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-09-04T08:10:25Z","receivedAt":"2016-09-04T08:10:46Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Fri, 2 Sep 2016, Jeff King wrote:\n\n> The good news (or maybe the bad) is that \"add -p\" is implemented\n> entirely in Perl. :)\n\nYeah, you would definitely not call this \"good news\" if you were in my\nshoes.\n\nThere is no question that it has grown way too unwieldy and that we (once\nagain, as with so many other scripts) missed the boat to convert it to C.\n\nScripting is nice for prototyping. But it comes at a high\nportability/performance cost if taken too far. And we took it way too far.\n\nJust look at all of those 1667 lines of git-add--interactive and weep. So\nmany things reimplemented in Perl instead of reusing functions in\nlibgit.a (or introducing them, making them usable from other parts of\nGit). Wasted time is what I see there.\n\nThe worst part is that it completely violates our original \"Unix\nphilosophy\" of implementing the business logic in C and combinig it using\nlight-weight scripting.\n\nAnd of course now the script is *so large* that nobody wants to undertake\nthe task of porting it to C.\n\nCiao,\nDscho\n"}]}