Skip to contentSkip to conversation

git-difftool: allow skipping file by typing 'n' at prompt

PATCH In review Sitaram Chamarty 6 participants 14 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-difftool: allow skipping file by typing 'n' at prompt

---

I'm using what is pretty much a universal convention to signify that the default choice is "y"; I hope documentation for something so small is not needed but if it is, let me know and I'll do that also.

 git-difftool--helper.sh |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
git-difftool--helper.sh +5 -4
index 8452890..bc1b098 100755
@@ -38,15 +38,16 @@ launch_merge_tool () {
 
 	# $LOCAL and $REMOTE are temporary files so prompt
 	# the user with the real $MERGED name before launching $merge_tool.
+	ans=y
 	if should_prompt
 	then
 		printf "\nViewing: '$MERGED'\n"
 		if use_ext_cmd
 		then
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [y]/n: " \
 				"$GIT_DIFFTOOL_EXTCMD"
 		else
-			printf "Hit return to launch '%s': " "$merge_tool"
+			printf "Launch '%s' [y]/n: " "$merge_tool"
 		fi
 		read ans
 	fi
@@ -54,9 +55,9 @@ launch_merge_tool () {
 	if use_ext_cmd
 	then
 		export BASE
-		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
+		test "$ans" != "n" && eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
-		run_merge_tool "$merge_tool"
+		test "$ans" != "n" && run_merge_tool "$merge_tool"
 	fi
 }
 
Signature · 1 line
1.7.6
#1 lore raw

git-difftool--helper.sh launch_merge_tool () { · line 47

Quoted 10 lines · Sitaram Chamarty

---

I'm using what is pretty much a universal convention to signify that the default choice is "y"; I hope documentation for something so small is not needed but if it is, let me know and I'll do that also.

git-difftool--helper.sh +1 -1
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [y]/n: " \

I think I've seen this done as: "do this? [Y/n]" elsewhere.

Not telling you what to do, but trying to feel what others may think.

#2 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Sitaram Chamarty

---

I'm using what is pretty much a universal convention to signify that the default choice is "y"; I hope documentation for something so small is not needed but if it is, let me know and I'll do that also.

Quoted 6 lines

git-difftool--helper.sh launch_merge_tool () { · line 47

Quoted 2 lines
git-difftool--helper.sh +1 -1
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [y]/n: " \

I think I've seen this done as: "do this? [Y/n]" elsewhere.

Not telling you what to do, but trying to feel what others may think.

Yes, that was my immediate thought, too (or even [Yn]).

-Peff

#3 lore raw
In reply to Junio C Hamano
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Sitaram Chamarty

---

I'm using what is pretty much a universal convention to signify that the default choice is "y"; I hope documentation for something so small is not needed but if it is, let me know and I'll do that also.

Quoted 6 lines
Quoted 2 lines

-                     printf "Hit return to launch '%s': " \
+                     printf "Launch '%s' [y]/n: " \

I think I've seen this done as: "do this? [Y/n]" elsewhere.

Not telling you what to do, but trying to feel what others may think.

I think so, too. The [y]/n syntax is not clear enough for me to confidently know what the default value will be.

Phil

#4 lore raw
Quoted 8 lines · Phil Hord
Quoted 3 lines · Junio C Hamano

I think I've seen this done as: "do this? [Y/n]" elsewhere.

Not telling you what to do, but trying to feel what others may think.

I think so, too. The [y]/n syntax is not clear enough for me to confidently know what the default value will be.

One downside of "do this [Y,n,m,o,p,q]? " is that it limits us to lowercase responses, which means we cannot assign 'q' for quitting from the innermost nested context and assign 'Q' for quitting from the whole interactive loop (e.g. "git add -p").

    "do this [y,n,m,o,p,q] (default=y)? "

may have been a better choice in hindsight.

No matter what we end up doing, let's try to be consistent.

Thanks.

#5 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Phil Hord
Quoted 3 lines · Junio C Hamano

I think I've seen this done as: "do this? [Y/n]" elsewhere.

Not telling you what to do, but trying to feel what others may think.

I think so, too.  The [y]/n syntax is not clear enough for me to confidently know what the default value will be.

Quoted 6 lines

One downside of "do this [Y,n,m,o,p,q]? " is that it limits us to lowercase responses, which means we cannot assign 'q' for quitting from the innermost nested context and assign 'Q' for quitting from the whole interactive loop (e.g. "git add -p").

   "do this [y,n,m,o,p,q] (default=y)? "

Does this even make a difference in this case? I was going to send out a new patch using [Y/n] instead of my original [y]/n. There's only one loop in this thing, and till now people have been presumably hitting Ctrl-C to get out of it. I see no real need to make that more elegant; all I set out to do is add one teeny weeny bit of functionality to a prompt that -- other than giving you a chance to hit that Ctrl-C -- was not actually doing anything useful at all.

Quoted 4 lines

may have been a better choice in hindsight.

No matter what we end up doing, let's try to be consistent.

The only other part of git where I have ever used a prompt is 'git add -p'. Consistency with *that* prompt, to me, would mean colors. And help text. And I'm not sure what else, really, since I only used it superficially.

Isn't that overkill for this case?

I'll wait a few hours for any further comments then send out a patch that is the same as my original one except it uses [Y/n] instead of [y]/n.

#6 lore raw

PATCH 1/1 git-difftool: allow skipping file by typing 'n' at prompt

---

(re-rolled according to earlier discussion)

 git-difftool--helper.sh |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
git-difftool--helper.sh +5 -4
index 8452890..0468446 100755
@@ -38,15 +38,16 @@ launch_merge_tool () {
 
 	# $LOCAL and $REMOTE are temporary files so prompt
 	# the user with the real $MERGED name before launching $merge_tool.
+	ans=y
 	if should_prompt
 	then
 		printf "\nViewing: '$MERGED'\n"
 		if use_ext_cmd
 		then
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [Y/n]: " \
 				"$GIT_DIFFTOOL_EXTCMD"
 		else
-			printf "Hit return to launch '%s': " "$merge_tool"
+			printf "Launch '%s' [Y/n]: " "$merge_tool"
 		fi
 		read ans
 	fi
@@ -54,9 +55,9 @@ launch_merge_tool () {
 	if use_ext_cmd
 	then
 		export BASE
-		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
+		test "$ans" != "n" && eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
-		run_merge_tool "$merge_tool"
+		test "$ans" != "n" && run_merge_tool "$merge_tool"
 	fi
 }
 
Signature · 1 line
1.7.6
#7 lore raw
Quoted 4 lines · Sitaram Chamarty

---

(re-rolled according to earlier discussion)

Thanks. It is clear from the subject and the patch text that you are changing "hit return to unconditionally launch" into "launch it if you want to", but can you give justification why a choice not to launch is needed in the log message?

#8 lore raw

PATCH 1/1 git-difftool: allow skipping file by typing 'n' at prompt

This is useful if you forgot to restrict the diff to the paths you want to see, or selecting precisely the ones you want is too much typing.

---

Quoted 4 lines · Junio C Hamano

Thanks. It is clear from the subject and the patch text that you are changing "hit return to unconditionally launch" into "launch it if you want to", but can you give justification why a choice not to launch is needed in the log message?

OK; done.

 git-difftool--helper.sh |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
git-difftool--helper.sh +5 -4
index 8452890..0468446 100755
@@ -38,15 +38,16 @@ launch_merge_tool () {
 
 	# $LOCAL and $REMOTE are temporary files so prompt
 	# the user with the real $MERGED name before launching $merge_tool.
+	ans=y
 	if should_prompt
 	then
 		printf "\nViewing: '$MERGED'\n"
 		if use_ext_cmd
 		then
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [Y/n]: " \
 				"$GIT_DIFFTOOL_EXTCMD"
 		else
-			printf "Hit return to launch '%s': " "$merge_tool"
+			printf "Launch '%s' [Y/n]: " "$merge_tool"
 		fi
 		read ans
 	fi
@@ -54,9 +55,9 @@ launch_merge_tool () {
 	if use_ext_cmd
 	then
 		export BASE
-		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
+		test "$ans" != "n" && eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
-		run_merge_tool "$merge_tool"
+		test "$ans" != "n" && run_merge_tool "$merge_tool"
 	fi
 }
 
Signature · 1 line
1.7.6
#9 lore raw
Quoted 6 lines · Sitaram Chamarty

This is useful if you forgot to restrict the diff to the paths you want to see, or selecting precisely the ones you want is too much typing.

---

Quoted 8 lines
Quoted 4 lines · Junio C Hamano

Thanks. It is clear from the subject and the patch text that you are changing "hit return to unconditionally launch" into "launch it if you want to", but can you give justification why a choice not to launch is needed in the log message?

OK; done.

Looks OK from a cursory viewing. Do we want some additional tests?

For that matter, have you run the test suite with this patch applied (I haven't)?

Quoted 37 lines
 git-difftool--helper.sh |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
git-difftool--helper.sh +5 -4
index 8452890..0468446 100755
@@ -38,15 +38,16 @@ launch_merge_tool () {
 
 	# $LOCAL and $REMOTE are temporary files so prompt
 	# the user with the real $MERGED name before launching $merge_tool.
+	ans=y
 	if should_prompt
 	then
 		printf "\nViewing: '$MERGED'\n"
 		if use_ext_cmd
 		then
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [Y/n]: " \
 				"$GIT_DIFFTOOL_EXTCMD"
 		else
-			printf "Hit return to launch '%s': " "$merge_tool"
+			printf "Launch '%s' [Y/n]: " "$merge_tool"
 		fi
 		read ans
 	fi
@@ -54,9 +55,9 @@ launch_merge_tool () {
 	if use_ext_cmd
 	then
 		export BASE
-		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
+		test "$ans" != "n" && eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
-		run_merge_tool "$merge_tool"
+		test "$ans" != "n" && run_merge_tool "$merge_tool"
 	fi
 }
#10 lore raw

PATCH 1/1 git-difftool: allow skipping file by typing 'n' at prompt

This is useful if you forgot to restrict the diff to the paths you want to see, or selecting precisely the ones you want is too much typing.

---

Quoted 4 lines · Junio C Hamano

Looks OK from a cursory viewing. Do we want some additional tests?

For that matter, have you run the test suite with this patch applied (I haven't)?

OK; done. I got some "broken" but nothing "failed":

    make aggregate-results
    make[3]: Entering directory `/home/sitaram/clones/git/t'
    for f in test-results/t*-*.counts; do \
            echo "$f"; \
    done | '/bin/sh' ./aggregate-results.sh
    fixed   0
    success 7377
    failed  0
    broken  49
    total   7461

Hope that is not a problem.

However, I'm not sure the file names that 'git difftool' comes up with are in a predictable order. That would mess up the test, but I can neither make it fail not find definitive information on the order in which the changed files are processed.

 git-difftool--helper.sh |    9 +++++----
 t/t7800-difftool.sh     |   44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 5 deletions(-)
git-difftool--helper.sh +5 -4
index 8452890..0468446 100755
@@ -38,15 +38,16 @@ launch_merge_tool () {
 
 	# $LOCAL and $REMOTE are temporary files so prompt
 	# the user with the real $MERGED name before launching $merge_tool.
+	ans=y
 	if should_prompt
 	then
 		printf "\nViewing: '$MERGED'\n"
 		if use_ext_cmd
 		then
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [Y/n]: " \
 				"$GIT_DIFFTOOL_EXTCMD"
 		else
-			printf "Hit return to launch '%s': " "$merge_tool"
+			printf "Launch '%s' [Y/n]: " "$merge_tool"
 		fi
 		read ans
 	fi
@@ -54,9 +55,9 @@ launch_merge_tool () {
 	if use_ext_cmd
 	then
 		export BASE
-		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
+		test "$ans" != "n" && eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
-		run_merge_tool "$merge_tool"
+		test "$ans" != "n" && run_merge_tool "$merge_tool"
 	fi
 }
 
t/t7800-difftool.sh +43 -1

54 lines not on this page · raw message

Signature · 1 line
1.7.6
#11 lore raw
Quoted 29 lines · Sitaram Chamarty
 git-difftool--helper.sh |    9 +++++----
 t/t7800-difftool.sh     |   44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 5 deletions(-)
git-difftool--helper.sh +3 -2
index 8452890..0468446 100755
@@ -38,15 +38,16 @@ launch_merge_tool () {
 
 	# $LOCAL and $REMOTE are temporary files so prompt
 	# the user with the real $MERGED name before launching $merge_tool.
+	ans=y
 	if should_prompt
 	then
 		printf "\nViewing: '$MERGED'\n"
 		if use_ext_cmd
 		then
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [Y/n]: " \
 				"$GIT_DIFFTOOL_EXTCMD"
 		else
-			printf "Hit return to launch '%s': " "$merge_tool"
+			printf "Launch '%s' [Y/n]: " "$merge_tool"
 		fi
 		read ans
 	fi

git-difftool--helper.sh launch_merge_tool () { · line 62

Quoted 10 lines
git-difftool--helper.sh +2 -2
@@ -54,9 +55,9 @@ launch_merge_tool () {
 	if use_ext_cmd
 	then
 		export BASE
-		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
+		test "$ans" != "n" && eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
-		run_merge_tool "$merge_tool"
+		test "$ans" != "n" && run_merge_tool "$merge_tool"
 	fi
 }

It's a minor point but for me, this looks a little more difficult to follow than it needs to be.

Why do we need to hold on to 'ans' for so long? With the new prompt, if we ever 'read ans' we always want to return from the launch_merge_tool without doing anything else if we read "n". I think it's easier to follow if we just change 'read ans' and leave the 'if use_ext_cmd' clauses alone. Perhaps some people don't like the early return, though?

Charles.

E.g. (for discussion, untested):

git-difftool--helper.sh +7 -3
index 8452890..b668a12 100755
@@ -43,12 +43,16 @@ launch_merge_tool () {
                printf "\nViewing: '$MERGED'\n"
                if use_ext_cmd
                then
-                       printf "Hit return to launch '%s': " \
+                       printf "Launch '%s' [Y/n]: " \
                                "$GIT_DIFFTOOL_EXTCMD"
                else
-                       printf "Hit return to launch '%s': " "$merge_tool"
+                       printf "Launch '%s' [Y/n]: " "$merge_tool"
+               fi
+
+               if read ans && test "$ans" = "n"
+               then
+                       return
                fi
-               read ans
        fi
 
        if use_ext_cmd
#12 lore raw
In reply to Sitaram Chamarty
Quoted 5 lines · Sitaram Chamarty

However, I'm not sure the file names that 'git difftool' comes up with are in a predictable order. That would mess up the test, but I can neither make it fail not find definitive information on the order in which the changed files are processed.

Hmm, that may be an issue, I would think.

Quoted 28 lines
 git-difftool--helper.sh |    9 +++++----
 t/t7800-difftool.sh     |   44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 5 deletions(-)
git-difftool--helper.sh +3 -2
index 8452890..0468446 100755
@@ -38,15 +38,16 @@ launch_merge_tool () {
 
 	# $LOCAL and $REMOTE are temporary files so prompt
 	# the user with the real $MERGED name before launching $merge_tool.
+	ans=y
 	if should_prompt
 	then
 		printf "\nViewing: '$MERGED'\n"
 		if use_ext_cmd
 		then
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [Y/n]: " \
 				"$GIT_DIFFTOOL_EXTCMD"
 		else
-			printf "Hit return to launch '%s': " "$merge_tool"
+			printf "Launch '%s' [Y/n]: " "$merge_tool"
 		fi
 		read ans
 	fi

git-difftool--helper.sh launch_merge_tool () { · line 62

Quoted 10 lines
git-difftool--helper.sh +2 -2
@@ -54,9 +55,9 @@ launch_merge_tool () {
 	if use_ext_cmd
 	then
 		export BASE
-		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
+		test "$ans" != "n" && eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
-		run_merge_tool "$merge_tool"
+		test "$ans" != "n" && run_merge_tool "$merge_tool"
 	fi
 }

I also found suggestion by Charles Bailey to return from the launch function when the user says "no" easier to follow.

Quoted 12 lines
t/t7800-difftool.sh +3 -1
index 395adfc..f547e0b 100755
@@ -38,7 +38,18 @@ restore_test_defaults()
 prompt_given()
 {
 	prompt="$1"
-	test "$prompt" = "Hit return to launch 'test-tool': branch"
+	test "$prompt" = "Launch 'test-tool' [Y/n]: branch"
+}
+

t/t7800-difftool.sh restore_test_defaults() · line 53

Quoted 10 lines
t/t7800-difftool.sh +9 -0
+stdin_contains()
+{
+	grep >/dev/null "$1"
+}
+
+stdin_doesnot_contain()
+{
+	grep >/dev/null "$1" && return 1
+	return 0
 }

Doesn't

	! grep >/dev/null "$1"

work in this case?

I also wondered if this is easier to read:

	pipe | stdin_contains m2 &&
	! pipe | stdin_contains master

but I do not think it is (we cannot say "pipe | ! stdin_contains master").

In any case, here is what I ended up queuing. Thanks.

-- >8 --
From: Sitaram Chamarty <[email protected]>
Date: Sat, 8 Oct 2011 18:40:15 +0530
Subject: [PATCH] git-difftool: allow skipping file by typing 'n' at prompt

This is useful if you forgot to restrict the diff to the paths you want to see, or selecting precisely the ones you want is too much typing.

[jc: with a change to return from the function upon 'n' by Charles Bailey and a small tweak in stdin_doesnot_contain() in the test]

---
 git-difftool--helper.sh |    9 ++++++---
 t/t7800-difftool.sh     |   43 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 4 deletions(-)
git-difftool--helper.sh +6 -3
index 8452890..e6558d1 100755
@@ -43,12 +43,15 @@ launch_merge_tool () {
 		printf "\nViewing: '$MERGED'\n"
 		if use_ext_cmd
 		then
-			printf "Hit return to launch '%s': " \
+			printf "Launch '%s' [Y/n]: " \
 				"$GIT_DIFFTOOL_EXTCMD"
 		else
-			printf "Hit return to launch '%s': " "$merge_tool"
+			printf "Launch '%s' [Y/n]: " "$merge_tool"
+		fi
+		if read ans && test "$ans" = n
+		then
+			return
 		fi
-		read ans
 	fi
 
 	if use_ext_cmd
t/t7800-difftool.sh +42 -1

53 lines not on this page · raw message

Signature · 1 line
1.7.7.138.g7f41b6
#13 lore raw
Quoted 6 lines · Junio C Hamano

I also wondered if this is easier to read:

       pipe | stdin_contains m2 &&
       ! pipe | stdin_contains master

but I do not think it is (we cannot say "pipe | ! stdin_contains master").

Agreed on both counts.

"pipe | ( ! grep master )" does work, but I suspect that is an inconsistency in the shell so I didn't want to use it. IIRC the "( list )" constrict is not supposed to make *that* much difference. Have to check when I have time.

Quoted 6 lines

In any case, here is what I ended up queuing.  Thanks.

t/t7800-difftool.sh +3 -0
+stdin_doesnot_contain()
+{
+       ! stdin_contains "$1"

 }

(facepalm) Why didn't I think of that!

Thanks :-)