git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/4] mergetools/meld: Use '--output' when available

From
David Aguilar <davvid@gmail.com>
Date
Aug 18, 2011, 09:24 UTC
Message-ID
<20110818092403.GB15416@gmail.com>
In-Reply-To
<20110818081309.GP31888@elie.gateway.2wire.net>
On Thu, Aug 18, 2011 at 03:13:10AM -0500, Jonathan Nieder wrote:
Show 19 quoted lines
> David Aguilar wrote:
> 
> > use the '--output' option when available.
> 
> Yay. :)
> 
> > --- a/mergetools/meld
> > +++ b/mergetools/meld
> > @@ -4,6 +4,37 @@ diff_cmd () {
> >  
> >  merge_cmd () {
> >  	touch "$BACKUP"
> > -	"$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
> > +	if test "$meld_has_output_option" = true
> > +	then
> > +		"$merge_tool_path" --output "$MERGED" \
> > +			"$BASE" "$LOCAL" "$REMOTE"
> 
> Shouldn't this be "$LOCAL" "$BASE" "$REMOTE"?
Yup, thanks.
Show 19 quoted lines
> 
> > +	else
> > +		"$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
> > +	fi
> >  	check_unchanged
> 
> I wonder if the version test could be made a little simpler (perhaps
> to cope better if future versions use a different numbering system):
> 
> 	if "$merge_tool_path" --output /dev/null --help >/dev/null 2>&1
> 	then
> 		"$merge_tool_path" --output ...
> 	else
> 		"$merge_tool_path" "$LOCAL" ...
> 	fi
> 
> Forgive my ignorance: is this function likely to be called in a loop?
> If so, it makes sense to precompute or cache the result of detection,
> like you already do.
Yes, it is called in a loop...
Show 50 quoted lines
> 	check_meld_for_output_option () {
> 		if ...
> 		then
> 			meld_has_output_option=true
> 		else
> 			meld_has_output_option=false
> 		fi
> 	}
> 
> 	merge_cmd () {
> 		if test -z "${meld_has_output_option:+set}"
> 		then
> 			check_meld_for_output_option
> 		fi
> 
> 		if test "$meld_has_output_option" = true
> 		then
> 			...
> 
> 
> [...]
> > +	# Filter meld --version to contain numbers and dots only
> > +	meld="$(meld --version 2>/dev/null | sed -e 's/[^0-9.]\+//g')"
> 
> \+ is not a BRE.  If parsing version numbers seems like the right
> thing to do, maybe "tr -cd 0-9."?
> 
> > +	meld="${meld:-0.0.0}"
> > +
> > +	meld_major="$(expr "$meld" : '\([0-9]\{1,\}\)' || echo 0)"
> > +	meld_minor="$(expr "$meld" : '[0-9]\{1,\}\.\([0-9]\{1,\}\)' || echo 0)"
> 
> I think git avoids \{m,n\} ranges where possible (for portability).
> This could be:
> 
> 	meld_major=${meld%%.*}
> 	meld_nonmajor=${meld#${meld_major}.}
> 	meld_minor=${meld_nonmajor%%.*}
> 
> or:
> 
> 	case $meld in
> 	[2-9].* | [1-9][0-9]* | 1.[5-9]* | 1.[1-9][0-9]*)	# >= 1.5.0
> 		meld_has_output_option=true ;;
> 	*)
> 		meld_has_output_option=false ;;
> 	esac
> 
> It's nice how self-contained this can be now that it's in its own
> file.  Thanks.

Right, I was using \{1,\} since that's what CodingStyle said to use instead of \+ (which I forgot to fixup above as you saw).

The case statement is nice and simple enough to understand. By doing meld --output /dev/null --help we're relying on older versions blowing up with --output and --help returning exit status 0. That seems pretty reasonable. The case statement does seem sufficient but just trying --output and seeing what happens is even simpler. Your example also uses $merge_tool_path, which I forgot to do, so I'll be sure to include that too.

I'll wait until tomorrow to see if there are any more comments and reroll.

Thanks,
-- 
					David
Previous: Jonathan NiederNext: David Aguilar
Message 15 of 18 in “Refactor git-mergetool--lib.sh”
  1. 0/4 Refactor git-mergetool--lib.shDavid Aguilar, Aug 18, 2011
  2. 1/4 difftool--helper: Make style consistent with gitDavid Aguilar, Aug 18, 2011
  3. Sebastian SchuberthAug 18, 2011
  4. David AguilarAug 18, 2011
  5. Junio C HamanoAug 18, 2011
  6. 2/4 mergetool--lib: Make style consistent with gitDavid Aguilar, Aug 18, 2011
  7. 3/4 mergetool--lib: Refactor tools into separate filesDavid Aguilar, Aug 18, 2011
  8. Makefile: fix permissions of mergetools/ checked out with permissive umaskJonathan Nieder, Oct 9, 2011
  9. Jonathan NiederOct 9, 2011
  10. David AguilarOct 9, 2011
  11. Jonathan NiederOct 9, 2011
  12. Junio C HamanoOct 11, 2011
  13. 4/4 mergetools/meld: Use '--output' when availableDavid Aguilar, Aug 18, 2011
  14. Jonathan NiederAug 18, 2011
  15. David AguilarAug 18, 2011
  16. 4/4 mergetools/meld: Use '--output' when availableDavid Aguilar, Aug 19, 2011
  17. Junio C HamanoAug 19, 2011
  18. Sebastian SchuberthAug 18, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.