Skip to contentSkip to conversation

git-sh-setup: move GIT_DIR initialization into a function

PATCH In review David Aguilar 2 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 git-sh-setup: move GIT_DIR initialization into a function

---
This is a new patch since the last round, prep for 2/3

 git-sh-setup.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
git-sh-setup.sh +6 -2
index 9447980..d968760 100644
@@ -330,8 +330,7 @@ esac
 
 # Make sure we are in a valid repository of a vintage we understand,
 # if we require to be in a git repository.
-if test -z "$NONGIT_OK"
-then
+git_dir_init () {
 	GIT_DIR=$(git rev-parse --git-dir) || exit
 	if [ -z "$SUBDIRECTORY_OK" ]
 	then
@@ -346,6 +345,11 @@ then
 		exit 1
 	}
 	: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
+}
+
+if test -z "$NONGIT_OK"
+then
+	git_dir_init
 fi
 
 peel_committish () {
Signature · 1 line
2.1.2.378.g89c0b73
#1 lore raw

PATCH v3 2/3 mergetool: don't require a work tree for --tool-help

From: Charles Bailey <[email protected]>

---
Changes since v2:

This now uses the new git_dir_init function.

 git-mergetool.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
git-mergetool.sh +4 -1
index 96a61ba..cddb533 100755
@@ -10,11 +10,11 @@
 
 USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
+NONGIT_OK=Yes
 OPTIONS_SPEC=
 TOOL_MODE=merge
 . git-sh-setup
 . git-mergetool--lib
-require_work_tree
 
 # Returns true if the mode reflects a symlink
 is_symlink () {
@@ -378,6 +378,9 @@ prompt_after_failed_merge () {
 	done
 }
 
+require_work_tree
+git_dir_init
+
 if test -z "$merge_tool"
 then
 	# Check if a merge tool has been configured
Signature · 1 line
2.1.2.378.g89c0b73
#2 lore raw

PATCH v3 3/3 difftool: don't assume that default sh is sane

From: Charles Bailey <[email protected]>

git-difftool used to create a command list script containing $( ... ) and explicitly calls "sh -c" with this list.

Instead, allow mergetool --tool-help to take a mode parameter and call mergetool directly to invoke the show_tool_help function. This mode parameter is intented for use solely by difftool.

---
No changes since v2.

 git-difftool.perl | 6 +-----
 git-mergetool.sh  | 4 ++++
 2 files changed, 5 insertions(+), 5 deletions(-)
git-difftool.perl +1 -5
index 18ca61e..598fcc2 100755
@@ -47,13 +47,9 @@ sub find_worktree
 
 sub print_tool_help
 {
-	my $cmd = 'TOOL_MODE=diff';
-	$cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"';
-	$cmd .= ' && show_tool_help';
-
 	# See the comment at the bottom of file_diff() for the reason behind
 	# using system() followed by exit() instead of exec().
-	my $rc = system('sh', '-c', $cmd);
+	my $rc = system(qw(git mergetool --tool-help=diff));
 	exit($rc | ($rc >> 8));
 }
 
git-mergetool.sh +4 -0
index cddb533..10782b8 100755
@@ -327,6 +327,10 @@ guessed_merge_tool=false
 while test $# != 0
 do
 	case "$1" in
+	--tool-help=*)
+		TOOL_MODE=${1#--tool-help=}
+		show_tool_help
+		;;
 	--tool-help)
 		show_tool_help
 		;;
Signature · 1 line
2.1.2.378.g89c0b73
#3 lore raw

Re: [PATCH v3 2/3] mergetool: don't require a work tree for --tool-help

In reply to David Aguilar
Quoted 30 lines · David Aguilar

From: Charles Bailey <[email protected]>

---
Changes since v2:

This now uses the new git_dir_init function.

 git-mergetool.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
git-mergetool.sh +1 -1
index 96a61ba..cddb533 100755
@@ -10,11 +10,11 @@
 
 USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
+NONGIT_OK=Yes
 OPTIONS_SPEC=
 TOOL_MODE=merge
 . git-sh-setup
 . git-mergetool--lib
-require_work_tree
 
 # Returns true if the mode reflects a symlink
 is_symlink () {

git-mergetool.sh prompt_after_failed_merge () { · line 382

Quoted 5 lines
git-mergetool.sh +2 -0
@@ -378,6 +378,9 @@ prompt_after_failed_merge () {
 	done
 }
 
+require_work_tree
+git_dir_init

This is somewhat curious. Shouldn't the order of these swapped?

Quoted 4 lines
git-mergetool.sh +1 -0
+
 if test -z "$merge_tool"
 then
 	# Check if a merge tool has been configured
#4 lore raw

Re: [PATCH v3 2/3] mergetool: don't require a work tree for --tool-help

Quoted 35 lines · Junio C Hamano
Quoted 33 lines · David Aguilar

From: Charles Bailey <[email protected]>

---
Changes since v2:

This now uses the new git_dir_init function.

 git-mergetool.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
git-mergetool.sh +1 -1
index 96a61ba..cddb533 100755
@@ -10,11 +10,11 @@
 
 USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
+NONGIT_OK=Yes
 OPTIONS_SPEC=
 TOOL_MODE=merge
 . git-sh-setup
 . git-mergetool--lib
-require_work_tree
 
 # Returns true if the mode reflects a symlink
 is_symlink () {
@@ -378,6 +378,9 @@ prompt_after_failed_merge () {
 	done
 }
 
Quoted 4 lines

git-mergetool.sh prompt_after_failed_merge () { · line 382

Quoted 2 lines
git-mergetool.sh +2 -0
+require_work_tree
+git_dir_init

This is somewhat curious. Shouldn't the order of these swapped?

Yes. I'll send a replacement patch for 2/3 only.

Signature · 1 line
David
#5 lore raw

Re: [PATCH v3 2/3] mergetool: don't require a work tree for --tool-help

Quoted 36 lines · David Aguilar
Quoted 35 lines · Junio C Hamano
Quoted 33 lines · David Aguilar

From: Charles Bailey <[email protected]>

---
Changes since v2:

This now uses the new git_dir_init function.

 git-mergetool.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
git-mergetool.sh +1 -1
index 96a61ba..cddb533 100755
@@ -10,11 +10,11 @@
 
 USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
+NONGIT_OK=Yes
 OPTIONS_SPEC=
 TOOL_MODE=merge
 . git-sh-setup
 . git-mergetool--lib
-require_work_tree
 
 # Returns true if the mode reflects a symlink
 is_symlink () {
@@ -378,6 +378,9 @@ prompt_after_failed_merge () {
 	done
 }
 
Quoted 6 lines
Quoted 4 lines

git-mergetool.sh prompt_after_failed_merge () { · line 382

Quoted 2 lines
git-mergetool.sh +2 -0
+require_work_tree
+git_dir_init

This is somewhat curious. Shouldn't the order of these swapped?

Yes. I'll send a replacement patch for 2/3 only.

Nevermind, I noticed you already fixed this up in pu.

Thank you,

Signature · 1 line
David