mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-11-04 11:22:13 +08:00 
			
		
		
		
	Speed up calls to lib_console
This commit is contained in:
		
							
								
								
									
										5
									
								
								vendor/lib/lib_console.cmd
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								vendor/lib/lib_console.cmd
									
									
									
									
										vendored
									
									
								
							@@ -3,6 +3,11 @@
 | 
			
		||||
call "%~dp0lib_base.cmd"
 | 
			
		||||
set lib_console=call "%~dp0lib_console.cmd"
 | 
			
		||||
 | 
			
		||||
:: Much faster than using "%lib_console% debug_output ..." etc.
 | 
			
		||||
set print_debug=if %debug_output% gtr 0 %lib_console% debug_output %*
 | 
			
		||||
set print_verbose=if %verbose_output% gtr 0 %lib_console% verbose_output %*
 | 
			
		||||
set print_error=%lib_console% show_error %*
 | 
			
		||||
 | 
			
		||||
if "%fast_init%" == "1" exit /b
 | 
			
		||||
 | 
			
		||||
if "%~1" == "/h" (
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								vendor/lib/lib_git.cmd
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										26
									
								
								vendor/lib/lib_git.cmd
									
									
									
									
										vendored
									
									
								
							@@ -39,11 +39,11 @@ exit /b
 | 
			
		||||
 | 
			
		||||
    :: set the executable path
 | 
			
		||||
    set "git_executable=%~2\git.exe"
 | 
			
		||||
    %lib_console% debug_output :read_version "Env Var - git_executable=%git_executable%"
 | 
			
		||||
    %print_debug% :read_version "Env Var - git_executable=%git_executable%"
 | 
			
		||||
 | 
			
		||||
    :: check if the executable actually exists
 | 
			
		||||
    if not exist "%git_executable%" (
 | 
			
		||||
        %lib_console% debug_output :read_version "%git_executable% does not exist."
 | 
			
		||||
        %print_debug% :read_version "%git_executable% does not exist."
 | 
			
		||||
        exit /b -255
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
@@ -60,7 +60,7 @@ exit /b
 | 
			
		||||
            exit /b
 | 
			
		||||
        )
 | 
			
		||||
    )
 | 
			
		||||
    endlocal & set "GIT_VERSION_%~1=%GIT_VERSION%" & %lib_console% debug_output :read_version "Env Var - GIT_VERSION_%~1=%GIT_VERSION%"
 | 
			
		||||
    endlocal & set "GIT_VERSION_%~1=%GIT_VERSION%" & %print_debug% :read_version "Env Var - GIT_VERSION_%~1=%GIT_VERSION%"
 | 
			
		||||
 | 
			
		||||
    exit /b
 | 
			
		||||
 | 
			
		||||
@@ -90,7 +90,7 @@ exit /b
 | 
			
		||||
:::-------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
    :: process a `x.x.x.xxxx.x` formatted string
 | 
			
		||||
    %lib_console% debug_output :parse_version "ARGV[1]=%~1, ARGV[2]=%~2"
 | 
			
		||||
    %print_debug% :parse_version "ARGV[1]=%~1, ARGV[2]=%~2"
 | 
			
		||||
 | 
			
		||||
    setlocal enabledelayedexpansion
 | 
			
		||||
    for /F "tokens=1-3* delims=.,-" %%A in ("%2") do (
 | 
			
		||||
@@ -130,16 +130,16 @@ exit /b
 | 
			
		||||
:::-------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
    :: now parse the version information into the corresponding variables
 | 
			
		||||
    %lib_console% debug_output :validate_version "ARGV[1]=%~1, ARGV[2]=%~2"
 | 
			
		||||
    %print_debug% :validate_version "ARGV[1]=%~1, ARGV[2]=%~2"
 | 
			
		||||
 | 
			
		||||
    call :parse_version %~1 %~2
 | 
			
		||||
 | 
			
		||||
    :: ... and maybe display it, for debugging purposes.
 | 
			
		||||
    REM %lib_console% debug_output :validate_version "Found Git Version for %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD!"
 | 
			
		||||
    REM %print_debug% :validate_version "Found Git Version for %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD!"
 | 
			
		||||
    if "%~1" == "VENDORED" (
 | 
			
		||||
      %lib_console% debug_output :validate_version "Found Git Version for %~1: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%"
 | 
			
		||||
      %print_debug% :validate_version "Found Git Version for %~1: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%"
 | 
			
		||||
    ) else (
 | 
			
		||||
      %lib_console% debug_output :validate_version "Found Git Version for %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%"
 | 
			
		||||
      %print_debug% :validate_version "Found Git Version for %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%"
 | 
			
		||||
    )
 | 
			
		||||
    exit /b
 | 
			
		||||
 | 
			
		||||
@@ -164,9 +164,9 @@ exit /b
 | 
			
		||||
    :: checks all major, minor, patch and build variables for the given arguments.
 | 
			
		||||
    :: whichever binary that has the most recent version will be used based on the return code.
 | 
			
		||||
 | 
			
		||||
    %lib_console% debug_output Comparing:
 | 
			
		||||
    %lib_console% debug_output %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%
 | 
			
		||||
    %lib_console% debug_output %~2: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%
 | 
			
		||||
    %print_debug% Comparing:
 | 
			
		||||
    %print_debug% %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%
 | 
			
		||||
    %print_debug% %~2: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%
 | 
			
		||||
 | 
			
		||||
    setlocal enabledelayedexpansion
 | 
			
		||||
    if !%~1_MAJOR! GTR !%~2_MAJOR! (endlocal & exit /b  1)
 | 
			
		||||
@@ -244,13 +244,13 @@ exit /b
 | 
			
		||||
                set "GIT_INSTALL_ROOT=!test_dir!"
 | 
			
		||||
            )
 | 
			
		||||
        ) else (
 | 
			
		||||
            !lib_console! verbose_output "Found old !GIT_VERSION_USER! in !test_dir!, but not using..."
 | 
			
		||||
            !print_verbose! "Found old !GIT_VERSION_USER! in !test_dir!, but not using..."
 | 
			
		||||
        )
 | 
			
		||||
    ) else (
 | 
			
		||||
        :: compare the user git version against the vendored version
 | 
			
		||||
        :: if the user provided git executable is not found
 | 
			
		||||
        IF ERRORLEVEL -255 IF NOT ERRORLEVEL -254 (
 | 
			
		||||
            !lib_console! verbose_output "No git at "!git_executable!" found."
 | 
			
		||||
            !print_verbose! "No git at "!git_executable!" found."
 | 
			
		||||
            set test_dir=
 | 
			
		||||
        )
 | 
			
		||||
    )
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								vendor/lib/lib_path.cmd
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										34
									
								
								vendor/lib/lib_path.cmd
									
									
									
									
										vendored
									
									
								
							@@ -42,7 +42,7 @@ exit /b
 | 
			
		||||
    if "%~1" neq "" (
 | 
			
		||||
        set "add_path=%~1"
 | 
			
		||||
    ) else (
 | 
			
		||||
        %lib_console% show_error "You must specify a directory to add to the path!"
 | 
			
		||||
        %print_error% "You must specify a directory to add to the path!"
 | 
			
		||||
        exit 1
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
@@ -81,29 +81,29 @@ exit /b
 | 
			
		||||
      echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!;"
 | 
			
		||||
      call :set_found
 | 
			
		||||
    )
 | 
			
		||||
    !lib_console! debug_output  :enhance_path "Env Var INSIDE PATH !find_query! - found=!found!"
 | 
			
		||||
    !print_debug!  :enhance_path "Env Var INSIDE PATH !find_query! - found=!found!"
 | 
			
		||||
 | 
			
		||||
    if /i "!position!" == "append" (
 | 
			
		||||
      if "!found!" == "0" (
 | 
			
		||||
        echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!\"$"
 | 
			
		||||
        call :set_found
 | 
			
		||||
      )
 | 
			
		||||
      !lib_console! debug_output  :enhance_path "Env Var END PATH !find_query! - found=!found!"
 | 
			
		||||
      !print_debug!  :enhance_path "Env Var END PATH !find_query! - found=!found!"
 | 
			
		||||
    ) else (
 | 
			
		||||
      if "!found!" == "0" (
 | 
			
		||||
        echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:"^\"!find_query!;"
 | 
			
		||||
        call :set_found
 | 
			
		||||
      )
 | 
			
		||||
      !lib_console! debug_output  :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!"
 | 
			
		||||
      !print_debug!  :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!"
 | 
			
		||||
    )
 | 
			
		||||
    endlocal & set found=%found%
 | 
			
		||||
 | 
			
		||||
    if "%found%" == "0" (
 | 
			
		||||
        if /i "%position%" == "append" (
 | 
			
		||||
            %lib_console% debug_output :enhance_path "Appending '%add_to_path%'"
 | 
			
		||||
            %print_debug% :enhance_path "Appending '%add_to_path%'"
 | 
			
		||||
            set "PATH=%PATH%;%add_to_path%"
 | 
			
		||||
        ) else (
 | 
			
		||||
            %lib_console% debug_output :enhance_path "Prepending '%add_to_path%'"
 | 
			
		||||
            %print_debug% :enhance_path "Prepending '%add_to_path%'"
 | 
			
		||||
            set "PATH=%add_to_path%;%PATH%"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
@@ -113,8 +113,8 @@ exit /b
 | 
			
		||||
    :end_enhance_path
 | 
			
		||||
    set "PATH=%PATH:;;=;%"
 | 
			
		||||
    if NOT "%OLD_PATH%" == "%PATH%" (
 | 
			
		||||
      %lib_console% debug_output  :enhance_path "END Env Var - PATH=%path%"
 | 
			
		||||
      %lib_console% debug_output  :enhance_path "Env Var %find_query% - found=%found%"
 | 
			
		||||
      %print_debug%  :enhance_path "END Env Var - PATH=%path%"
 | 
			
		||||
      %print_debug%  :enhance_path "Env Var %find_query% - found=%found%"
 | 
			
		||||
    )
 | 
			
		||||
    set "position="
 | 
			
		||||
    exit /b
 | 
			
		||||
@@ -156,7 +156,7 @@ exit /b
 | 
			
		||||
    if "%~1" neq "" (
 | 
			
		||||
        set "add_path=%~1"
 | 
			
		||||
    ) else (
 | 
			
		||||
        %lib_console% show_error "You must specify a directory to add to the path!"
 | 
			
		||||
        %print_error% "You must specify a directory to add to the path!"
 | 
			
		||||
        exit 1
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
@@ -188,14 +188,14 @@ exit /b
 | 
			
		||||
      exit /b
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    %lib_console% debug_output  :enhance_path_recursive "Env Var - add_path=%add_to_path%"
 | 
			
		||||
    %lib_console% debug_output  :enhance_path_recursive "Env Var - position=%position%"
 | 
			
		||||
    %lib_console% debug_output  :enhance_path_recursive "Env Var - depth=%depth%"
 | 
			
		||||
    %lib_console% debug_output  :enhance_path_recursive "Env Var - max_depth=%max_depth%"
 | 
			
		||||
    %print_debug%  :enhance_path_recursive "Env Var - add_path=%add_to_path%"
 | 
			
		||||
    %print_debug%  :enhance_path_recursive "Env Var - position=%position%"
 | 
			
		||||
    %print_debug%  :enhance_path_recursive "Env Var - depth=%depth%"
 | 
			
		||||
    %print_debug%  :enhance_path_recursive "Env Var - max_depth=%max_depth%"
 | 
			
		||||
 | 
			
		||||
    if %max_depth% gtr %depth% (
 | 
			
		||||
        if "%add_to_path%" neq "" (
 | 
			
		||||
            %lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_to_path%'"
 | 
			
		||||
            %print_debug% :enhance_path_recursive "Adding parent directory - '%add_to_path%'"
 | 
			
		||||
            call :enhance_path "%add_to_path%" %position%
 | 
			
		||||
        )
 | 
			
		||||
        call :set_depth
 | 
			
		||||
@@ -216,10 +216,10 @@ exit /b
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    for /d %%i in ("%add_path%\*") do (
 | 
			
		||||
        %lib_console% debug_output  :enhance_path_recursive "Env Var BEFORE - depth=%depth%"
 | 
			
		||||
        %lib_console% debug_output :enhance_path_recursive "Found Subdirectory - '%%~fi'"
 | 
			
		||||
        %print_debug%  :enhance_path_recursive "Env Var BEFORE - depth=%depth%"
 | 
			
		||||
        %print_debug% :enhance_path_recursive "Found Subdirectory - '%%~fi'"
 | 
			
		||||
        call :enhance_path_recursive "%%~fi" %depth% %max_depth% %position%
 | 
			
		||||
        %lib_console% debug_output  :enhance_path_recursive "Env Var AFTER- depth=%depth%"
 | 
			
		||||
        %print_debug%  :enhance_path_recursive "Env Var AFTER- depth=%depth%"
 | 
			
		||||
    )
 | 
			
		||||
    exit /b
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/lib/lib_profile.cmd
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/lib/lib_profile.cmd
									
									
									
									
										vendored
									
									
								
							@@ -38,7 +38,7 @@ exit /b
 | 
			
		||||
 | 
			
		||||
  pushd "%~1"
 | 
			
		||||
  for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do (
 | 
			
		||||
    %lib_console% verbose_output "Calling '%~1\%%x'..."
 | 
			
		||||
    %print_verbose% "Calling '%~1\%%x'..."
 | 
			
		||||
    call "%~1\%%x"
 | 
			
		||||
  )
 | 
			
		||||
  popd
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user