threads / discuss / 45824

[Suggestion] Alternative way for displaying help menu of patch flow

Subject: [Suggestion] Alternative way for displaying help menu of patch flow

## tl;dr

3 messages between Apr 28, 2017 and Apr 28, 2017.

replies: 2people: 2as markdown or json

Kaartic Sivaraam· Apr 28, 2017, 05:14 UTC · lore
Hello community,

I would like to state about a small issue I face when I use the `git add -i` command. I guess it's expressed easily with an example.

**** Start ****

Imagine a situation in which you accidentally made a reasonable amount of change to your code from your last commit. You would like to put them in separate commits and hence you go for the `git add -i` command and choose the `patch` option. You choose the file which you want to update as patches.

Unfortunately a hunk (of reasonable size) in the file seems to be having changes that you would like to be in separate commits. So, you would like to split the hunk into smaller parts but you forgot the correct option for it and you use `?` option. In most cases you wouldn't see the help menu completely. Moreover, if the hunk's size is reasonable enough to take up the whole screen of the terminal you would be seeing the same screen as before as the help menu is hidden above the hunk and you need to scroll to see it (only if you knew it's up there in the first place!)

**** End ****

I guess it would be better to display the help menu in a separate flow, like when the user click the `?` option in the `patch` flow then the whole screen is cleared and the help menu is displayed in some appropriate place and after the user has viewed the help menu he could quit from the help screen (probably by using a key like `q`) to continue where he left off. I think it would be better because, in general, a user would want to see the help menu when he uses the `?` option in the patch flow, not the hunk that gets displayed after it.

Is it a good suggestion or is there anything I missed?
Quote : "You don’t change the world by doing what you’re told.” — Joi Ito

Regards, Kaartic

Jeff King· Apr 28, 2017, 06:37 UTC · re: Kaartic Sivaraam · lore

Re: [Suggestion] Alternative way for displaying help menu of patch flow

On Fri, Apr 28, 2017 at 10:44:22AM +0530, Kaartic Sivaraam wrote:
Show 8 quoted lines
> I guess it would be better to display the help menu in a separate flow, like
> when the user click the `?` option in the `patch` flow then the whole screen
> is cleared and the help menu is displayed in some appropriate place and
> after the user has viewed the help menu he could quit from the help screen
> (probably by using a key like `q`) to continue where he left off. I think it
> would be better because, in general, a user would want to see the help menu
> when he uses the `?` option in the patch flow, not the hunk that gets
> displayed after it.

I think it would be nicer to avoid modality in the interface. I.e., rather than having "?" switch you into "help mode", stay at the same hunk prompt but just don't show the hunk again automatically. In most cases it will still be visible on the screen anyway, and there probably ought to be a "r"edisplay command if the user wants to see it from scratch.

Something like the patch at the end of this message.

I think this problem does extend to other output we show in the patch loop. For instance, if you hit 'j' and there is no, you get:

  $ git add -p
  diff --git a/foo b/foo
  index 3367afd..3e75765 100644
  --- a/foo
  +++ b/foo
  @@ -1 +1 @@
  -old
  +new
  Stage this hunk [y,n,q,a,d,/,e,?]? j
  No next hunk
  @@ -1 +1 @@
  -old
  +new
  Stage this hunk [y,n,q,a,d,/,e,?]? 

If the hunk is big, that message scrolls off the screen. We could probably put it after the hunk, but I'd worry that the ordering would be confusing (because it comes between the hunk and the "this hunk" prompt.

Or it could just not re-display the hunk all (like what my patch does for help), and you'd get:

  @@ -1 +1 @@
  -old
  +new
  Stage this hunk [y,n,q,a,d,/,e,?]? j
  No next hunk
  Stage this hunk [y,n,q,a,d,/,e,?]? 
at which point you could "r" to redisplay it if you wanted to.

I also suspect that other menus in add--interactive have the same issue. E.g., if you have a large number of files what does the file-selection menu "git add -i" look like? Perhaps the issue is less common there, though.

---
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 709a5f6ce..81f62331b 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1237,6 +1237,7 @@ k - leave this hunk undecided, see previous undecided hunk
 K - leave this hunk undecided, see previous hunk
 s - split the current hunk into smaller hunks
 e - manually edit the current hunk
+r - redisplay the current hunk
 ? - print help
 EOF
 }
@@ -1385,6 +1386,7 @@ my %patch_update_prompt_modes = (
 sub patch_update_file {
 	my $quit = 0;
 	my ($ix, $num);
+	my $skip_hunk_display;
 	my $path = shift;
 	my ($head, @hunk) = parse_diff($path);
 	($head, my $mode, my $deletion) = parse_diff_header($head);
@@ -1451,8 +1453,13 @@ sub patch_update_file {
 		if ($hunk[$ix]{TYPE} eq 'hunk') {
 			$other .= ',e';
 		}
-		for (@{$hunk[$ix]{DISPLAY}}) {
-			print;
+
+		if ($skip_hunk_display) {
+			$skip_hunk_display = 0;
+		} else {
+			for (@{$hunk[$ix]{DISPLAY}}) {
+				print;
+			}
 		}
 		print colored $prompt_color,
 			sprintf(__($patch_update_prompt_modes{$patch_mode}{$hunk[$ix]{TYPE}}), $other);
@@ -1608,8 +1615,13 @@ sub patch_update_file {
 					splice @hunk, $ix, 1, $newhunk;
 				}
 			}
+			elsif ($line =~ /^r/) {
+				# do nothing; we'll show the hunk when we loop
+				next;
+			}
 			else {
 				help_patch_cmd($other);
+				$skip_hunk_display = 1;
 				next;
 			}
 			# soft increment
Kaartic Sivaraam· Apr 28, 2017, 07:21 UTC · re: Jeff King · lore

Re: [Suggestion] Alternative way for displaying help menu of patch flow

On Friday 28 April 2017 12:07 PM, Jeff King wrote:
>
> If the hunk is big, that message scrolls off the screen. We could
> probably put it after the hunk, but I'd worry that the ordering would be
> confusing (because it comes between the hunk and the "this hunk" prompt.

Probably it could be better to clear the console after each user input, before the result of that input is displayed. That could probably remove the clutter and could allow the user to easily differentiate from the current output from previous output.

Show 11 quoted lines
> Or it could just not re-display the hunk all (like what my patch does
> for help), and you'd get:
>
>    @@ -1 +1 @@
>    -old
>    +new
>    Stage this hunk [y,n,q,a,d,/,e,?]? j
>    No next hunk
>    Stage this hunk [y,n,q,a,d,/,e,?]?
>
> at which point you could "r" to redisplay it if you wanted to.

This seems good too. But, I guess, the help menu would probably hide the hunk and could make that prompt a little absurd.

Show 56 quoted lines
> I also suspect that other menus in add--interactive have the same
> issue. E.g., if you have a large number of files what does the
> file-selection menu "git add -i" look like? Perhaps the issue is less
> common there, though.
>
> ---
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 709a5f6ce..81f62331b 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -1237,6 +1237,7 @@ k - leave this hunk undecided, see previous undecided hunk
>   K - leave this hunk undecided, see previous hunk
>   s - split the current hunk into smaller hunks
>   e - manually edit the current hunk
> +r - redisplay the current hunk
>   ? - print help
>   EOF
>   }
> @@ -1385,6 +1386,7 @@ my %patch_update_prompt_modes = (
>   sub patch_update_file {
>   	my $quit = 0;
>   	my ($ix, $num);
> +	my $skip_hunk_display;
>   	my $path = shift;
>   	my ($head, @hunk) = parse_diff($path);
>   	($head, my $mode, my $deletion) = parse_diff_header($head);
> @@ -1451,8 +1453,13 @@ sub patch_update_file {
>   		if ($hunk[$ix]{TYPE} eq 'hunk') {
>   			$other .= ',e';
>   		}
> -		for (@{$hunk[$ix]{DISPLAY}}) {
> -			print;
> +
> +		if ($skip_hunk_display) {
> +			$skip_hunk_display = 0;
> +		} else {
> +			for (@{$hunk[$ix]{DISPLAY}}) {
> +				print;
> +			}
>   		}
>   		print colored $prompt_color,
>   			sprintf(__($patch_update_prompt_modes{$patch_mode}{$hunk[$ix]{TYPE}}), $other);
> @@ -1608,8 +1615,13 @@ sub patch_update_file {
>   					splice @hunk, $ix, 1, $newhunk;
>   				}
>   			}
> +			elsif ($line =~ /^r/) {
> +				# do nothing; we'll show the hunk when we loop
> +				next;
> +			}
>   			else {
>   				help_patch_cmd($other);
> +				$skip_hunk_display = 1;
>   				next;
>   			}
>   			# soft increment

Regards, Kaartic

← back to recent threads