From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#73232: [PATCH] Allow vc-diff to suggest a default revision in vc-dir Date: Fri, 13 Sep 2024 12:25:10 -0400 Message-ID: References: <864j6jjzzn.fsf@gnu.org> Reply-To: Spencer Baugh Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38811"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 73232@debbugs.gnu.org, juri@linkov.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 13 18:26:12 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sp97a-0009s5-Vm for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 13 Sep 2024 18:26:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sp97K-0004uV-79; Fri, 13 Sep 2024 12:25:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sp97J-0004pK-47 for bug-gnu-emacs@gnu.org; Fri, 13 Sep 2024 12:25:53 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sp97I-0007iU-LB for bug-gnu-emacs@gnu.org; Fri, 13 Sep 2024 12:25:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=PCr27WKu5H4rTyVPHa+hCG6B7CrC3hRMKwKZxwvfpm8=; b=r42VMF1Fl7udd5jI/HJ3fwiDQQU4K00KqJkRHAR21nSmaLSiN81Y47YhaFDIfmzwRSBc+UrPYKe0aK/q82BL7de/8+gy5V+m+UfB86Yh2JdA4kvA2nSGwFyxRN+G+d5RDdmb3FOaF1iZeBWAKXf7dGe7GdpJLJdB47hR49s/0fKu5ILlEjkBJb0ipJ3c9vN99vfYEuYAcnyXfKPfGvLHxAOtu8Ub8/6ds+BOIoI8vI1mHjF/X7GLjzGLCzixpIdkWPUKVmDHDqy6ZMznpdEE0BaooGRboz22iDLiKiPpc6NF+LEl5i0mfLnFsORFUfwMXTQkDSydaIugQpfPRjOdcQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sp97R-0001Gb-M9 for bug-gnu-emacs@gnu.org; Fri, 13 Sep 2024 12:26:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Sep 2024 16:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73232 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 73232-submit@debbugs.gnu.org id=B73232.17262447284807 (code B ref 73232); Fri, 13 Sep 2024 16:26:01 +0000 Original-Received: (at 73232) by debbugs.gnu.org; 13 Sep 2024 16:25:28 +0000 Original-Received: from localhost ([127.0.0.1]:44160 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sp96u-0001FS-0z for submit@debbugs.gnu.org; Fri, 13 Sep 2024 12:25:28 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:38027) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sp96s-0001F9-1o for 73232@debbugs.gnu.org; Fri, 13 Sep 2024 12:25:26 -0400 In-Reply-To: <864j6jjzzn.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 13 Sep 2024 19:10:52 +0300") DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1726244711; bh=PCr27WKu5H4rTyVPHa+hCG6B7CrC3hRMKwKZxwvfpm8=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=cNNApFNgQ55XZ+r9Gjt/y19crDMPoLT2M0dIbmdkBsMcnEkfpREpcb1ZPHH4aOA0z QVeB0sGW2yAcdCyMh/6MgAdjGra7W5ce7qZ43LYJYNBWbEh3jAnkrTOLiGzz3kRKsg iWceYjg/qcMg8YeXs1nG3kZf1xc53NxPaMyKaUz1SH4iEf6S/AXaERgW4g8Cv7Ei9H 7Jhu+1Gus2AFGNgvZNpVe4ZtLayCyMARGJ8wNH0EuCxmK5YuVd/5/5pK3Q5OtEm5B2 cYxDxKl8eJ1MCXfe8uDbe1I+8H+ekNHRD+2iB8v4Umh53GeLaLdz5Lvqa+GVSQ7d+T aGQED579mZNhQ== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:291666 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> Cc: Juri Linkov >> Date: Fri, 13 Sep 2024 11:51:47 -0400 >> From: Spencer Baugh via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" >> >> - ;; 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))) > > Doesn't this change the conditions under which we use > vc-working-revision for regular files? Did you perhaps mean > > ((and (not (file-directory-p first)) (vc-up-to-date-p first)) > > instead? Oops, yes, fixed. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Allow-vc-diff-to-suggest-a-default-revision-in-vc-di.patch >From f87b92ce5775d0558b7d9dd502687d1f460bcd2a Mon Sep 17 00:00:00 2001 From: Spencer Baugh 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. (bug#73232) --- 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..7b1133565f9 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))) + ((and (not (file-directory-p first)) (not (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 --=-=-=--