[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vc-got 9b53f629f3 1/2: faster vc-got-working-revision
From: |
ELPA Syncer |
Subject: |
[elpa] externals/vc-got 9b53f629f3 1/2: faster vc-got-working-revision |
Date: |
Fri, 5 Aug 2022 05:58:04 -0400 (EDT) |
branch: externals/vc-got
commit 9b53f629f36d3301a0c9e41df4b5110d5ab61d9b
Author: Omar Polo <op@omarpolo.com>
Commit: Omar Polo <op@omarpolo.com>
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.
---
vc-got.el | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/vc-got.el b/vc-got.el
index 1c5aef4099..6f1b28ea6b 100755
--- a/vc-got.el
+++ b/vc-got.el
@@ -223,6 +223,13 @@ The output will be placed in the current buffer."
(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)
"Execute the log command in the worktree of PATH in the current buffer.
@@ -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.