commit 9b53f629f36d3301a0c9e41df4b5110d5ab61d9b from: Omar Polo date: Fri Aug 05 09:26:06 2022 UTC faster vc-got-working-revision invoking `got log' to find the working revision of a file is quite heavy. It takes several seconds to run on some occasions and working in /usr/src is a pain. (usr.bin/diff/diff.c takes _seven_ seconds to get the first log entry.) `got info' instead is quicker since it doesn't have to traverse the history but only parse the fileindex. (usr.bin/diff/diff.c takes one second to compare.) It also avoids an extra `got status' call if the file is added since `got info' succeeds but doesn't print any commit information in that case. commit - 489c6310a6f64bc73ea3eeda5dc9a96ad8bf5043 commit + 9b53f629f36d3301a0c9e41df4b5110d5ab61d9b blob - 1c5aef4099c14a998dea30f500beabf642af6879 blob + 6f1b28ea6b78638cc4e6384ab69565a1baca162b --- vc-got.el +++ vc-got.el @@ -222,6 +222,13 @@ The output will be placed in the current buffer." "Add FILES to got, passing `vc-register-switches' to the command invocation." (with-temp-buffer (vc-got--call "add" vc-register-switches "--" files))) + +(defun vc-got--info (path) + "Execute got info in the worktree of PATH in the current buffer." + (let* ((process-file-side-effects nil)) + (vc-got-with-worktree path + (zerop (save-excursion + (vc-got--call "info" "--" path)))))) (defun vc-got--log (&optional path limit start-commit stop-commit search-pattern reverse include-diff) @@ -552,21 +559,12 @@ FILES is nil, consider all the files in DIR." (defun vc-got-working-revision (file) "Return the last commit that touched FILE or \"0\" if it's newly added." - (or - (with-temp-buffer - (when (vc-got--log file 1) - (let (start) - (goto-char (point-min)) - (forward-word) ; skip "commit" - (forward-char) ; skip the space - (setq start (point)) ; store start of the SHA - (forward-word) ; goto SHA end - (buffer-substring start (point))))) - ;; special case: if this file is added but has no previous commits - ;; touching it, got log will fail (as expected), but we have to - ;; return "0". - (when (eq (vc-got-state file) 'added) - "0"))) + (with-temp-buffer + (when (vc-got--info file) + (let ((pos (re-search-forward "^based on commit: " nil t))) + (if pos + (buffer-substring-no-properties pos (line-end-position)) + "0"))))) (defun vc-got-checkout-model (_files) "Return the checkout model.