mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-31 09:22:15 +08:00 
			
		
		
		
	Merge pull request #2621 from chehrlic/clink_git_speedup
Speed up git status / conflict status by calling git only once.
This commit is contained in:
		
							
								
								
									
										37
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										37
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							| @@ -339,32 +339,27 @@ local function get_svn_branch(svn_dir) | |||||||
| end | end | ||||||
|  |  | ||||||
| --- | --- | ||||||
| -- Get the status of working dir | -- Get the status and conflict status of working dir | ||||||
| -- @return {bool} | -- @return {bool <status>, bool <is_conflict>} | ||||||
| --- | --- | ||||||
| local function get_git_status() | local function get_git_status() | ||||||
|     local file = io_popenyield("git --no-optional-locks status --porcelain 2>nul") |     local file = io_popenyield("git --no-optional-locks status --porcelain 2>nul") | ||||||
|  |     local conflict_found = false | ||||||
|  |     local is_status = true | ||||||
|     for line in file:lines() do |     for line in file:lines() do | ||||||
|         file:close() |         local code = line:sub(1, 2) | ||||||
|         return false |         -- print (string.format("code: %s, line: %s", code, line)) | ||||||
|  |         if code == "DD" or code == "AU" or code == "UD" or code == "UA" or code == "DU" or code == "AA" or code == "UU" then | ||||||
|  |           is_status = false | ||||||
|  |           conflict_found = true | ||||||
|  |           break | ||||||
|  |         -- unversioned files are ignored, comment out 'code ~= "!!"' to unignore them | ||||||
|  |         elseif code ~= "!!" and code ~= "??" then | ||||||
|  |           is_status = false | ||||||
|  |         end | ||||||
|     end |     end | ||||||
|     file:close() |     file:close() | ||||||
|  |     return { status = is_status, conflict = conflict_found } | ||||||
|     return true |  | ||||||
| end |  | ||||||
|  |  | ||||||
| --- |  | ||||||
| -- Gets the conflict status |  | ||||||
| -- @return {bool} indicating true for conflict, false for no conflicts |  | ||||||
| --- |  | ||||||
| function get_git_conflict() |  | ||||||
|     local file = io_popenyield("git diff --name-only --diff-filter=U 2>nul") |  | ||||||
|     for line in file:lines() do |  | ||||||
|         file:close() |  | ||||||
|         return true; |  | ||||||
|     end |  | ||||||
|     file:close() |  | ||||||
|     return false |  | ||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -404,7 +399,7 @@ end | |||||||
| --- | --- | ||||||
| local function get_git_info_table() | local function get_git_info_table() | ||||||
|     local info = clink_promptcoroutine(function () |     local info = clink_promptcoroutine(function () | ||||||
|         return { status=get_git_status(), conflict=get_git_conflict() } |         return get_git_status() | ||||||
|     end) |     end) | ||||||
|     if not info then |     if not info then | ||||||
|         info = cached_info.git_info or {} |         info = cached_info.git_info or {} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user