[TASK] Squeeze every bit of performance from CGL fixer 17/52417/14
authorClaus Due <claus@namelesscoder.net>
Tue, 11 Apr 2017 18:23:31 +0000 (20:23 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 22 May 2017 15:32:40 +0000 (17:32 +0200)
This patch reduces the amount of time required to check
CGL to less than 3% of what it was before when xdebug
is loaded and the script is asked to check ~100 files.

Time before: 17m
Time after: 23.3s

Change-Id: I533ac3bfd03922362ccd6180caf6df2bfecd5bac
Releases: master, 8.7
Resolves: #80814
Reviewed-on: https://review.typo3.org/52417
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Build/Scripts/cglFixMyCommit.sh

index 7aa80e5..f75069a 100755 (executable)
 #
 ##########################
 
 #
 ##########################
 
-COUNTER=0
+php_no_xdebug () {
+    temporaryPath="$(mktemp -t php.XXXX).ini"
+    php -i | grep "\.ini" | grep -o -e '\(/[a-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' > "${temporaryPath}"
+    php -n -c "${temporaryPath}" "$@"
+    RETURN=$?
+    rm -f "${temporaryPath}"
+    exit $RETURN
+}
+
 DRYRUN=""
 
 if [ "$1" = "dryrun" ]
 DRYRUN=""
 
 if [ "$1" = "dryrun" ]
@@ -19,23 +27,16 @@ then
     DRYRUN="--dry-run"
 fi
 
     DRYRUN="--dry-run"
 fi
 
-for FILE in $(git diff-tree --no-commit-id --name-only -r HEAD | grep '.php$'); do
-    if [ -e $FILE ]
-    then
-        ./bin/php-cs-fixer fix $FILE \
-            -v $DRYRUN \
-            --config=Build/.php_cs
-
-        if [ "$?" -gt "0" ]
-        then
-            COUNTER=$((COUNTER+1))
-        fi
-    fi
-done
-
-if [ ${COUNTER} -gt 0 ] ; then
-    echo "$COUNTER number of files are not CGL clean. Check $0 to find out what is going wrong."
-    exit 1
+DETECTED_FILES=`git diff-tree --no-commit-id --name-only -r HEAD | grep '.php$' 2>/dev/null`
+if [ -z "${DETECTED_FILES}" ]
+then
+    echo "No PHP files to check in current commit, all is well."
+    exit 0
 fi
 
 fi
 
-exit 0
+php_no_xdebug ./bin/php-cs-fixer fix \
+    -v ${DRYRUN} \
+    --config=Build/.php_cs \
+    `echo ${DETECTED_FILES} | xargs ls -d 2>/dev/null`
+
+exit $?