{"thread":{"id":"61604","subject":"Autosplit option for git add -p","startedAt":"2024-06-07T09:05:39Z","lastAt":"2024-06-08T18:53:38Z","messageCount":4,"participants":["Konstantin Tokarev","Christian Couder","Dragan Simic","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"496637","messageId":"20240607120530.74297526@yuvnserver","threadId":"61604","inReplyTo":null,"subject":"Autosplit option for git add -p","fromName":"Konstantin Tokarev","fromEmail":"annulen@yandex.ru","sentAt":"2024-06-07T09:05:30Z","receivedAt":"2024-06-07T09:05:39Z","isPatch":false,"sender":{"key":"annulen@yandex.ru","avatar":null},"body":"Hello all,\n\nIs there any option in git to make `git add -p` split hunks by\ndefault, just like 's' was pressed automatically? If no, how would one\nimplement such an option?\n\nMy use case: I've recently started working with big LaTeX document\nhaving every paragraph as a single line. As a result, hunks quickly\nbecome larger than screen, so that splitting is highly desirable.\n\nThanks.\n"},{"id":"496704","messageId":"CAP8UFD3JM_h1BvK59R4wT1DeZyo6o-9T3GXGK8xE6vLnDMDCaQ@mail.gmail.com","threadId":"61604","inReplyTo":"20240607120530.74297526@yuvnserver","subject":"Re: Autosplit option for git add -p","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2024-06-08T10:43:33Z","receivedAt":"2024-06-08T10:43:47Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Hi,\n\nOn Fri, Jun 7, 2024 at 11:06 AM Konstantin Tokarev <annulen@yandex.ru> wrote:\n>\n> Hello all,\n>\n> Is there any option in git to make `git add -p` split hunks by\n> default, just like 's' was pressed automatically? If no, how would one\n> implement such an option?\n\nIt doesn't look like there is any option to do that. About\nimplementing it, it depends if it would be a command line option or a\nconfig option.\n\nAnyway I think you might want to take a look at the run_add_p()\nfunction in \"add-patch.c\".\n\n> My use case: I've recently started working with big LaTeX document\n> having every paragraph as a single line. As a result, hunks quickly\n> become larger than screen, so that splitting is highly desirable.\n\nBest!\n"},{"id":"496705","messageId":"2a50a861804727da14f6a440bc335178@manjaro.org","threadId":"61604","inReplyTo":"CAP8UFD3JM_h1BvK59R4wT1DeZyo6o-9T3GXGK8xE6vLnDMDCaQ@mail.gmail.com","subject":"Re: Autosplit option for git add -p","fromName":"Dragan Simic","fromEmail":"dsimic@manjaro.org","sentAt":"2024-06-08T10:47:39Z","receivedAt":"2024-06-08T10:47:41Z","isPatch":false,"sender":{"key":"dsimic@manjaro.org","avatar":null},"body":"Hello,\n\nOn 2024-06-08 12:43, Christian Couder wrote:\n> On Fri, Jun 7, 2024 at 11:06 AM Konstantin Tokarev <annulen@yandex.ru> \n> wrote:\n>> Is there any option in git to make `git add -p` split hunks by\n>> default, just like 's' was pressed automatically? If no, how would one\n>> implement such an option?\n> \n> It doesn't look like there is any option to do that. About\n> implementing it, it depends if it would be a command line option or a\n> config option.\n\nTo me, a new command-line option would make more sense.  Though,\nperhaps a new configuration option could also make sense when enabled\nfor particular repositories, but that could also trigger the main red\nflag, which is that a repository configuration can change the user\nexperience, so I'm not sure it wouldn't be frowned upon.\n\n> Anyway I think you might want to take a look at the run_add_p()\n> function in \"add-patch.c\".\n> \n>> My use case: I've recently started working with big LaTeX document\n>> having every paragraph as a single line. As a result, hunks quickly\n>> become larger than screen, so that splitting is highly desirable.\n"},{"id":"496720","messageId":"xmqqmsnvclle.fsf@gitster.g","threadId":"61604","inReplyTo":"CAP8UFD3JM_h1BvK59R4wT1DeZyo6o-9T3GXGK8xE6vLnDMDCaQ@mail.gmail.com","subject":"Re: Autosplit option for git add -p","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-06-08T18:53:33Z","receivedAt":"2024-06-08T18:53:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> It doesn't look like there is any option to do that. About\n> implementing it, it depends if it would be a command line option or a\n> config option.\n\nHaving these alone make no sense to me.\n\nI'd suggest extending the lowest level (i.e. interactive prompt\nresponse) first so that a stronger 's' splits all hunks in the\ncurrent file.  It might be sufficient for the use case.\n\nOn top of that, it happens to be that when changes to _all_ paths\nwant to be split, it may prove handy to also have a command line\noption.\n\nBut the reason why I am hesitant to endorse a command line option\nthat splits everything is because:\n\n (1) it is dubious to expect the user to _know_ that it makes sense\n     to split all changes before starting \"add -p\" (and friends).\n\n (2) if the user gives such an option and then in the interactive\n     session regrets that it was too much to split all the hunks, it\n     is unclear how the user can easily recover (there is no \"merge\n     all hunks back to the original\" operation).\n\n\n"}]}