git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Autosplit option for git add -p
@ 2024-06-07  9:05 Konstantin Tokarev
  2024-06-08 10:43 ` Christian Couder
  0 siblings, 1 reply; 4+ messages in thread
From: Konstantin Tokarev @ 2024-06-07  9:05 UTC (permalink / raw)
  To: git

Hello all,

Is there any option in git to make `git add -p` split hunks by
default, just like 's' was pressed automatically? If no, how would one
implement such an option?

My use case: I've recently started working with big LaTeX document
having every paragraph as a single line. As a result, hunks quickly
become larger than screen, so that splitting is highly desirable.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Autosplit option for git add -p
  2024-06-07  9:05 Autosplit option for git add -p Konstantin Tokarev
@ 2024-06-08 10:43 ` Christian Couder
  2024-06-08 10:47   ` Dragan Simic
  2024-06-08 18:53   ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Christian Couder @ 2024-06-08 10:43 UTC (permalink / raw)
  To: Konstantin Tokarev; +Cc: git

Hi,

On Fri, Jun 7, 2024 at 11:06 AM Konstantin Tokarev <annulen@yandex.ru> wrote:
>
> Hello all,
>
> Is there any option in git to make `git add -p` split hunks by
> default, just like 's' was pressed automatically? If no, how would one
> implement such an option?

It doesn't look like there is any option to do that. About
implementing it, it depends if it would be a command line option or a
config option.

Anyway I think you might want to take a look at the run_add_p()
function in "add-patch.c".

> My use case: I've recently started working with big LaTeX document
> having every paragraph as a single line. As a result, hunks quickly
> become larger than screen, so that splitting is highly desirable.

Best!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Autosplit option for git add -p
  2024-06-08 10:43 ` Christian Couder
@ 2024-06-08 10:47   ` Dragan Simic
  2024-06-08 18:53   ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Dragan Simic @ 2024-06-08 10:47 UTC (permalink / raw)
  To: Christian Couder; +Cc: Konstantin Tokarev, git

Hello,

On 2024-06-08 12:43, Christian Couder wrote:
> On Fri, Jun 7, 2024 at 11:06 AM Konstantin Tokarev <annulen@yandex.ru> 
> wrote:
>> Is there any option in git to make `git add -p` split hunks by
>> default, just like 's' was pressed automatically? If no, how would one
>> implement such an option?
> 
> It doesn't look like there is any option to do that. About
> implementing it, it depends if it would be a command line option or a
> config option.

To me, a new command-line option would make more sense.  Though,
perhaps a new configuration option could also make sense when enabled
for particular repositories, but that could also trigger the main red
flag, which is that a repository configuration can change the user
experience, so I'm not sure it wouldn't be frowned upon.

> Anyway I think you might want to take a look at the run_add_p()
> function in "add-patch.c".
> 
>> My use case: I've recently started working with big LaTeX document
>> having every paragraph as a single line. As a result, hunks quickly
>> become larger than screen, so that splitting is highly desirable.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Autosplit option for git add -p
  2024-06-08 10:43 ` Christian Couder
  2024-06-08 10:47   ` Dragan Simic
@ 2024-06-08 18:53   ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-06-08 18:53 UTC (permalink / raw)
  To: Christian Couder; +Cc: Konstantin Tokarev, git

Christian Couder <christian.couder@gmail.com> writes:

> It doesn't look like there is any option to do that. About
> implementing it, it depends if it would be a command line option or a
> config option.

Having these alone make no sense to me.

I'd suggest extending the lowest level (i.e. interactive prompt
response) first so that a stronger 's' splits all hunks in the
current file.  It might be sufficient for the use case.

On top of that, it happens to be that when changes to _all_ paths
want to be split, it may prove handy to also have a command line
option.

But the reason why I am hesitant to endorse a command line option
that splits everything is because:

 (1) it is dubious to expect the user to _know_ that it makes sense
     to split all changes before starting "add -p" (and friends).

 (2) if the user gives such an option and then in the interactive
     session regrets that it was too much to split all the hunks, it
     is unclear how the user can easily recover (there is no "merge
     all hunks back to the original" operation).



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-08 18:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-07  9:05 Autosplit option for git add -p Konstantin Tokarev
2024-06-08 10:43 ` Christian Couder
2024-06-08 10:47   ` Dragan Simic
2024-06-08 18:53   ` Junio C Hamano

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).