From 10e527be4e2fe356fccd76316eafe0c5b6283a95 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Tue, 24 Jun 2025 22:50:22 -0700 Subject: [PATCH] Use short revisions by default when navigating to revisions * lisp/vc/vc-annotate.el (vc-annotate-revision-previous-to-line) (vc-annotate-show-diff-revision-at-line-internal) (vc-annotate-warp-revision): Let-bind 'vc-use-short-revision' around calls to 'previous-revision' and 'next-revision'. * lisp/vc/vc-git.el (vc-git-previous-revision, vc-git-next-revision): Handle 'vc-use-short-revision' option (bug#78900). (cherry picked from commit e88af5fff7fbb148a5ddad377219336dc22500b1) --- lisp/vc/vc-annotate.el | 38 ++++++++++++++++++++++---------------- lisp/vc/vc-git.el | 15 ++++++++++++--- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lisp/vc/vc-annotate.el b/lisp/vc/vc-annotate.el index 4f72faacaaf..e68c5a79919 100644 --- a/lisp/vc/vc-annotate.el +++ b/lisp/vc/vc-annotate.el @@ -557,8 +557,9 @@ Return a cons (REV . FILENAME)." (if (not rev-at-line) (message "Cannot extract revision number from the current line") (setq prev-rev - (vc-call-backend vc-annotate-backend 'previous-revision - fname rev)) + (let ((vc-use-short-revision vc-annotate-use-short-revision)) + (vc-call-backend vc-annotate-backend 'previous-revision + fname rev))) (if (not prev-rev) (message "No previous revisions") (vc-annotate-warp-revision prev-rev fname)))))) @@ -613,8 +614,9 @@ the file in question, search for the log entry required and move point." (if (not rev-at-line) (message "Cannot extract revision number from the current line") (setq prev-rev - (vc-call-backend vc-annotate-backend 'previous-revision - (if filediff fname nil) rev)) + (let ((vc-use-short-revision vc-annotate-use-short-revision)) + (vc-call-backend vc-annotate-backend 'previous-revision + (if filediff fname nil) rev))) (vc-diff-internal vc-allow-async-diff ;; The value passed here should follow what @@ -658,23 +660,27 @@ describes a revision number, so warp to that revision." (cond ((and (integerp revspec) (> revspec 0)) (setq newrev vc-buffer-revision) - (while (and (> revspec 0) newrev) - (setq newrev (vc-call-backend vc-annotate-backend 'next-revision - (or file - (caadr vc-buffer-overriding-fileset)) - newrev)) - (setq revspec (1- revspec))) + (let ((vc-use-short-revision vc-annotate-use-short-revision)) + (while (and (> revspec 0) newrev) + (setq newrev + (vc-call-backend vc-annotate-backend 'next-revision + (or file + (caadr vc-buffer-overriding-fileset)) + newrev)) + (setq revspec (1- revspec)))) (unless newrev (message "Cannot increment %d revisions from revision %s" revspeccopy vc-buffer-revision))) ((and (integerp revspec) (< revspec 0)) (setq newrev vc-buffer-revision) - (while (and (< revspec 0) newrev) - (setq newrev (vc-call-backend vc-annotate-backend 'previous-revision - (or file - (caadr vc-buffer-overriding-fileset)) - newrev)) - (setq revspec (1+ revspec))) + (let ((vc-use-short-revision vc-annotate-use-short-revision)) + (while (and (< revspec 0) newrev) + (setq newrev + (vc-call-backend vc-annotate-backend 'previous-revision + (or file + (caadr vc-buffer-overriding-fileset)) + newrev)) + (setq revspec (1+ revspec)))) (unless newrev (message "Cannot decrement %d revisions from revision %s" (- 0 revspeccopy) vc-buffer-revision))) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index eb0465cd0d5..9075ceed634 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1937,13 +1937,18 @@ This requires git 1.8.4 or later, for the \"-L\" option of \"git log\"." ;;; MISCELLANEOUS +(defsubst vc-git--maybe-abbrev () + (if vc-use-short-revision "--abbrev-commit" "--no-abbrev-commit")) + (defun vc-git-previous-revision (file rev) "Git-specific version of `vc-previous-revision'." (if file (let* ((fname (file-relative-name file)) (prev-rev (with-temp-buffer (and - (vc-git--out-ok "rev-list" "-2" rev "--" fname) + (vc-git--out-ok "rev-list" + (vc-git--maybe-abbrev) + "-2" rev "--" fname) (goto-char (point-max)) (bolp) (zerop (forward-line -1)) @@ -1974,7 +1979,9 @@ This requires git 1.8.4 or later, for the \"-L\" option of \"git log\"." (current-rev (with-temp-buffer (and - (vc-git--out-ok "rev-list" "-1" rev "--" file) + (vc-git--out-ok "rev-list" + (vc-git--maybe-abbrev) + "-1" rev "--" file) (goto-char (point-max)) (bolp) (zerop (forward-line -1)) @@ -1986,7 +1993,9 @@ This requires git 1.8.4 or later, for the \"-L\" option of \"git log\"." (and current-rev (with-temp-buffer (and - (vc-git--out-ok "rev-list" "HEAD" "--" file) + (vc-git--out-ok "rev-list" + (vc-git--maybe-abbrev) + "HEAD" "--" file) (goto-char (point-min)) (search-forward current-rev nil t) (zerop (forward-line -1)) -- 2.39.5