Skip to content

Commit 9088a5e

Browse files
authored
Merge pull request #2430 from qfp64/faster-init
Improve init speed
2 parents 25bc575 + 11a78a8 commit 9088a5e

File tree

5 files changed

+60
-55
lines changed

5 files changed

+60
-55
lines changed

vendor/init.bat

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ call "%cmder_root%\vendor\lib\lib_profile"
6767
set "max_depth=%~2"
6868
shift
6969
) else (
70-
%lib_console% show_error "'/max_depth' requires a number between 1 and 5!"
70+
%print_error% "'/max_depth' requires a number between 1 and 5!"
7171
exit /b
7272
)
7373
) else if /i "%1" == "/c" (
@@ -88,7 +88,7 @@ call "%cmder_root%\vendor\lib\lib_profile"
8888
set "GIT_INSTALL_ROOT=%~2"
8989
shift
9090
) else (
91-
%lib_console% show_error "The Git install root folder "%~2", you specified does not exist!"
91+
%print_error% "The Git install root folder "%~2", you specified does not exist!"
9292
exit /b
9393
)
9494
) else if /i "%1"=="/nix_tools" (
@@ -110,7 +110,7 @@ call "%cmder_root%\vendor\lib\lib_profile"
110110
set "HOME=%~2"
111111
shift
112112
) else (
113-
%lib_console% show_error The home folder "%2", you specified does not exist!
113+
%print_error% The home folder "%2", you specified does not exist!
114114
exit /b
115115
)
116116
) else if /i "%1" == "/svn_ssh" (
@@ -125,11 +125,11 @@ goto var_loop
125125
:start
126126
:: Sets CMDER_SHELL, CMDER_CLINK, CMDER_ALIASES
127127
%lib_base% cmder_shell
128-
%lib_console% debug_output init.bat "Env Var - CMDER_ROOT=%CMDER_ROOT%"
129-
%lib_console% debug_output init.bat "Env Var - debug_output=%debug_output%"
128+
%print_debug% init.bat "Env Var - CMDER_ROOT=%CMDER_ROOT%"
129+
%print_debug% init.bat "Env Var - debug_output=%debug_output%"
130130

131131
if defined CMDER_USER_CONFIG (
132-
%lib_console% debug_output init.bat "CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '%CMDER_USER_CONFIG%'!"
132+
%print_debug% init.bat "CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '%CMDER_USER_CONFIG%'!"
133133

134134
if not exist "%CMDER_USER_CONFIG%\opt" md "%CMDER_USER_CONFIG%\opt"
135135
)
@@ -144,7 +144,7 @@ if "%PROCESSOR_ARCHITECTURE%"=="x86" (
144144
)
145145

146146
if "%CMDER_CLINK%" == "1" (
147-
%lib_console% verbose_output "Injecting Clink!"
147+
%print_verbose% "Injecting Clink!"
148148

149149
:: Run clink
150150
if defined CMDER_USER_CONFIG (
@@ -163,15 +163,15 @@ if "%CMDER_CLINK%" == "1" (
163163
"%CMDER_ROOT%\vendor\clink\clink_%clink_architecture%.exe" inject --quiet --profile "%CMDER_ROOT%\config" --scripts "%CMDER_ROOT%\vendor"
164164
)
165165
) else (
166-
%lib_console% verbose_output "WARNING: Incompatible 'ComSpec/Shell' Detetected Skipping Clink Injection!"
166+
%print_verbose% "WARNING: Incompatible 'ComSpec/Shell' Detetected Skipping Clink Injection!"
167167
)
168168

169169
if "%CMDER_CONFIGURED%" GTR "1" (
170-
%lib_console% verbose_output "Cmder is already configured, skipping Cmder Init!"
170+
%print_verbose% "Cmder is already configured, skipping Cmder Init!"
171171

172172
goto USER_ALIASES
173173
) else if "%CMDER_CONFIGURED%" == "1" (
174-
%lib_console% verbose_output "Cmder is already configured, skipping to Cmder User Init!"
174+
%print_verbose% "Cmder is already configured, skipping to Cmder User Init!"
175175

176176
goto USER_CONFIG_START
177177
)
@@ -191,12 +191,12 @@ if defined GIT_INSTALL_ROOT (
191191
if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" goto :SPECIFIED_GIT
192192
) else if "%fast_init%" == "1" (
193193
if exist "%CMDER_ROOT%\vendor\git-for-windows\cmd\git.exe" (
194-
%lib_console% debug_output "Skipping Git Auto-Detect!"
194+
%print_debug% "Skipping Git Auto-Detect!"
195195
goto :VENDORED_GIT
196196
)
197197
)
198198

199-
%lib_console% debug_output init.bat "Looking for Git install root..."
199+
%print_debug% init.bat "Looking for Git install root..."
200200

201201
:: get the version information for vendored git binary
202202
%lib_git% read_version VENDORED "%CMDER_ROOT%\vendor\git-for-windows\cmd" 2>nul
@@ -218,31 +218,31 @@ for /F "delims=" %%F in ('where git.exe 2^>nul') do (
218218
:VENDORED_GIT
219219
if exist "%CMDER_ROOT%\vendor\git-for-windows" (
220220
set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
221-
%lib_console% debug_output "Using vendored Git '%GIT_VERSION_VENDORED%'..."
221+
%print_debug% "Using vendored Git '%GIT_VERSION_VENDORED%'..."
222222
goto :CONFIGURE_GIT
223223
) else (
224224
goto :NO_GIT
225225
)
226226

227227
:SPECIFIED_GIT
228-
%lib_console% debug_output "Using /GIT_INSTALL_ROOT..."
228+
%print_debug% "Using /GIT_INSTALL_ROOT..."
229229
goto :CONFIGURE_GIT
230230

231231
:FOUND_GIT
232-
%lib_console% debug_output "Using found Git '%GIT_VERSION_USER%' from '%GIT_INSTALL_ROOT%..."
232+
%print_debug% "Using found Git '%GIT_VERSION_USER%' from '%GIT_INSTALL_ROOT%..."
233233
goto :CONFIGURE_GIT
234234

235235
:CONFIGURE_GIT
236-
%lib_console% debug_output "Using Git from '%GIT_INSTALL_ROOT%..."
236+
%print_debug% "Using Git from '%GIT_INSTALL_ROOT%..."
237237
:: Add git to the path
238238
if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" %lib_path% enhance_path "%GIT_INSTALL_ROOT%\cmd" ""
239239

240240
:: Add the unix commands at the end to not shadow windows commands like more
241241
if %nix_tools% equ 1 (
242-
%lib_console% verbose_output "Preferring Windows commands"
242+
%print_verbose% "Preferring Windows commands"
243243
set "path_position=append"
244244
) else (
245-
%lib_console% verbose_output "Preferring *nix commands"
245+
%print_verbose% "Preferring *nix commands"
246246
set "path_position="
247247
)
248248

@@ -268,7 +268,7 @@ if not defined git_locale for /F "tokens=* delims=" %%F in ('where env.exe 2^>nu
268268
setlocal enabledelayedexpansion
269269
if defined git_locale (
270270

271-
REM !lib_console! debug_output init.bat "Env Var - git_locale=!git_locale!"
271+
REM %print_debug% init.bat "Env Var - git_locale=!git_locale!"
272272
if not defined LANG (
273273
for /F "delims=" %%F in ('!git_locale! -uU 2') do (
274274
set "LANG=%%F"
@@ -277,8 +277,8 @@ if defined git_locale (
277277
)
278278
endlocal && set LANG=%LANG%
279279

280-
%lib_console% debug_output init.bat "Env Var - GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%"
281-
%lib_console% debug_output init.bat "Found Git in: '%GIT_INSTALL_ROOT%'"
280+
%print_debug% init.bat "Env Var - GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%"
281+
%print_debug% init.bat "Found Git in: '%GIT_INSTALL_ROOT%'"
282282
goto :PATH_ENHANCE
283283

284284
:NO_GIT
@@ -361,20 +361,20 @@ if exist "%GIT_INSTALL_ROOT%\post-install.bat" (
361361

362362
:: Set home path
363363
if not defined HOME set "HOME=%USERPROFILE%"
364-
%lib_console% debug_output init.bat "Env Var - HOME=%HOME%"
364+
%print_debug% init.bat "Env Var - HOME=%HOME%"
365365

366366
set "initialConfig=%CMDER_ROOT%\config\user_profile.cmd"
367367
if exist "%CMDER_ROOT%\config\user_profile.cmd" (
368368
REM Create this file and place your own command in there
369-
%lib_console% debug_output init.bat "Calling - %CMDER_ROOT%\config\user_profile.cmd"
369+
%print_debug% init.bat "Calling - %CMDER_ROOT%\config\user_profile.cmd"
370370
call "%CMDER_ROOT%\config\user_profile.cmd"
371371
)
372372

373373
if defined CMDER_USER_CONFIG (
374374
set "initialConfig=%CMDER_USER_CONFIG%\user_profile.cmd"
375375
if exist "%CMDER_USER_CONFIG%\user_profile.cmd" (
376376
REM Create this file and place your own command in there
377-
%lib_console% debug_output init.bat "Calling - %CMDER_USER_CONFIG%\user_profile.cmd"
377+
%print_debug% init.bat "Calling - %CMDER_USER_CONFIG%\user_profile.cmd"
378378
call "%CMDER_USER_CONFIG%\user_profile.cmd"
379379
)
380380
)

vendor/lib/lib_console.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
call "%~dp0lib_base.cmd"
44
set lib_console=call "%~dp0lib_console.cmd"
55

6+
:: Much faster than using "%lib_console% debug_output ..." etc.
7+
set print_debug=if %debug_output% gtr 0 %lib_console% debug_output
8+
set print_verbose=if %verbose_output% gtr 0 %lib_console% verbose_output
9+
set print_error=%lib_console% show_error
10+
611
if "%fast_init%" == "1" exit /b
712

813
if "%~1" == "/h" (

vendor/lib/lib_git.cmd

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ exit /b
3939

4040
:: set the executable path
4141
set "git_executable=%~2\git.exe"
42-
%lib_console% debug_output :read_version "Env Var - git_executable=%git_executable%"
42+
%print_debug% :read_version "Env Var - git_executable=%git_executable%"
4343

4444
:: check if the executable actually exists
4545
if not exist "%git_executable%" (
46-
%lib_console% debug_output :read_version "%git_executable% does not exist."
46+
%print_debug% :read_version "%git_executable% does not exist."
4747
exit /b -255
4848
)
4949

@@ -59,7 +59,7 @@ exit /b
5959
exit /b
6060
)
6161
)
62-
endlocal & set "GIT_VERSION_%~1=%GIT_VERSION%" & %lib_console% debug_output :read_version "Env Var - GIT_VERSION_%~1=%GIT_VERSION%"
62+
endlocal & set "GIT_VERSION_%~1=%GIT_VERSION%" & %print_debug% :read_version "Env Var - GIT_VERSION_%~1=%GIT_VERSION%"
6363

6464
exit /b
6565

@@ -89,7 +89,7 @@ exit /b
8989
:::-------------------------------------------------------------------------------
9090

9191
:: process a `x.x.x.xxxx.x` formatted string
92-
%lib_console% debug_output :parse_version "ARGV[1]=%~1, ARGV[2]=%~2"
92+
%print_debug% :parse_version "ARGV[1]=%~1, ARGV[2]=%~2"
9393

9494
setlocal enabledelayedexpansion
9595
for /F "tokens=1-3* delims=.,-" %%A in ("%2") do (
@@ -129,16 +129,16 @@ exit /b
129129
:::-------------------------------------------------------------------------------
130130

131131
:: now parse the version information into the corresponding variables
132-
%lib_console% debug_output :validate_version "ARGV[1]=%~1, ARGV[2]=%~2"
132+
%print_debug% :validate_version "ARGV[1]=%~1, ARGV[2]=%~2"
133133

134134
call :parse_version %~1 %~2
135135

136136
:: ... and maybe display it, for debugging purposes.
137-
REM %lib_console% debug_output :validate_version "Found Git Version for %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD!"
137+
REM %print_debug% :validate_version "Found Git Version for %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD!"
138138
if "%~1" == "VENDORED" (
139-
%lib_console% debug_output :validate_version "Found Git Version for %~1: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%"
139+
%print_debug% :validate_version "Found Git Version for %~1: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%"
140140
) else (
141-
%lib_console% debug_output :validate_version "Found Git Version for %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%"
141+
%print_debug% :validate_version "Found Git Version for %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%"
142142
)
143143
exit /b
144144

@@ -163,9 +163,9 @@ exit /b
163163
:: checks all major, minor, patch and build variables for the given arguments.
164164
:: whichever binary that has the most recent version will be used based on the return code.
165165

166-
%lib_console% debug_output Comparing:
167-
%lib_console% debug_output %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%
168-
%lib_console% debug_output %~2: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%
166+
%print_debug% Comparing:
167+
%print_debug% %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%
168+
%print_debug% %~2: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%
169169

170170
setlocal enabledelayedexpansion
171171
if !%~1_MAJOR! GTR !%~2_MAJOR! (endlocal & exit /b 1)
@@ -243,13 +243,13 @@ exit /b
243243
set "GIT_INSTALL_ROOT=!test_dir!"
244244
)
245245
) else (
246-
!lib_console! verbose_output "Found old !GIT_VERSION_USER! in !test_dir!, but not using..."
246+
%print_verbose% "Found old !GIT_VERSION_USER! in !test_dir!, but not using..."
247247
)
248248
) else (
249249
:: compare the user git version against the vendored version
250250
:: if the user provided git executable is not found
251251
IF ERRORLEVEL -255 IF NOT ERRORLEVEL -254 (
252-
!lib_console! verbose_output "No git at "!git_executable!" found."
252+
%print_verbose% "No git at "!git_executable!" found."
253253
set test_dir=
254254
)
255255
)

vendor/lib/lib_path.cmd

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ exit /b
4242
if "%~1" neq "" (
4343
set "add_path=%~1"
4444
) else (
45-
%lib_console% show_error "You must specify a directory to add to the path!"
45+
%print_error% "You must specify a directory to add to the path!"
4646
exit 1
4747
)
4848

@@ -81,29 +81,29 @@ exit /b
8181
echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!;"
8282
call :set_found
8383
)
84-
!lib_console! debug_output :enhance_path "Env Var INSIDE PATH !find_query! - found=!found!"
84+
%print_debug% :enhance_path "Env Var INSIDE PATH !find_query! - found=!found!"
8585

8686
if /i "!position!" == "append" (
8787
if "!found!" == "0" (
8888
echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!\"$"
8989
call :set_found
9090
)
91-
!lib_console! debug_output :enhance_path "Env Var END PATH !find_query! - found=!found!"
91+
%print_debug% :enhance_path "Env Var END PATH !find_query! - found=!found!"
9292
) else (
9393
if "!found!" == "0" (
9494
echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:"^\"!find_query!;"
9595
call :set_found
9696
)
97-
!lib_console! debug_output :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!"
97+
%print_debug% :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!"
9898
)
9999
endlocal & set found=%found%
100100

101101
if "%found%" == "0" (
102102
if /i "%position%" == "append" (
103-
%lib_console% debug_output :enhance_path "Appending '%add_to_path%'"
103+
%print_debug% :enhance_path "Appending '%add_to_path%'"
104104
set "PATH=%PATH%;%add_to_path%"
105105
) else (
106-
%lib_console% debug_output :enhance_path "Prepending '%add_to_path%'"
106+
%print_debug% :enhance_path "Prepending '%add_to_path%'"
107107
set "PATH=%add_to_path%;%PATH%"
108108
)
109109

@@ -113,8 +113,8 @@ exit /b
113113
:end_enhance_path
114114
set "PATH=%PATH:;;=;%"
115115
if NOT "%OLD_PATH%" == "%PATH%" (
116-
%lib_console% debug_output :enhance_path "END Env Var - PATH=%path%"
117-
%lib_console% debug_output :enhance_path "Env Var %find_query% - found=%found%"
116+
%print_debug% :enhance_path "END Env Var - PATH=%path%"
117+
%print_debug% :enhance_path "Env Var %find_query% - found=%found%"
118118
)
119119
set "position="
120120
exit /b
@@ -156,7 +156,7 @@ exit /b
156156
if "%~1" neq "" (
157157
set "add_path=%~1"
158158
) else (
159-
%lib_console% show_error "You must specify a directory to add to the path!"
159+
%print_error% "You must specify a directory to add to the path!"
160160
exit 1
161161
)
162162

@@ -188,14 +188,14 @@ exit /b
188188
exit /b
189189
)
190190

191-
%lib_console% debug_output :enhance_path_recursive "Env Var - add_path=%add_to_path%"
192-
%lib_console% debug_output :enhance_path_recursive "Env Var - position=%position%"
193-
%lib_console% debug_output :enhance_path_recursive "Env Var - depth=%depth%"
194-
%lib_console% debug_output :enhance_path_recursive "Env Var - max_depth=%max_depth%"
191+
%print_debug% :enhance_path_recursive "Env Var - add_path=%add_to_path%"
192+
%print_debug% :enhance_path_recursive "Env Var - position=%position%"
193+
%print_debug% :enhance_path_recursive "Env Var - depth=%depth%"
194+
%print_debug% :enhance_path_recursive "Env Var - max_depth=%max_depth%"
195195

196196
if %max_depth% gtr %depth% (
197197
if "%add_to_path%" neq "" (
198-
%lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_to_path%'"
198+
%print_debug% :enhance_path_recursive "Adding parent directory - '%add_to_path%'"
199199
call :enhance_path "%add_to_path%" %position%
200200
)
201201
call :set_depth
@@ -216,10 +216,10 @@ exit /b
216216
)
217217

218218
for /d %%i in ("%add_path%\*") do (
219-
%lib_console% debug_output :enhance_path_recursive "Env Var BEFORE - depth=%depth%"
220-
%lib_console% debug_output :enhance_path_recursive "Found Subdirectory - '%%~fi'"
219+
%print_debug% :enhance_path_recursive "Env Var BEFORE - depth=%depth%"
220+
%print_debug% :enhance_path_recursive "Found Subdirectory - '%%~fi'"
221221
call :enhance_path_recursive "%%~fi" %depth% %max_depth% %position%
222-
%lib_console% debug_output :enhance_path_recursive "Env Var AFTER- depth=%depth%"
222+
%print_debug% :enhance_path_recursive "Env Var AFTER- depth=%depth%"
223223
)
224224
exit /b
225225

vendor/lib/lib_profile.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exit /b
3838

3939
pushd "%~1"
4040
for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do (
41-
%lib_console% verbose_output "Calling '%~1\%%x'..."
41+
%print_verbose% "Calling '%~1\%%x'..."
4242
call "%~1\%%x"
4343
)
4444
popd

0 commit comments

Comments
 (0)