On Thu, Oct 20, 2016 at 12:54:32PM -0700, Stefan Beller wrote:

> Maybe we should stop introducing un-optimized tests.
> [...]
> * heavy use of the "git -C <dir>" pattern. When applying that
>   thouroughly we'd save spanning the subshells.

Yeah, I imagine with some style changes we could drop quite a few
subshells. The problem is that the conversion work is manual and
tedious. I'd look first for spots where we can eliminate thousands of
calls with a single change.

> That said I really like the idea of having a helper that would eliminate the 
> cat
> for you, e.g. :
> 
> git_test_helper_equal_stdin_or_diff_and_die -C super_repo status
> --porcelain=v2 --branch --untracked-files=all <<-EOF
> 1 A. N... 000000 100644 100644 $_z40 $HMOD .gitmodules
> 1 AM S.M. 000000 160000 160000 $_z40 $HSUP sub1
> EOF

I think that helper still ends up using "cat" and "diff" under the hood,
unless you write those bits in pure shell. But at that point, I suspect
we could "cat" and "test_cmp" in pure shell, something like:

        cat () {
                # optimize common here-doc usage
                if test $# -eq 0
                then
                        while read -r line
                        do
                                printf '%s' "$line"
                        done
                fi
                command cat "$@"
        }

        test_cmp () {
                # optimize for common "they are the same" case
                # without any subshells or subprograms
                while true; do
                        if ! read -r line1 <&3
                        then
                                if ! read -r line2 <&4
                                        # EOF on both; good
                                        return 0
                                else
                                        # EOF only on file1; fail
                                        break
                                fi
                        fi
                        if ! read -r line2 <&4
                        then
                                # EOF only on file2; fail
                                break
                        fi
                        test "$line1" = "$line2" || break
                done 3<"$1" 4<"$2"

                # if we get here, the optimized version found some
                # difference. We can just "return 1", but let's run
                # the real $GIT_TEST_CMP to provide pretty output.
                # This should generally only happen on test failures,
                # so performance isn't a big deal.
                "$GIT_TEST_CMP" "$@"
        }

Those are both completely untested. But maybe they are worth playing
around with for somebody on Windows to see if they make a dent in the
test runtime.

-Peff

Reply via email to