From: Spencer Baugh via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 73232@debbugs.gnu.org
Cc: Juri Linkov <juri@linkov.net>
Subject: bug#73232: [PATCH] Allow vc-diff to suggest a default revision in vc-dir
Date: Fri, 13 Sep 2024 11:51:47 -0400 [thread overview]
Message-ID: <iered5npn58.fsf@janestreet.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2212 bytes --]
Tags: patch
C-u M-x vc-root-diff will prompt for the old revision to use for the
diff. The prompt will have a default calculated by
vc-diff-build-argument-list-internal. The default is either the
working revision of the current fileset or the revision before that.
vc-diff-build-argument-list-internal contained a check (added in
c0d66cb21bac57f5ec0378e8a04aac8f35c3eb5c) which explicitly avoided
setting a default if the current fileset was a directory. This check
was added in 1997 when vc only worked for single files.
This prevents a backend from choosing to return a non-nil value from
'working-revision when passed a directory. (The vc-hg and vc-git
backends, at least, will do this)
Allow this by moving the file-directory-p check, so that we try
calling 'working-revision when the fileset is a single directory. The
call is in inside ignore-errors, so if a backend errors when passed a
directory, we'll just get no default, as before. (Most backends will
just return nil for a directory, rather than erroring)
Also, while we're here, explicitly pass the backend to
vc-working-revision rather than having vc-working-revision recompute
it.
Concretely this has the effect that for the vc-git and vc-hg backends,
running C-u M-x vc-root-diff in vc-dir will have the same behavior as
running C-u M-x vc-root-diff in a clean file: The "Previous revision:"
prompt's default will be the revision before HEAD.
* lisp/vc/vc.el (vc-diff-build-argument-list-internal): Move
file-directory-p check.
In GNU Emacs 29.2.50 (build 17, x86_64-pc-linux-gnu, X toolkit, cairo
version 1.15.12, Xaw scroll bars) of 2024-09-06 built on
igm-qws-u22796a
Repository revision: e6d04c06a7eb6ce932b52a346368d02b7a811a00
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Rocky Linux 8.10 (Green Obsidian)
Configured using:
'configure --with-x-toolkit=lucid --without-gpm --without-gconf
--without-selinux --without-imagemagick --with-modules --with-gif=no
--with-cairo --with-rsvg --without-compress-install
--with-native-compilation=aot --with-tree-sitter
PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-vc-diff-to-suggest-a-default-revision-in-vc-di.patch --]
[-- Type: text/patch, Size: 3069 bytes --]
From e57db4d91cf098d26c8c131d715ef3619466d159 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Fri, 13 Sep 2024 11:34:55 -0400
Subject: [PATCH] Allow vc-diff to suggest a default revision in vc-dir
C-u M-x vc-root-diff will prompt for the old revision to use for the
diff. The prompt will have a default calculated by
vc-diff-build-argument-list-internal. The default is either the
working revision of the current fileset or the revision before that.
vc-diff-build-argument-list-internal contained a check (added in
c0d66cb21bac57f5ec0378e8a04aac8f35c3eb5c) which explicitly avoided
setting a default if the current fileset was a single directory. This
check was added in 1997 when vc only worked for single files.
This prevents a backend from choosing to return a non-nil value from
'working-revision when passed a directory. (The vc-hg and vc-git
backends, at least, will do this)
Allow this by moving the file-directory-p check, so that we try
calling 'working-revision when the fileset is a single directory. The
call is in inside ignore-errors, so if a backend errors when passed a
directory, we'll just get no default, as before. (Most backends will
just return nil for a directory, rather than erroring)
Also, while we're here, explicitly pass the backend to
vc-working-revision rather than having vc-working-revision recompute
it.
Concretely this has the effect that for the vc-git and vc-hg backends,
running C-u M-x vc-root-diff in vc-dir will have the same behavior as
running C-u M-x vc-root-diff in a clean file: The "Previous revision:"
prompt's default will be the revision before HEAD.
* lisp/vc/vc.el (vc-diff-build-argument-list-internal): Move
file-directory-p check.
---
lisp/vc/vc.el | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 597a1622f5a..d88a655dc6b 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -2074,17 +2074,14 @@ vc-diff-build-argument-list-internal
;; filesets, but not yet.
((/= (length files) 1)
nil)
- ;; if it's a directory, don't supply any revision default
- ((file-directory-p first)
- nil)
;; if the file is not up-to-date, use working revision as older revision
- ((not (vc-up-to-date-p first))
- (setq rev1-default (vc-working-revision first)))
+ ((not (and (file-directory-p first) (vc-up-to-date-p first)))
+ (setq rev1-default (vc-working-revision first backend)))
;; if the file is not locked, use last revision and current source as defaults
(t
(setq rev1-default (ignore-errors ;If `previous-revision' doesn't work.
(vc-call-backend backend 'previous-revision first
- (vc-working-revision first))))
+ (vc-working-revision first backend))))
(when (string= rev1-default "") (setq rev1-default nil))))
;; construct argument list
(let* ((rev1-prompt (format-prompt "Older revision" rev1-default))
--
2.39.3
next reply other threads:[~2024-09-13 15:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-13 15:51 Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-09-13 16:10 ` bug#73232: [PATCH] Allow vc-diff to suggest a default revision in vc-dir Eli Zaretskii
2024-09-13 16:25 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-14 1:45 ` Dmitry Gutov
2024-09-14 7:04 ` Eli Zaretskii
2024-09-14 16:13 ` Dmitry Gutov
2024-09-14 16:49 ` Eli Zaretskii
2024-09-17 6:59 ` Juri Linkov
2024-09-27 21:49 ` Dmitry Gutov
2024-09-27 21:55 ` Dmitry Gutov
2024-10-04 11:38 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-09 23:36 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=iered5npn58.fsf@janestreet.com \
--to=bug-gnu-emacs@gnu.org \
--cc=73232@debbugs.gnu.org \
--cc=juri@linkov.net \
--cc=sbaugh@janestreet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).