unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Sean Whitton <spwhitton@spwhitton.name>
Cc: 50344@debbugs.gnu.org, larsi@gnus.org,
	Filipp Gunbin <fgunbin@fastmail.fm>,
	Dmitry Gutov <dgutov@yandex.ru>
Subject: bug#50344: C-x v keybinding for vc-print-branch-log
Date: Sun, 11 Sep 2022 18:10:08 +0300	[thread overview]
Message-ID: <86y1uqxaj7.fsf@mail.linkov.net> (raw)
In-Reply-To: <87a679nlq1.fsf@melete.silentflame.com> (Sean Whitton's message of "Thu, 08 Sep 2022 22:46:46 -0700")

[-- Attachment #1: Type: text/plain, Size: 350 bytes --]

>> I have pushed the change which obsoletes vc-switch-backend now.
>>
>> Which should remove the main obstacle to adding the branches map with good
>> binding in Emacs 29.
>
> Would now perhaps be an appropriate time to go ahead and add the
> branches map?

Here is the complete patch that addresses all concerns
raised during this long discussion:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-create-branch.patch --]
[-- Type: text/x-diff, Size: 8047 bytes --]

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index c4f0671d64..a9627a2862 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -449,7 +449,7 @@
 ;;
 ;;   Return the common ancestor between REV1 and REV2 revisions.
 
-;; TAG SYSTEM
+;; TAG/BRANCH SYSTEM
 ;;
 ;; - create-tag (dir name branchp)
 ;;
@@ -464,8 +464,9 @@
 ;; - retrieve-tag (dir name update)
 ;;
 ;;   Retrieve the version tagged by NAME of all registered files at or below DIR.
+;;   If NAME is a branch name, switch to that branch.
 ;;   If UPDATE is non-nil, then update buffers of any files in the
-;;   tag that are currently visited.  The default implementation
+;;   tag/branch that are currently visited.  The default implementation
 ;;   does a sanity check whether there aren't any uncommitted changes at
 ;;   or below DIR, and then performs a tree walk, using the `checkout'
 ;;   function to retrieve the corresponding revisions.
@@ -664,8 +665,6 @@
 ;;   display the branch name in the mode-line.  Replace
 ;;   vc-cvs-sticky-tag with that.
 ;;
-;; - Add a primitives for switching to a branch (creating it if required.
-;;
 ;; - Add the ability to list tags and branches.
 ;;
 ;;;; Unify two different versions of the amend capability
@@ -2432,7 +2431,23 @@ vc-create-tag
   (message "Making %s... done" (if branchp "branch" "tag")))
 
 ;;;###autoload
-(defun vc-retrieve-tag (dir name)
+(defun vc-create-branch (dir name)
+  "Descending recursively from DIR, make a branch called NAME.
+After a new branch is made, the files are checked out in that new branch.
+Uses `vc-create-tag' with the non-nil arg `branchp'."
+  (interactive
+   (let ((granularity
+          (vc-call-backend (vc-responsible-backend default-directory)
+                           'revision-granularity)))
+     (list
+      (if (eq granularity 'repository)
+          default-directory
+        (read-directory-name "Directory: " default-directory default-directory t))
+      (read-string "New branch name: " nil 'vc-revision-history))))
+  (vc-create-tag dir name t))
+
+;;;###autoload
+(defun vc-retrieve-tag (dir name &optional branchp)
   "For each file in or below DIR, retrieve their tagged version NAME.
 NAME can name a branch, in which case this command will switch to the
 named branch in the directory DIR.
@@ -2442,6 +2457,8 @@ vc-retrieve-tag
 If locking is used for the files in DIR, then there must not be any
 locked files at or below DIR (but if NAME is empty, locked files are
 allowed and simply skipped).
+If the prefix argument BRANCHP is given, switch the branch
+and check out the files in that branch.
 This function runs the hook `vc-retrieve-tag-hook' when finished."
   (interactive
    (let* ((granularity
@@ -2457,15 +2474,21 @@ vc-retrieve-tag
              (read-directory-name "Directory: " default-directory nil t))))
      (list
       dir
-      (vc-read-revision (format-prompt "Tag name to retrieve" "latest revisions")
+      (vc-read-revision (format-prompt
+                         (if current-prefix-arg
+                             "Switch to branch"
+                           "Tag name to retrieve")
+                         "latest revisions")
                         (list dir)
-                        (vc-responsible-backend dir)))))
+                        (vc-responsible-backend dir))
+      current-prefix-arg)))
   (let* ((backend (vc-responsible-backend dir))
          (update (when (vc-call-backend backend 'update-on-retrieve-tag)
                    (yes-or-no-p "Update any affected buffers? ")))
 	 (msg (if (or (not name) (string= name ""))
 		  (format "Updating %s... " (abbreviate-file-name dir))
-	        (format "Retrieving tag %s into %s... "
+	        (format "Retrieving %s %s into %s... "
+                        (if branchp "branch" "tag")
 		        name (abbreviate-file-name dir)))))
     (message "%s" msg)
     (vc-call-backend backend 'retrieve-tag dir name update)
@@ -2473,6 +2496,25 @@ vc-retrieve-tag
     (run-hooks 'vc-retrieve-tag-hook)
     (message "%s" (concat msg "done"))))
 
+;;;###autoload
+(defun vc-switch-branch (dir name)
+  "Switch to the branch NAME in the directory DIR.
+If NAME is empty, it refers to the latest revisions of the current branch.
+Uses `vc-retrieve-tag' with the non-nil arg `branchp'."
+  (interactive
+   (let* ((granularity
+           (vc-call-backend (vc-responsible-backend default-directory)
+                            'revision-granularity))
+          (dir
+           (if (eq granularity 'repository)
+               (expand-file-name (vc-root-dir))
+             (read-directory-name "Directory: " default-directory nil t))))
+     (list
+      dir
+      (vc-read-revision (format-prompt "Switch to branch" "latest revisions")
+                        (list dir)
+                        (vc-responsible-backend dir)))))
+  (vc-retrieve-tag dir name t))
 
 ;; Miscellaneous other entry points
 
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 2941cc75be..792981b142 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -82,7 +82,7 @@
 ;; - annotate-time ()                              OK
 ;; - annotate-current-time ()                      NOT NEEDED
 ;; - annotate-extract-revision-at-line ()          OK
-;; TAG SYSTEM
+;; TAG/BRANCH SYSTEM
 ;; - create-tag (dir name branchp)                 OK
 ;; - retrieve-tag (dir name update)                OK
 ;; MISCELLANEOUS
@@ -1572,13 +1590,25 @@ vc-git-annotate-extract-revision-at-line
 		    (expand-file-name fname (vc-git-root default-directory))))
 	  revision)))))
 
-;;; TAG SYSTEM
+;;; TAG/BRANCH SYSTEM
+
+(declare-function vc-read-revision "vc"
+                  (prompt &optional files backend default initial-input))
 
 (defun vc-git-create-tag (dir name branchp)
-  (let ((default-directory dir))
-    (and (vc-git-command nil 0 nil "update-index" "--refresh")
+  (let ((default-directory dir)
+        (start-point (when branchp (vc-read-revision
+                                    (format-prompt "Start point"
+                                                   (car (vc-git-branches)))
+                                    (list dir) 'Git))))
+    (and (or (zerop (vc-git-command nil t nil "update-index" "--refresh"))
+             (y-or-n-p "Modified files exist.  Proceed? ")
+             (user-error (format "Can't create %s with modified files"
+                                 (if branchp "branch" "tag"))))
          (if branchp
-             (vc-git-command nil 0 nil "checkout" "-b" name)
+             (vc-git-command nil 0 nil "checkout" "-b" name
+                             (when (and start-point (not (eq start-point "")))
+                               start-point))
            (vc-git-command nil 0 nil "tag" name)))))
 
 (defun vc-git-retrieve-tag (dir name _update)
diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index 1f0eeb7e18..8f9e6010ee 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -857,6 +857,9 @@ vc-kill-buffer-hook
 ;; (autoload 'vc-prefix-map "vc" nil nil 'keymap)
 (defvar-keymap vc-prefix-map
   "a"   #'vc-update-change-log
+  "b c" #'vc-create-branch
+  "b l" #'vc-print-branch-log
+  "b s" #'vc-switch-branch
   "d"   #'vc-dir
   "g"   #'vc-annotate
   "G"   #'vc-ignore
@@ -883,9 +887,6 @@ vc-prefix-map
 (fset 'vc-prefix-map vc-prefix-map)
 (define-key ctl-x-map "v" 'vc-prefix-map)
 
-(with-suppressed-warnings ((obsolete vc-switch-backend))
-  (keymap-set vc-prefix-map "b" #'vc-switch-backend))
-
 (defvar vc-menu-map
   (let ((map (make-sparse-keymap "Version Control")))
     ;;(define-key map [show-files]
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 068a66b25b..aa8bad7961 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -356,7 +356,7 @@ vc-dir-mode-map
     (define-key map "G" #'vc-dir-ignore)
 
     (let ((branch-map (make-sparse-keymap)))
-      (define-key map "B" branch-map)
+      (define-key map "b" branch-map)
       (define-key branch-map "c" #'vc-create-tag)
       (define-key branch-map "l" #'vc-print-branch-log)
       (define-key branch-map "s" #'vc-retrieve-tag))

  parent reply	other threads:[~2022-09-11 15:10 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 18:43 bug#50344: C-x v keybinding for vc-print-branch-log Juri Linkov
2021-09-02 23:24 ` Dmitry Gutov
2021-09-03  8:15   ` Juri Linkov
2021-09-03 12:26     ` Dmitry Gutov
2021-09-03 16:18   ` Juri Linkov
2021-09-03 16:41     ` Dmitry Gutov
2021-09-04  6:33       ` Lars Ingebrigtsen
2021-09-05 16:28         ` Juri Linkov
2021-09-06  8:25           ` Lars Ingebrigtsen
2021-09-06 15:19             ` Juri Linkov
2021-09-07 15:05               ` Lars Ingebrigtsen
2021-09-08  2:58                 ` Dmitry Gutov
2021-09-08  8:00                   ` Lars Ingebrigtsen
2021-09-08 11:59                     ` Dmitry Gutov
2021-09-09 17:39                       ` Juri Linkov
2021-09-09 23:18                         ` Dmitry Gutov
2021-09-10  6:46                           ` Juri Linkov
2021-09-10 11:27                             ` Dmitry Gutov
2021-09-10 10:32                         ` Lars Ingebrigtsen
2021-09-10 11:26                           ` Dmitry Gutov
2021-09-13  7:47                             ` Juri Linkov
2021-10-07  7:21                               ` Juri Linkov
2021-10-07  7:47                                 ` Eli Zaretskii
2021-10-07  7:58                                   ` Juri Linkov
2021-10-07  8:28                                     ` Eli Zaretskii
2021-10-07 11:12                                       ` Dmitry Gutov
2021-10-07 12:56                                         ` Eli Zaretskii
2021-10-07 13:06                                           ` Dmitry Gutov
2021-10-07 13:21                                             ` Eli Zaretskii
2021-10-07 13:26                                               ` Dmitry Gutov
2021-10-07 13:50                                                 ` Eli Zaretskii
2021-10-07 17:36                                               ` Juri Linkov
2021-10-07 18:22                                                 ` Eli Zaretskii
2021-10-07 21:49                                               ` Dmitry Gutov
2021-10-12 12:48                                                 ` Filipp Gunbin
2021-10-13  1:45                                                   ` Dmitry Gutov
2021-10-13 10:12                                                     ` Filipp Gunbin
2021-10-13 23:37                                                       ` Dmitry Gutov
2021-12-24 11:56                                                         ` Philip Kaludercic
2021-12-24 12:03                                                           ` Dmitry Gutov
2021-12-24 13:57                                                             ` Philip Kaludercic
2021-12-24 23:45                                                               ` Dmitry Gutov
2021-12-25 11:37                                                                 ` Philip Kaludercic
2021-12-25 12:08                                                                   ` Dmitry Gutov
2022-09-09  5:46                                                         ` Sean Whitton
2022-09-09  6:29                                                           ` Juri Linkov
2022-09-09 17:09                                                             ` Lars Ingebrigtsen
2022-09-11 15:10                                                           ` Juri Linkov [this message]
2022-09-11 15:25                                                             ` Lars Ingebrigtsen
2022-09-12 18:07                                                               ` Juri Linkov
2022-09-12 18:21                                                                 ` Eli Zaretskii
2022-09-12 19:13                                                                   ` Juri Linkov
2022-09-13 12:24                                                                     ` Eli Zaretskii
2022-09-12 18:57                                                                 ` Sean Whitton
2021-10-07 13:11                                           ` Robert Pluim
2021-10-07 13:51                                             ` Filipp Gunbin
2021-10-07  9:57                                     ` Gregory Heytings
2021-10-07 11:14                                       ` Dmitry Gutov
2021-10-07 11:25                                         ` Gregory Heytings
2021-10-07 11:35                                           ` Dmitry Gutov
2021-10-07 11:42                                             ` Gregory Heytings
2021-10-07 12:25                                               ` Kévin Le Gouguec
2021-10-07 12:42                                             ` Filipp Gunbin
2021-10-07 12:53                                               ` Dmitry Gutov
2021-10-07 13:11                                             ` Eli Zaretskii
2021-10-07 12:51                                       ` Eli Zaretskii
2021-10-07 17:30                                         ` Juri Linkov
2021-10-07 18:25                                           ` Eli Zaretskii
2021-09-16 11:46                         ` Filipp Gunbin
2021-09-16 11:54                           ` Dmitry Gutov
2021-09-17 15:15                             ` Filipp Gunbin
2021-09-18  0:09                               ` bug#50643: " Dmitry Gutov
2021-09-18 19:03                                 ` Juri Linkov
2021-09-19  0:01                                   ` Dmitry Gutov
2021-09-19 17:04                                     ` bug#50643: " Juri Linkov
2021-09-20  0:33                                       ` Dmitry Gutov
2021-09-20  6:49                                         ` bug#50643: " Juri Linkov
2021-09-20 16:53                                           ` Dmitry Gutov
2021-09-20 17:31                                             ` Filipp Gunbin
2021-09-20 15:59                                   ` bug#50643: " Filipp Gunbin
2021-10-05 17:43                               ` Juri Linkov
2021-10-06  0:37                                 ` Dmitry Gutov
2021-10-06  7:29                                   ` Juri Linkov
2021-10-07  0:57                                     ` Dmitry Gutov
2021-10-06 16:28                                   ` Juri Linkov
2021-10-07  0:47                                     ` Dmitry Gutov
2021-10-07 12:46                                 ` Filipp Gunbin
2021-10-07 12:55                                   ` Robert Pluim
2021-10-07 17:27                                   ` Juri Linkov
2021-09-08  2:50         ` Dmitry Gutov
2021-09-08  7:53           ` Lars Ingebrigtsen

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=86y1uqxaj7.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=50344@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=fgunbin@fastmail.fm \
    --cc=larsi@gnus.org \
    --cc=spwhitton@spwhitton.name \
    /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).