From: David Aguilar <davvid@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, David Aguilar <davvid@gmail.com>
Subject: [PATCH 3/8] sh-tools: add a git-sh-tools shell helper script
Date: Sun, 29 Mar 2009 22:03:43 -0700 [thread overview]
Message-ID: <1238389428-69328-4-git-send-email-davvid@gmail.com> (raw)
In-Reply-To: <1238389428-69328-3-git-send-email-davvid@gmail.com>
git-sh-tools holds functions common to the git-*tool commands.
Signed-off-by: David Aguilar <davvid@gmail.com>
---
.gitignore | 1 +
Documentation/git-sh-tools.txt | 49 +++++++++++++++++++++++++++++++++++++++
Makefile | 1 +
command-list.txt | 1 +
git-sh-tools.sh | 50 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 102 insertions(+), 0 deletions(-)
create mode 100644 Documentation/git-sh-tools.txt
create mode 100644 git-sh-tools.sh
diff --git a/.gitignore b/.gitignore
index 966c886..cecf77e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,6 +114,7 @@ git-rm
git-send-email
git-send-pack
git-sh-setup
+git-sh-tools
git-shell
git-shortlog
git-show
diff --git a/Documentation/git-sh-tools.txt b/Documentation/git-sh-tools.txt
new file mode 100644
index 0000000..055a10c
--- /dev/null
+++ b/Documentation/git-sh-tools.txt
@@ -0,0 +1,49 @@
+git-sh-tool(1)
+==============
+
+NAME
+----
+git-sh-tools - Common git *tool shell script functions
+
+SYNOPSIS
+--------
+'. "$(git --exec-path)/git-sh-tools"'
+
+DESCRIPTION
+-----------
+
+This is not a command the end user would want to run. Ever.
+This documentation is meant for people who are studying the
+Porcelain-ish scripts and/or are writing new ones.
+
+The 'git-sh-tools' scriptlet is designed to be sourced (using
+`.`) by other shell scripts to set up some functions for
+working with git merge/diff tools.
+
+Before sourcing it, your script should set up a few variables;
+`TOOL_MODE` is used to define the operation mode for various
+functions. 'diff' and 'merge' are valid values.
+
+FUNCTIONS
+---------
+valid_tool::
+ verifies that the specified merge tool is properly setup.
+
+valid_custom_tool::
+ verifies that a '(diff|merge)tool.<tool>.cmd' configuration exists.
+
+init_merge_tool_path::
+ sets up `$merge_tool_path` according to '(diff|merge)tool.<tool>.path'
+ configurations.
+
+Author
+------
+Written by David Aguilar <davvid@gmail.com>
+
+Documentation
+--------------
+Documentation by David Aguilar and the git-list <git@vger.kernel.org>.
+
+GIT
+---
+Part of the linkgit:git[1] suite
diff --git a/Makefile b/Makefile
index d77fd71..3b7c20f 100644
--- a/Makefile
+++ b/Makefile
@@ -292,6 +292,7 @@ SCRIPT_SH += git-rebase.sh
SCRIPT_SH += git-repack.sh
SCRIPT_SH += git-request-pull.sh
SCRIPT_SH += git-sh-setup.sh
+SCRIPT_SH += git-sh-tools.sh
SCRIPT_SH += git-stash.sh
SCRIPT_SH += git-submodule.sh
SCRIPT_SH += git-web--browse.sh
diff --git a/command-list.txt b/command-list.txt
index fb03a2e..c3b6c87 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -109,6 +109,7 @@ git-show-branch ancillaryinterrogators
git-show-index plumbinginterrogators
git-show-ref plumbinginterrogators
git-sh-setup purehelpers
+git-sh-tools purehelpers
git-stash mainporcelain
git-status mainporcelain common
git-stripspace purehelpers
diff --git a/git-sh-tools.sh b/git-sh-tools.sh
new file mode 100644
index 0000000..234bac7
--- /dev/null
+++ b/git-sh-tools.sh
@@ -0,0 +1,50 @@
+# Verifies that the chosen merge tool is properly setup.
+# Built-in merge tools are always valid.
+valid_tool() {
+ case "$1" in
+ kdiff3 | kompare | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | ecmerge)
+ ;; # happy
+ *)
+ if ! valid_custom_tool "$1"; then
+ return 1
+ fi
+ ;;
+ esac
+}
+
+# Verifies that (difftool|mergetool).<tool>.cmd exists
+# Requires $TOOL_MODE to be set.
+valid_custom_tool() {
+ if test "$TOOL_MODE" = "diff"; then
+ merge_tool_cmd="$(git config difftool.$1.cmd)"
+ test -z "$merge_tool_cmd" &&
+ merge_tool_cmd="$(git config mergetool.$1.cmd)"
+ test -n "$merge_tool_cmd"
+ elif test "$TOOL_MODE" = "merge"; then
+ merge_tool_cmd="$(git config mergetool.$1.cmd)"
+ test -n "$merge_tool_cmd"
+ fi
+}
+
+
+# Set up $merge_tool_path for (diff|merge)tool.<tool>.path configurations
+init_merge_tool_path() {
+ if test "$TOOL_MODE" = "diff"; then
+ merge_tool_path=$(git config difftool."$1".path)
+ test -z "$merge_tool_path" &&
+ merge_tool_path=$(git config mergetool."$1".path)
+ elif test "$TOOL_MODE" = "merge"; then
+ merge_tool_path=$(git config mergetool."$1".path)
+ fi
+
+ if test -z "$merge_tool_path" ; then
+ case "$1" in
+ emerge)
+ merge_tool_path=emacs
+ ;;
+ *)
+ merge_tool_path=$1
+ ;;
+ esac
+ fi
+}
--
1.6.1.3
next prev parent reply other threads:[~2009-03-30 5:05 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-30 5:03 (unknown), David Aguilar
2009-03-30 5:03 ` [PATCH 1/8] mergetool: use tabs consistently David Aguilar
2009-03-30 5:03 ` [PATCH 2/8] mergetool: use $( ... ) instead of `backticks` David Aguilar
2009-03-30 5:03 ` David Aguilar [this message]
2009-03-30 5:03 ` [PATCH 4/8] mergetool: refactor git-mergetool to use git-sh-tools David Aguilar
2009-03-30 5:03 ` [PATCH 5/8] difftool: refactor git-difftool " David Aguilar
2009-03-30 5:03 ` [PATCH 6/8] sh-tools: add a run_merge_tool function David Aguilar
2009-03-30 5:03 ` [PATCH 7/8] mergetool: refactor git-mergetool to use run_merge_tool David Aguilar
2009-03-30 5:03 ` [PATCH 8/8] difftool: refactor git-difftool-helper " David Aguilar
2009-03-30 6:55 ` [PATCH 6/8] sh-tools: add a run_merge_tool function Markus Heidelberg
2009-03-30 7:32 ` Markus Heidelberg
2009-03-30 7:46 ` David Aguilar
2009-03-30 8:44 ` [PATCH 1/8] mergetool: use tabs consistently Junio C Hamano
2009-03-30 9:22 ` David Aguilar
2009-03-30 21:35 ` Charles Bailey
2009-03-31 6:36 ` David Aguilar
2009-04-01 17:56 ` Junio C Hamano
2009-03-30 7:02 ` Markus Heidelberg
2009-03-30 8:46 ` Re: Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1238389428-69328-4-git-send-email-davvid@gmail.com \
--to=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.