mergetools: Simplify how we handle "vim" and "defaults"
PATCH 1/1 mergetools: Simplify how we handle "vim" and "defaults"
Remove the exceptions for "vim" and "defaults" in the mergetool library so that every filename in mergetools/ matches 1:1 with the name of a valid built-in tool.
Make common functions available in $MERGE_TOOLS_DIR/include/.
---
This should make things ok on platforms where we don't have symlinks.
Makefile | 2 +-
git-mergetool--lib.sh | 41 +++++++++++-----------------
mergetools/gvimdiff | 1 +
mergetools/gvimdiff2 | 1 +
mergetools/{defaults => include/defaults.sh} | 0
mergetools/{vim => include/vim.sh} | 0
mergetools/vimdiff | 1 +
mergetools/vimdiff2 | 1 +
8 files changed, 21 insertions(+), 26 deletions(-)
create mode 100644 mergetools/gvimdiff
create mode 100644 mergetools/gvimdiff2
rename mergetools/{defaults => include/defaults.sh} (100%)
rename mergetools/{vim => include/vim.sh} (100%)
create mode 100644 mergetools/vimdiff
create mode 100644 mergetools/vimdiff2Makefile +1 -1
@@ -2724,7 +2724,7 @@ install: all $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' + cp -R mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' ifndef NO_GETTEXT $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(localedir_SQ)' (cd po/build/locale && $(TAR) cf - .) | \
git-mergetool--lib.sh +16 -25
77 lines not on this page · raw message
mergetools/gvimdiff new file +1 -0
@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"
mergetools/gvimdiff2 new file +1 -0
@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"
mergetools/include/defaults.sh renamed from mergetools/defaults +0 -0
mergetools/include/vim.sh renamed from mergetools/vim +0 -0
mergetools/vimdiff new file +1 -0
@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"
mergetools/vimdiff2 new file +1 -0
@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"
Signature · 1 line
1.8.0.6.ge6f188f.dirty
Quoted 14 lines · David Aguilar
Remove the exceptions for "vim" and "defaults" in the mergetool library so that every filename in mergetools/ matches 1:1 with the name of a valid built-in tool.
Make common functions available in $MERGE_TOOLS_DIR/include/.
Signed-off-by David Aguilar <[email protected]>---
Makefile +0
-0
Makefile install: all · line 2727
Quoted 5 lines
Makefile +1
-1@@ -2724,7 +2724,7 @@ install: all $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' + cp -R mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
Shouldn't this be more like this?
$(INSTALL) -m 644 $(subst include,,$(wildcard mergetools/*)) \ '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' $(INSTALL) -m 644 mergetools/include/* \ '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include'
I'm not sure creating an 'include' directory actually buys us much over declaring that 'vimdiff' is the real script and the others just source it. Either way there is a single special entry in the mergetools directory.
Quoted 19 lines
Makefile +0
-0ifndef NO_GETTEXT $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(localedir_SQ)' (cd po/build/locale && $(TAR) cf - .) | \git-mergetool--lib.sh +2
-0@@ -1,5 +1,7 @@ #!/bin/sh # git-mergetool--lib is a library for common merge tool functions +MERGE_TOOLS_DIR="$(git --exec-path)/mergetools" + diff_mode() { test "$TOOL_MODE" = diff }@@ -44,25 +46,14 @@ valid_tool () { } setup_tool () {
git-mergetool--lib.sh valid_tool () { · line 49
Quoted 10 lines
git-mergetool--lib.sh +1
-9- case "$1" in - vim*|gvim*) - tool=vim - ;; - *) - tool="$1" - ;; - esac - mergetools="$(git --exec-path)/mergetools" + tool="$1"
Unnecessary quoting.
Quoted 16 lines
git-mergetool--lib.sh +3
-6- # Load the default definitions - . "$mergetools/defaults" - if ! test -f "$mergetools/$tool" + if ! test -f "$MERGE_TOOLS_DIR/$tool" then return 1 fi - - # Load the redefined functions - . "$mergetools/$tool" + . "$MERGE_TOOLS_DIR/include/defaults.sh" + . "$MERGE_TOOLS_DIR/$tool" if merge_mode && ! can_merge then
git-mergetool--lib.sh run_merge_tool () { · line 93
Quoted 5 lines
git-mergetool--lib.sh +1
-1@@ -99,7 +90,7 @@ run_merge_tool () { base_present="$2" status=0 - # Bring tool-specific functions into scope + # Bring tool specific functions into scope
This isn't related to this change (and I think tool-specific is more correct anyway).
Quoted 31 lines
git-mergetool--lib.sh +8
-9setup_tool "$1" if merge_mode@@ -177,18 +168,17 @@ list_merge_tool_candidates () { show_tool_help () { unavailable= available= LF=' ' - - scriptlets="$(git --exec-path)"/mergetools - for i in "$scriptlets"/* + for i in "$MERGE_TOOLS_DIR"/* do - . "$scriptlets"/defaults - . "$i" - - tool="$(basename "$i")" - if test "$tool" = "defaults" + if test -d "$i" then continue - elif merge_mode && ! can_merge + fi + + . "$MERGE_TOOLS_DIR"/include/defaults.sh + . "$i" + + if merge_mode && ! can_merge then continue elif diff_mode && ! can_diff
git-mergetool--lib.sh show_tool_help () { · line 187
Quoted 2 lines
git-mergetool--lib.sh +0
-0@@ -196,6 +186,7 @@ show_tool_help () { continue fi
I'd prefer to see my change to setup_tool done before this so that we can just use:
setup_tool "$tool" 2>/dev/null || continue
for the above block. I'll send a fixed version in a couple of minutes.
Quoted 40 lines
git-mergetool--lib.sh +1
-0+ tool=$(basename "$i") merge_tool_path=$(translate_merge_tool_path "$tool") if type "$merge_tool_path" >/dev/null 2>&1 thenmergetools/gvimdiff new file +1
-0@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"mergetools/gvimdiff2 new file +1
-0@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"mergetools/include/defaults.sh renamed from mergetools/defaults +0
-0mergetools/include/vim.sh renamed from mergetools/vim +0
-0mergetools/vimdiff new file +1
-0@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"mergetools/vimdiff2 new file +1
-0@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"
Quoted 3 lines · John Keeping
I'm not sure creating an 'include' directory actually buys us much over declaring that 'vimdiff' is the real script and the others just source it.
Is 'include' really used for such a purpose? It only houses defaults.sh as far as I can see.
As that defaults.sh file is used only to define trivially empty shell functions, I wonder if it is better to get rid of it, and define these functions in line in git-mergetool--lib.sh. Such a change would like the attached on top of the entire series.
Makefile | 6 +----- git-mergetool--lib.sh | 24 ++++++++++++++++++++++-- mergetools/include/defaults.sh | 22 ---------------------- 3 files changed, 23 insertions(+), 29 deletions(-)
Makefile +1 -5
@@ -2724,11 +2724,7 @@ install: all $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -m 644 $(filter-out mergetools/include,$(wildcard mergetools/*)) \ - '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' - $(INSTALL) -m 644 mergetools/include/* \ - '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' + $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' ifndef NO_GETTEXT $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(localedir_SQ)' (cd po/build/locale && $(TAR) cf - .) | \
git-mergetool--lib.sh +22 -2
@@ -57,8 +57,28 @@ setup_tool () { return 2 fi - # Load the default functions - . "$MERGE_TOOLS_DIR/include/defaults.sh" + # Fallback definitions, to be overriden by tools. + can_merge () { + return 0 + } + + can_diff () { + return 0 + } + + diff_cmd () { + status=1 + return $status + } + + merge_cmd () { + status=1 + return $status + } + + translate_merge_tool_path () { + echo "$1" + } # Load the redefined functions . "$MERGE_TOOLS_DIR/$tool"
mergetools/include/defaults.sh deleted +0 -22
@@ -1,22 +0,0 @@ -# Redefined by builtin tools -can_merge () { - return 0 -} - -can_diff () { - return 0 -} - -diff_cmd () { - status=1 - return $status -} - -merge_cmd () { - status=1 - return $status -} - -translate_merge_tool_path () { - echo "$1" -}
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · John Keeping
I'm not sure creating an 'include' directory actually buys us much over declaring that 'vimdiff' is the real script and the others just source it.
Quoted 7 lines
Is 'include' really used for such a purpose? It only houses
defaults.shas far as I can see.As that
defaults.shfile is used only to define trivially empty shell functions, I wonder if it is better to get rid of it, and define these functions in line ingit-mergetool--lib.sh. Such a change would like the attached on top of the entire series.
I think that's much better.
Quoted 85 lines
Makefile | 6 +----- git-mergetool--lib.sh | 24 ++++++++++++++++++++++-- mergetools/include/defaults.sh | 22 ---------------------- 3 files changed, 23 insertions(+), 29 deletions(-)Makefile +1
-5@@ -2724,11 +2724,7 @@ install: all $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -m 644 $(filter-out mergetools/include,$(wildcard mergetools/*)) \ - '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' - $(INSTALL) -m 644 mergetools/include/* \ - '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' + $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' ifndef NO_GETTEXT $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(localedir_SQ)' (cd po/build/locale && $(TAR) cf - .) | \git-mergetool--lib.sh +22
-2@@ -57,8 +57,28 @@ setup_tool () { return 2 fi - # Load the default functions - . "$MERGE_TOOLS_DIR/include/defaults.sh" + # Fallback definitions, to be overriden by tools. + can_merge () { + return 0 + } + + can_diff () { + return 0 + } + + diff_cmd () { + status=1 + return $status + } + + merge_cmd () { + status=1 + return $status + } + + translate_merge_tool_path () { + echo "$1" + } # Load the redefined functions . "$MERGE_TOOLS_DIR/$tool"mergetools/include/defaults.sh deleted +0
-22@@ -1,22 +0,0 @@ -# Redefined by builtin tools -can_merge () { - return 0 -} - -can_diff () { - return 0 -} - -diff_cmd () { - status=1 - return $status -} - -merge_cmd () { - status=1 - return $status -} - -translate_merge_tool_path () { - echo "$1" -}
Signature · 1 line
David
Quoted 10 lines · David Aguilar
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · John Keeping
I'm not sure creating an 'include' directory actually buys us much over declaring that 'vimdiff' is the real script and the others just source it.
Is 'include' really used for such a purpose? It only houses
defaults.shas far as I can see.
Quoted 6 lines
Quoted 4 lines
As that
defaults.shfile is used only to define trivially empty shell functions, I wonder if it is better to get rid of it, and define these functions in line ingit-mergetool--lib.sh. Such a change would like the attached on top of the entire series.I think that's much better.
Would you like me to put this together into a proper patch?
You can also squash it in (along with a removal of the last line of the commit message) if you prefer.
Quoted 85 lines
Quoted 85 lines
Makefile | 6 +----- git-mergetool--lib.sh | 24 ++++++++++++++++++++++-- mergetools/include/defaults.sh | 22 ---------------------- 3 files changed, 23 insertions(+), 29 deletions(-)Makefile +1
-5@@ -2724,11 +2724,7 @@ install: all $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -m 644 $(filter-out mergetools/include,$(wildcard mergetools/*)) \ - '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' - $(INSTALL) -m 644 mergetools/include/* \ - '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' + $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' ifndef NO_GETTEXT $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(localedir_SQ)' (cd po/build/locale && $(TAR) cf - .) | \git-mergetool--lib.sh +22
-2@@ -57,8 +57,28 @@ setup_tool () { return 2 fi - # Load the default functions - . "$MERGE_TOOLS_DIR/include/defaults.sh" + # Fallback definitions, to be overriden by tools. + can_merge () { + return 0 + } + + can_diff () { + return 0 + } + + diff_cmd () { + status=1 + return $status + } + + merge_cmd () { + status=1 + return $status + } + + translate_merge_tool_path () { + echo "$1" + } # Load the redefined functions . "$MERGE_TOOLS_DIR/$tool"mergetools/include/defaults.sh deleted +0
-22@@ -1,22 +0,0 @@ -# Redefined by builtin tools -can_merge () { - return 0 -} - -can_diff () { - return 0 -} - -diff_cmd () { - status=1 - return $status -} - -merge_cmd () { - status=1 - return $status -} - -translate_merge_tool_path () { - echo "$1" -}
Signature · 1 line
David
Quoted 6 lines · David Aguilar
Quoted 1 line
I think that's much better.
Would you like me to put this together into a proper patch?
You can also squash it in (along with a removal of the last line of the commit message) if you prefer.
I was lazy and didn't want to think about rewriting your log message, so I just queued it with this log message on top.
mergetools: remove mergetools/include/defaults.sh
This and its containing directory are used only to define trivial fallback definition of five shell functions in a single script. Defining them in-line at the location that wants to have them makes the result much easier to read.
But as you said, removing the last line of your log message and squashing the change into it would be more preferrable. Let me do that later.
Thanks.
Quoted 129 lines · John Keeping
Quoted 14 lines · David Aguilar
Remove the exceptions for "vim" and "defaults" in the mergetool library so that every filename in mergetools/ matches 1:1 with the name of a valid built-in tool.
Make common functions available in $MERGE_TOOLS_DIR/include/.
Signed-off-by David Aguilar <[email protected]>---
Makefile +0
-0Makefile install: all · line 2727
Quoted 5 lines
Makefile +1
-1@@ -2724,7 +2724,7 @@ install: all $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' + cp -R mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'Shouldn't this be more like this?
$(INSTALL) -m 644 $(subst include,,$(wildcard mergetools/*)) \ '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' $(INSTALL) -m 644 mergetools/include/* \ '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include'I'm not sure creating an 'include' directory actually buys us much over declaring that 'vimdiff' is the real script and the others just source it. Either way there is a single special entry in the mergetools directory.
Quoted 19 lines
Makefile +0
-0ifndef NO_GETTEXT $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(localedir_SQ)' (cd po/build/locale && $(TAR) cf - .) | \git-mergetool--lib.sh +2
-0@@ -1,5 +1,7 @@ #!/bin/sh # git-mergetool--lib is a library for common merge tool functions +MERGE_TOOLS_DIR="$(git --exec-path)/mergetools" + diff_mode() { test "$TOOL_MODE" = diff }@@ -44,25 +46,14 @@ valid_tool () { } setup_tool () {git-mergetool--lib.sh valid_tool () { · line 49
Quoted 10 lines
git-mergetool--lib.sh +1
-9- case "$1" in - vim*|gvim*) - tool=vim - ;; - *) - tool="$1" - ;; - esac - mergetools="$(git --exec-path)/mergetools" + tool="$1"Unnecessary quoting.
Quoted 16 lines
git-mergetool--lib.sh +3
-6- # Load the default definitions - . "$mergetools/defaults" - if ! test -f "$mergetools/$tool" + if ! test -f "$MERGE_TOOLS_DIR/$tool" then return 1 fi - - # Load the redefined functions - . "$mergetools/$tool" + . "$MERGE_TOOLS_DIR/include/defaults.sh" + . "$MERGE_TOOLS_DIR/$tool" if merge_mode && ! can_merge thengit-mergetool--lib.sh run_merge_tool () { · line 93
Quoted 5 lines
git-mergetool--lib.sh +1
-1@@ -99,7 +90,7 @@ run_merge_tool () { base_present="$2" status=0 - # Bring tool-specific functions into scope + # Bring tool specific functions into scopeThis isn't related to this change (and I think tool-specific is more correct anyway).
Quoted 31 lines
git-mergetool--lib.sh +8
-9setup_tool "$1" if merge_mode@@ -177,18 +168,17 @@ list_merge_tool_candidates () { show_tool_help () { unavailable= available= LF=' ' - - scriptlets="$(git --exec-path)"/mergetools - for i in "$scriptlets"/* + for i in "$MERGE_TOOLS_DIR"/* do - . "$scriptlets"/defaults - . "$i" - - tool="$(basename "$i")" - if test "$tool" = "defaults" + if test -d "$i" then continue - elif merge_mode && ! can_merge + fi + + . "$MERGE_TOOLS_DIR"/include/defaults.sh + . "$i" + + if merge_mode && ! can_merge then continue elif diff_mode && ! can_diffgit-mergetool--lib.sh show_tool_help () { · line 187
Quoted 2 lines
git-mergetool--lib.sh +0
-0@@ -196,6 +186,7 @@ show_tool_help () { continue fiI'd prefer to see my change to
setup_tooldone before this so that we can just use:
Quoted 3 lines
setup_tool "$tool" 2>/dev/null || continuefor the above block. I'll send a fixed version in a couple of minutes.
I'll reroll this patch with your notes on top of your new patch later today.
Thanks (and thanks for the Makefile hint.. I knew it was wrong! ;-).
Quoted 41 lines
Quoted 41 lines
git-mergetool--lib.sh +1
-0+ tool=$(basename "$i") merge_tool_path=$(translate_merge_tool_path "$tool") if type "$merge_tool_path" >/dev/null 2>&1 thenmergetools/gvimdiff new file +1
-0@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"mergetools/gvimdiff2 new file +1
-0@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"mergetools/include/defaults.sh renamed from mergetools/defaults +0
-0mergetools/include/vim.sh renamed from mergetools/vim +0
-0mergetools/vimdiff new file +1
-0@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"mergetools/vimdiff2 new file +1
-0@@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/include/vim.sh"
Signature · 1 line
David
Quoted 21 lines · David Aguilar
Quoted 20 lines · John Keeping
Makefile install: all · line 2727
Quoted 10 lines · David Aguilar
Makefile +1
-1@@ -2724,7 +2724,7 @@ install: all $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' - $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' + cp -R mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'Shouldn't this be more like this?
$(INSTALL) -m 644 $(subst include,,$(wildcard mergetools/*)) \ '$(DESTDIR_SQ)$(mergetools_instdir_SQ)' $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include' $(INSTALL) -m 644 mergetools/include/* \ '$(DESTDIR_SQ)$(mergetools_instdir_SQ)/include'
Quoted 6 lines
Quoted 4 lines
I'm not sure creating an 'include' directory actually buys us much over declaring that 'vimdiff' is the real script and the others just source it. Either way there is a single special entry in the mergetools directory.
Thanks (and thanks for the
Makefilehint.. I knew it was wrong! ;-).
I think that version's still not right actually, the first line should probably use filter-out not subst:
$(INSTALL) -m 644 $(filter-out include,$(wildcard mergetools/*)) \ '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
John