<commit_before>@ECHO off

REM
REM Automated Build Script to automate the update process by grabbing the latest from the source
REM control repository, used here is subversion (svn) though it shouldn't be hard to modify to Git or Hg.
REM
REM This may be run by an automated process to clean and/or build each project with an /automated/auto_ script.
REM
REM Available on github: https://www.github.com/timbeaudet/build_automation/ under the unliscense agreement.
REM -------------------------------------------------------------------------------------------------------------------

REM This should go back to project_root to update, which by default is 1 level back from: project_root/build/

IF NOT DEFINED abs_detailed_report_file (
	ECHO WARNING: abs_detailed_report_file was not set.
	SET abs_detailed_report_file="auto_build_report.txt"
)

(ECHO.)>>%abs_detailed_report_file%
(ECHO.)>>%abs_detailed_report_file%
(ECHO updating from source control of %CD%)>>%abs_detailed_report_file%
(ECHO ========================================================)>>%abs_detailed_report_file%

PUSHD ..\
(svn update --quiet --non-interactive)>>%abs_detailed_report_file%
POPD

SET project_update_hook="%CD%\abs_build_hooks\project_update.bat"
IF EXIST %project_update_hook% (
	CALL %project_update_hook%
)

REM Nothing can really go terribly wrong in updating, can it?
SET abs_return_value=0<commit_msg>Supporting git or svn local repository now.<commit_after>@ECHO off

REM
REM Automated Build Script to automate the update process by grabbing the latest from the source
REM control repository, used here is Git if .git directory exists one directory back, or subversion (svn) if not.
REM
REM Available on github: https://www.github.com/timbeaudet/build_automation/ under the unliscense agreement.
REM -------------------------------------------------------------------------------------------------------------------

REM This should go back to project_root to update, which is expected to be 1 level back from: project_root/build/

REM Apparently %var% gets expanded upon reading the script and not during the running
REM the command so when used within a for loop, or IF?, oddities seem to ensue.
REM Enabling delayed expansion and using !var! causes the expansion to happen during
REM the command. Still I think I've seen oddities with regards to nested loops.
SETLOCAL enableextensions ENABLEDELAYEDEXPANSION

REM This is a temporary file use to spit out the contents of a command and read them
REM back in to check if the contents was empty, a 4 command hack to the bash solution.
SET init_external_update_file="temp_update_check_file.abs"

PUSHD ..\

IF NOT DEFINED abs_detailed_report_file (
	SET abs_detailed_report_file="conout$"
)

(ECHO.)>>%abs_detailed_report_file%
(ECHO.)>>%abs_detailed_report_file%
(ECHO updating from source control of %CD%)>>%abs_detailed_report_file%
(ECHO ========================================================)>>%abs_detailed_report_file%

SET found_updates=0

IF EXIST ".git\" (
	git fetch origin
	(git log HEAD..origin/master --oneline)>"%init_external_update_file%"
	set size=0
	FOR /f %%i in ("%init_external_update_file%") do set size=%%~zi
	IF !size! gtr 0 (
		ECHO "Found modifications, updating repository."
		git pull --rebase
		SET found_updates=1
	)
	DEL "%init_external_update_file%"
) ELSE (
	(svn merge --dry-run -r BASE:HEAD .)>"%init_external_update_file%"
	set size=0
	FOR /f %%i in ("%init_external_update_file%") do set size=%%~zi
	IF !size! gtr 0 (
		ECHO "Found modifications, updating repository."
		(svn update --quiet --non-interactive)>>%abs_detailed_report_file%
		SET found_updates=1
	)
	DEL "%init_external_update_file%"
)

POPD

SET project_update_hook="%CD%\abs_build_hooks\project_update.bat"
IF EXIST %project_update_hook% (
	CALL %project_update_hook%
	REM TODO: Check the return value from the hook and set failure if needed.
)

REM TODO: Would be nice to call build/initialize_externals.sh if that file exists.
REM SET abs_initialize_externals="%CD%\initialize_externals.bat"
REM IF EXIST %abs_initialize_externals% (
REM 	CALL %abs_initialize_externals%
REM 	REM TODO: Check the return value from the hook and set failure if needed.
REM )

REM Not exactly true, but nothing went wrong by default. This will set the value to 1 or 0 depending
REM on whether updates were found or not. NOTE: the primary script will not throw an error in this
REM very specific situation (abs_update script value 1) and instead will either continue or skip the
REM rest of the build steps for the current project depending on settings.
SET abs_return_value=%found_updates%
{'fraction_non_alphanumeric': 0.14313555651797316, 'fraction_numerical': 0.0030316154179298397, 'mean_word_length': 4.015200868621064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2807068', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1326, 'n_words': 527}