threads / rfc / 13989

RFC v3Remove the use of '--' in merge program invocation

Subject: [PATCH v3/RFC] Remove the use of '--' in merge program invocation

## tl;dr

3 messages between Jun 16, 2008 and Jun 17, 2008. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Patrick Higgins· Jun 16, 2008, 23:33 UTC · lore

Put a "./" at the beginning of all paths given to the merge program so that filenames beginning with a '-' character don't get interpreted as options.

This deals with a problem where kdiff3 can be compiled with or without support for the '--' separator between options and filenames.

Signed-off-by: Patrick Higgins <patrick.higgins@cexp.com>
---

This is applying Junio's idea because my earlier attempts would fail on files that started with a dash. This should work for those files with kdiff3 compiled with or without '--' support, does not require any additional overhead to determine if kdiff3 has that support, and the technique should work for all merge programs in case any others have the problem kdiff3 has.

My only concern is if 'git ls-files -u' ever returns absolute paths, then this will not work.

 git-mergetool.sh |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)
Show changes to git-mergetool.sh +12 −12
diff --git a/git-mergetool.sh b/git-mergetool.sh
index fcdec4a..94187c3 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -141,10 +141,10 @@ merge_file () {
     fi
 
     ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')"
-    BACKUP="$MERGED.BACKUP.$ext"
-    LOCAL="$MERGED.LOCAL.$ext"
-    REMOTE="$MERGED.REMOTE.$ext"
-    BASE="$MERGED.BASE.$ext"
+    BACKUP="./$MERGED.BACKUP.$ext"
+    LOCAL="./$MERGED.LOCAL.$ext"
+    REMOTE="./$MERGED.REMOTE.$ext"
+    BASE="./$MERGED.BASE.$ext"
 
     mv -- "$MERGED" "$BACKUP"
     cp -- "$BACKUP" "$MERGED"
@@ -183,29 +183,29 @@ merge_file () {
 	kdiff3)
 	    if base_present ; then
 		("$merge_tool_path" --auto --L1 "$MERGED (Base)" --L2 "$MERGED (Local)" --L3 "$MERGED (Remote)" \
-		    -o "$MERGED" -- "$BASE" "$LOCAL" "$REMOTE" > /dev/null 2>&1)
+		    -o "$MERGED" "$BASE" "$LOCAL" "$REMOTE" > /dev/null 2>&1)
 	    else
 		("$merge_tool_path" --auto --L1 "$MERGED (Local)" --L2 "$MERGED (Remote)" \
-		    -o "$MERGED" -- "$LOCAL" "$REMOTE" > /dev/null 2>&1)
+		    -o "$MERGED" "$LOCAL" "$REMOTE" > /dev/null 2>&1)
 	    fi
 	    status=$?
 	    ;;
 	tkdiff)
 	    if base_present ; then
-		"$merge_tool_path" -a "$BASE" -o "$MERGED" -- "$LOCAL" "$REMOTE"
+		"$merge_tool_path" -a "$BASE" -o "$MERGED" "$LOCAL" "$REMOTE"
 	    else
-		"$merge_tool_path" -o "$MERGED" -- "$LOCAL" "$REMOTE"
+		"$merge_tool_path" -o "$MERGED" "$LOCAL" "$REMOTE"
 	    fi
 	    status=$?
 	    ;;
 	meld|vimdiff)
 	    touch "$BACKUP"
-	    "$merge_tool_path" -- "$LOCAL" "$MERGED" "$REMOTE"
+	    "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
 	    check_unchanged
 	    ;;
 	gvimdiff)
 	    touch "$BACKUP"
-	    "$merge_tool_path" -f -- "$LOCAL" "$MERGED" "$REMOTE"
+	    "$merge_tool_path" -f "$LOCAL" "$MERGED" "$REMOTE"
 	    check_unchanged
 	    ;;
 	xxdiff)
@@ -215,13 +215,13 @@ merge_file () {
 		    -R 'Accel.SaveAsMerged: "Ctrl-S"' \
 		    -R 'Accel.Search: "Ctrl+F"' \
 		    -R 'Accel.SearchForward: "Ctrl-G"' \
-		    --merged-file "$MERGED" -- "$LOCAL" "$BASE" "$REMOTE"
+		    --merged-file "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
 	    else
 		"$merge_tool_path" -X --show-merged-pane \
 		    -R 'Accel.SaveAsMerged: "Ctrl-S"' \
 		    -R 'Accel.Search: "Ctrl+F"' \
 		    -R 'Accel.SearchForward: "Ctrl-G"' \
-		    --merged-file "$MERGED" -- "$LOCAL" "$REMOTE"
+		    --merged-file "$MERGED" "$LOCAL" "$REMOTE"
 	    fi
 	    check_unchanged
 	    ;;
-- 
1.5.6.rc2
Junio C Hamano· Jun 17, 2008, 00:05 UTC · re: Patrick Higgins · lore

Re: [PATCH v3/RFC] Remove the use of '--' in merge program invocation

Patrick Higgins <patrick.higgins@cexp.com> writes:
Show 18 quoted lines
> Put a "./" at the beginning of all paths given to the merge program so
> that filenames beginning with a '-' character don't get interpreted as
> options.
>
> This deals with a problem where kdiff3 can be compiled with or without
> support for the '--' separator between options and filenames.
>
> Signed-off-by: Patrick Higgins <patrick.higgins@cexp.com>
> ---
>
> This is applying Junio's idea because my earlier attempts would fail on files
> that started with a dash. This should work for those files with kdiff3
> compiled with or without '--' support, does not require any additional
> overhead to determine if kdiff3 has that support, and the technique should
> work for all merge programs in case any others have the problem kdiff3 has.
>
> My only concern is if 'git ls-files -u' ever returns absolute paths,
> then this will not work.

What do you mean by "absolute paths"? The path git proper deals with is always relative to the root of the repository's work tree, so you won't be seeing "/home/patrick/src/Makefile" from ls-files if that is what you are worried about.

This change applies to all the backends not just kdiff3; people who use different merge backends please give success (or breakage) reports.

Thanks.
patrick.higgins@cexp.com· Jun 17, 2008, 16:52 UTC · re: Junio C Hamano · lore

RE: [PATCH v3/RFC] Remove the use of '--' in merge program invocation

From: Junio C Hamano [mailto:gitster@pobox.com]
Show 13 quoted lines
> 
> Patrick Higgins <patrick.higgins@cexp.com> writes:
> 
> > My only concern is if 'git ls-files -u' ever returns absolute paths,
> > then this will not work.
> 
> What do you mean by "absolute paths"?  The path git proper 
> deals with is
> always relative to the root of the repository's work tree, so 
> you won't be
> seeing "/home/patrick/src/Makefile" from ls-files if that is 
> what you are
> worried about.
Yes, that's what I was worried about. Glad to hear that won't ever happen.

← back to recent threads