{"thread":{"id":"22236","subject":"[PATCH v2 1/3] t7800-difftool.sh: Simplify the --extcmd test","startedAt":"2010-01-15T22:03:42Z","lastAt":"2010-01-15T22:03:44Z","messageCount":3,"participants":["David Aguilar"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"131785","messageId":"1263593024-12093-1-git-send-email-davvid@gmail.com","threadId":"22236","inReplyTo":null,"subject":"[PATCH v2 1/3] t7800-difftool.sh: Simplify the --extcmd test","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2010-01-15T22:03:42Z","receivedAt":"2010-01-15T22:03:42Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"Instead of running 'grep', 'echo', and 'wc' we simply compare\ngit-difftool's output against a known good value.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nThis is unchanged from v1 but is included in the series\nfor completeness.\n\nThese all apply to 'next', specifically the da/difftool branch.\n\n t/t7800-difftool.sh |   13 +++++--------\n 1 files changed, 5 insertions(+), 8 deletions(-)\n\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex 8ee186a..1d9e07b 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -15,6 +15,9 @@ if ! test_have_prereq PERL; then\n \ttest_done\n fi\n \n+LF='\n+'\n+\n remove_config_vars()\n {\n \t# Unset all config variables used by git-difftool\n@@ -219,19 +222,13 @@ test_expect_success 'difftool.<tool>.path' '\n \trestore_test_defaults\n '\n \n-test_expect_success 'difftool --extcmd=...' '\n+test_expect_success 'difftool --extcmd=cat' '\n \tdiff=$(git difftool --no-prompt --extcmd=cat branch) &&\n+\ttest \"$diff\" = branch\"$LF\"master\n \n-\tlines=$(echo \"$diff\" | wc -l) &&\n-\ttest \"$lines\" -eq 2 &&\n \n-\tlines=$(echo \"$diff\" | grep master | wc -l) &&\n-\ttest \"$lines\" -eq 1 &&\n \n-\tlines=$(echo \"$diff\" | grep branch | wc -l) &&\n-\ttest \"$lines\" -eq 1 &&\n \n-\trestore_test_defaults\n '\n \n test_done\n-- \n1.6.6.6.g627fb.dirty\n"},{"id":"131786","messageId":"1263593024-12093-2-git-send-email-davvid@gmail.com","threadId":"22236","inReplyTo":"1263593024-12093-1-git-send-email-davvid@gmail.com","subject":"[PATCH v2 2/3] difftool: Add '-x' and as an alias for '--extcmd'","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2010-01-15T22:03:43Z","receivedAt":"2010-01-15T22:03:43Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"This adds '-x' as a shorthand for the '--extcmd' option.\nArguments to '--extcmd' can be specified separately, which\nwas not originally possible.\n\nThis also fixes the brief help text so that it mentions\nboth '-x' and '--extcmd'.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nChanges since v1:\n\nThe copyright notice to says \"2009, 2010\" instead of \"2009-2010\"\n\n Documentation/git-difftool.txt |    3 ++-\n git-difftool.perl              |   21 ++++++++++++++-------\n t/t7800-difftool.sh            |    8 ++++++++\n 3 files changed, 24 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt\nindex f67d2db..5c68cff 100644\n--- a/Documentation/git-difftool.txt\n+++ b/Documentation/git-difftool.txt\n@@ -7,7 +7,7 @@ git-difftool - Show changes using common diff tools\n \n SYNOPSIS\n --------\n-'git difftool' [--tool=<tool>] [-y|--no-prompt|--prompt] [<'git diff' options>]\n+'git difftool' [<options>] <commit>{0,2} [--] [<path>...]\n \n DESCRIPTION\n -----------\n@@ -58,6 +58,7 @@ is set to the name of the temporary file containing the contents\n of the diff post-image.  `$BASE` is provided for compatibility\n with custom merge tool commands and has the same value as `$LOCAL`.\n \n+-x <command>::\n --extcmd=<command>::\n \tSpecify a custom command for viewing diffs.\n \t'git-difftool' ignores the configured defaults and runs\ndiff --git a/git-difftool.perl b/git-difftool.perl\nindex f8ff245..d639de3 100755\n--- a/git-difftool.perl\n+++ b/git-difftool.perl\n@@ -1,5 +1,5 @@\n #!/usr/bin/env perl\n-# Copyright (c) 2009 David Aguilar\n+# Copyright (c) 2009, 2010 David Aguilar\n #\n # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible\n # git-difftool--helper script.\n@@ -23,8 +23,9 @@ my $DIR = abs_path(dirname($0));\n sub usage\n {\n \tprint << 'USAGE';\n-usage: git difftool [-g|--gui] [-t|--tool=<tool>] [-y|--no-prompt]\n-                    [\"git diff\" options]\n+usage: git difftool [-t|--tool=<tool>] [-x|--extcmd=<cmd>]\n+                    [-y|--no-prompt]   [-g|--gui]\n+                    ['git diff' options]\n USAGE\n \texit 1;\n }\n@@ -62,14 +63,20 @@ sub generate_command\n \t\t\t$skip_next = 1;\n \t\t\tnext;\n \t\t}\n-\t\tif ($arg =~ /^--extcmd=/) {\n-\t\t\t$ENV{GIT_DIFFTOOL_EXTCMD} = substr($arg, 9);\n-\t\t\tnext;\n-\t\t}\n \t\tif ($arg =~ /^--tool=/) {\n \t\t\t$ENV{GIT_DIFF_TOOL} = substr($arg, 7);\n \t\t\tnext;\n \t\t}\n+\t\tif ($arg eq '-x' || $arg eq '--extcmd') {\n+\t\t\tusage() if $#ARGV <= $idx;\n+\t\t\t$ENV{GIT_DIFFTOOL_EXTCMD} = $ARGV[$idx + 1];\n+\t\t\t$skip_next = 1;\n+\t\t\tnext;\n+\t\t}\n+\t\tif ($arg =~ /^--extcmd=/) {\n+\t\t\t$ENV{GIT_DIFFTOOL_EXTCMD} = substr($arg, 9);\n+\t\t\tnext;\n+\t\t}\n \t\tif ($arg eq '-g' || $arg eq '--gui') {\n \t\t\tmy $tool = Git::command_oneline('config',\n \t\t\t                                'diff.guitool');\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex 1d9e07b..69e1c34 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -225,8 +225,16 @@ test_expect_success 'difftool.<tool>.path' '\n test_expect_success 'difftool --extcmd=cat' '\n \tdiff=$(git difftool --no-prompt --extcmd=cat branch) &&\n \ttest \"$diff\" = branch\"$LF\"master\n+'\n \n+test_expect_success 'difftool --extcmd cat' '\n+\tdiff=$(git difftool --no-prompt --extcmd cat branch) &&\n+\ttest \"$diff\" = branch\"$LF\"master\n+'\n \n+test_expect_success 'difftool -x cat' '\n+\tdiff=$(git difftool --no-prompt -x cat branch) &&\n+\ttest \"$diff\" = branch\"$LF\"master\n \n \n '\n-- \n1.6.6.6.g627fb.dirty\n"},{"id":"131787","messageId":"1263593024-12093-3-git-send-email-davvid@gmail.com","threadId":"22236","inReplyTo":"1263593024-12093-1-git-send-email-davvid@gmail.com","subject":"[PATCH v2 3/3] difftool: Use eval to expand '--extcmd' expressions","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2010-01-15T22:03:44Z","receivedAt":"2010-01-15T22:03:44Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"It was not possible to pass quoted commands to '--extcmd'.\nBy using 'eval' we ensure that expressions with spaces and\nquotes are supported.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nUpdates since v1:\n* Uses a more readable quoting style as suggested by J6t.\n* We no longer use a subshell.\n\n git-difftool--helper.sh |    3 +--\n t/t7800-difftool.sh     |   13 +++++++++++++\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/git-difftool--helper.sh b/git-difftool--helper.sh\nindex d806eae..a1c5c09 100755\n--- a/git-difftool--helper.sh\n+++ b/git-difftool--helper.sh\n@@ -48,11 +48,10 @@ launch_merge_tool () {\n \tfi\n \n \tif use_ext_cmd; then\n-\t\t$GIT_DIFFTOOL_EXTCMD \"$LOCAL\" \"$REMOTE\"\n+\t\teval $GIT_DIFFTOOL_EXTCMD '\"$LOCAL\"' '\"$REMOTE\"'\n \telse\n \t\trun_merge_tool \"$merge_tool\"\n \tfi\n-\n }\n \n if ! use_ext_cmd; then\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex 69e1c34..a183f1d 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -235,8 +235,21 @@ test_expect_success 'difftool --extcmd cat' '\n test_expect_success 'difftool -x cat' '\n \tdiff=$(git difftool --no-prompt -x cat branch) &&\n \ttest \"$diff\" = branch\"$LF\"master\n+'\n+\n+test_expect_success 'difftool --extcmd echo arg1' '\n+\tdiff=$(git difftool --no-prompt --extcmd sh\\ -c\\ \\\"echo\\ \\$1\\\" branch)\n+\ttest \"$diff\" = file\n+'\n \n+test_expect_success 'difftool --extcmd cat arg1' '\n+\tdiff=$(git difftool --no-prompt --extcmd sh\\ -c\\ \\\"cat\\ \\$1\\\" branch)\n+\ttest \"$diff\" = master\n+'\n \n+test_expect_success 'difftool --extcmd cat arg2' '\n+\tdiff=$(git difftool --no-prompt --extcmd sh\\ -c\\ \\\"cat\\ \\$2\\\" branch)\n+\ttest \"$diff\" = branch\n '\n \n test_done\n-- \n1.6.6.6.g627fb.dirty\n"}]}