Subject: Re: [PATCH] fast-import: add options to enable/disable case folding

From: Eric Sunshine <[email-masked]>
Date: Fri, 17 Apr 2015 15:57:05 -0400

On Fri, Apr 17, 2015 at 06:56:43PM +0200, Torsten Bögershausen wrote:
> On 04/17/2015 01:52 PM, Mike Hommey wrote:
> > +test_expect_success 'V: default case folding with ignorecase=true' '
> > +	git config core.ignorecase true &&
> > +	git fast-import <input &&
> > +	git ls-tree refs/heads/V >actual &&
> > +	git update-ref -d refs/heads/V &&
> > +	cat >expected <<\EOF &&
> > +100644 blob 78981922613b2afb6025042ff6bd878ac1994e85	a
> > +EOF
> > +	test_cmp expected actual'
> > +
> > +test_expect_success 'V: default case folding with ignorecase=false' '
> > +	git config core.ignorecase false &&
> > +	git fast-import <input &&
> > +	git ls-tree refs/heads/V >actual &&
> > +	git update-ref -d refs/heads/V &&
> > +	cat >expected <<\EOF &&
> > +100644 blob 78981922613b2afb6025042ff6bd878ac1994e85	A
> > +EOF
> > +	test_cmp expected actual'
> > +
> > +test_expect_success 'V: forced case folding with ignorecase=true' '
> > +	git config core.ignorecase true &&
> > +	git fast-import --fold-case <input &&
> > +	git ls-tree refs/heads/V >actual &&
> > +	git update-ref -d refs/heads/V &&
> > +	cat >expected <<\EOF &&
> > +100644 blob 78981922613b2afb6025042ff6bd878ac1994e85	a
> > +EOF
> > +	test_cmp expected actual'
>
> If you want to make it shorter (and try to avoid repetition):
> The forced true cases could be collected in a loop.
> (and the same for forced=false)

I was also going to suggest squashing the repetition. Here's what I
had in mind:

--- >8 ---
test_foldcase() {
	ignore=$1 &&
	case "$2" in
	true) fold=--fold-case folded=true ;;
	false) fold=--no-fold-case folded=false ;;
	*) fold= folded=$ignore ;;
	esac &&
	case $folded in true) folded=a ;; false) folded=A ;; esac &&

	test_expect_success "V: case folding: ignorecase=$ignore${fold:+ $fold}" "
		git -c core.ignorecase=$ignore fast-import $fold <input &&
		git ls-tree refs/heads/V >actual &&
		git update-ref -d refs/heads/V &&
		cat >expect <<-EOF &&
		100644 blob 78981922613b2afb6025042ff6bd878ac1994e85	$folded
		EOF
		test_cmp expect actual
	"
}

for o in '' true false
do
	for c in true false
	do
		test_foldcase $c "$o"
	done
done
--- >8 ---

which outputs:

--- >8 ---
ok 176 - V: case folding: ignorecase=true
ok 177 - V: case folding: ignorecase=false
ok 178 - V: case folding: ignorecase=true --fold-case
ok 179 - V: case folding: ignorecase=false --fold-case
ok 180 - V: case folding: ignorecase=true --no-fold-case
ok 181 - V: case folding: ignorecase=false --no-fold-case
--- >8 ---