From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#57400: 29.0.50; Support sending patches from VC directly Date: Mon, 03 Oct 2022 18:59:09 +0000 Message-ID: <87y1twvima.fsf@posteo.net> References: <84v8qgn1z9.fsf@iki.fi> <87h71zo3p8.fsf@posteo.net> <87sfljmgwz.fsf@posteo.net> 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="2377"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 57400@debbugs.gnu.org To: Antoine Kalmbach Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 03 21:00:39 2022 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 1ofQgB-0000QI-B4 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 03 Oct 2022 21:00:39 +0200 Original-Received: from localhost ([::1]:38932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofQgA-0008Ki-9X for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 03 Oct 2022 15:00:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofQfb-0008HZ-4A for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2022 15:00:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofQfa-0007Su-RC for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2022 15:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ofQfa-0000NG-CA for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2022 15:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 03 Oct 2022 19:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57400 X-GNU-PR-Package: emacs Original-Received: via spool by 57400-submit@debbugs.gnu.org id=B57400.16648235631366 (code B ref 57400); Mon, 03 Oct 2022 19:00:02 +0000 Original-Received: (at 57400) by debbugs.gnu.org; 3 Oct 2022 18:59:23 +0000 Original-Received: from localhost ([127.0.0.1]:51726 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ofQew-0000Ly-RF for submit@debbugs.gnu.org; Mon, 03 Oct 2022 14:59:23 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:44189) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ofQeu-0000Lg-Gp for 57400@debbugs.gnu.org; Mon, 03 Oct 2022 14:59:21 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 63802240028 for <57400@debbugs.gnu.org>; Mon, 3 Oct 2022 20:59:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1664823554; bh=SlZ1K0apbE2dG2ZBaQu4zge0AWypMjGnWVYB0tF5jW8=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=bNxRQAmqLGZtxoz7fYjx2bmsHWboho70pGO6/RsnbOVKHzRgRJ/isWtU+z5UpXcYF I9KRgktFXTGmLSuT5KRWZEEngAwrMTW/gm3EIa9YYvGwh4dtmgavVmM+XWugnFbAgJ Fs+FKwU+349da47EjxqxbIBlqv9U1HI+EAXiTtoxk5CEQC6g3nffWfY0MM5Pi8n9sM WTHCgX55byQNsvC+5lyFF+IgtCFjAT0cJIGpAO46ibU7ICCQID2Xampo6bsTcXjBkm /IAlSQdjFQeoYkNSZgyrte6kAncds6pfKcFl2JHC8pvqO2G/BaP7xUjLTxLEcCjyus seJj812g9iimg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Mh99Y3Yx2z6tmM; Mon, 3 Oct 2022 20:59:10 +0200 (CEST) In-Reply-To: (Antoine Kalmbach's message of "Fri, 26 Aug 2022 13:45:51 +0300") Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB 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" Xref: news.gmane.io gmane.emacs.bugs:244327 Archived-At: --=-=-= Content-Type: text/plain Antoine Kalmbach writes: > Philip Kaludercic writes: > >> Yes, and I began implementing a different approach (as mentioned on the >> emacs-devel thread), which I have since abandoned. If you haven't >> written anything yet, and don't insist on it, I could propose to start >> sketching out your suggestions. > > Sure! I was thinking we could start from a very basic command, call it > `vc-prepare-patch` as per your suggestion. Since VC uses generics, we > can dispatch to backend-specific implementations, something like this, > with Git: > > 1. `M-x vc-prepare-patch` > 2. Dispatch to `vc-git-prepare-patch` > 3. Git wants a revision range, so interactively prompt for that > (e.g. `HEAD^`, `abcd1234..ghjk5678`, or `-1`) > 4. `call-process` to `git format-patch $REV`, and so forth, get the > list of files. > 5. Loop each file in `message-mode`. `C-c C-c` sends and goes to the > next patch, `C-c C-k` cancels the whole thing. Sorry for the delay, here is a first approximation of this idea: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-a-command-to-send-patches.patch >From a350b7cbd1b61925c687b501c6251a8ef4fb5549 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Mon, 3 Oct 2022 20:54:38 +0200 Subject: [PATCH] Add a command to send patches * lisp/vc/vc-git.el (vc-git-prepare-patch): Add Git implementation. * lisp/vc/vc.el (vc-read-revision): Add a MULTIPLE argument. (vc-read-multiple-revisions): Add an auxiliary function that always calls 'vc-read-revision' with a non-nil value for MULTIPLE. (vc-compose-patches-inline): Add user option. (message-goto-body): Declare function. (message--name-table): Declare function. (vc-compose-patch): Add command. (bug#57400) --- lisp/vc/vc-git.el | 27 ++++++++++++++++++ lisp/vc/vc.el | 70 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index f5ac43f536..439e82b12e 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1705,6 +1705,33 @@ vc-git-extra-status-menu (defun vc-git-root (file) (vc-find-root file ".git")) +(defun vc-git-prepare-patch (rev) + (with-temp-buffer + (call-process vc-git-program nil t nil "format-patch" + "--no-numbered" "--stdout" + ;; From gitrevisions(7): ^ means the th parent + ;; (i.e. ^ is equivalent to ^1). As a + ;; special rule, ^0 means the commit itself and + ;; is used when is the object name of a tag + ;; object that refers to a commit object. + (concat rev "^0")) + (let (filename subject body) + ;; Save the patch in a temporary file if required + (when (bound-and-true-p vc-compose-patches-inline) + (setq filename (make-temp-file "vc-git-prepare-patch")) + (write-region nil nil filename)) ;FIXME: Clean up + ;; Extract the subject line + (goto-char (point-min)) + (search-forward-regexp "^Subject: \\(.+\\)") + (setq subject (match-string 1)) + ;; Extract the patch body + (search-forward-regexp "\n\n") + (setq body (buffer-substring (point) (point-max))) + ;; Return the extracted data + (list :filename filename + :subject subject + :body body)))) + ;; grep-compute-defaults autoloads grep. (declare-function grep-read-regexp "grep" ()) (declare-function grep-read-files "grep" (regexp)) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 24300e014a..e990f51a91 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -574,6 +574,14 @@ ;; containing FILE-OR-DIR. The optional REMOTE-NAME specifies the ;; remote (in Git parlance) whose URL is to be returned. It has ;; only a meaning for distributed VCS and is ignored otherwise. +;; +;; - prepare-patch (rev) +;; +;; Prepare a patch and return a property list with the keys +;; `:subject' indicating the patch message as a string, `:body' +;; containing the contents of the patch as a string (excluding the +;; header) and `:filename' pointing to a file where the patch has +;; been stored. ;;; Changes from the pre-25.1 API: ;; @@ -1910,7 +1918,7 @@ vc-diff-internal (defvar vc-revision-history nil "History for `vc-read-revision'.") -(defun vc-read-revision (prompt &optional files backend default initial-input) +(defun vc-read-revision (prompt &optional files backend default initial-input multiple) (cond ((null files) (let ((vc-fileset (vc-deduce-fileset t))) ;FIXME: why t? --Stef @@ -1920,9 +1928,16 @@ vc-read-revision (let ((completion-table (vc-call-backend backend 'revision-completion-table files))) (if completion-table - (completing-read prompt completion-table - nil nil initial-input 'vc-revision-history default) - (read-string prompt initial-input nil default)))) + (funcall + (if multiple #'completing-read-multiple #'completing-read) + prompt completion-table nil nil initial-input 'vc-revision-history default) + (let ((answer (read-string prompt initial-input nil default))) + (if multiple + (split-string answer "[ \t]*,[ \t]*") + answer))))) + +(defun vc-read-multiple-revisions (prompt &optional files backend default initial-input) + (vc-read-revision prompt files backend default initial-input t)) (defun vc-diff-build-argument-list-internal (&optional fileset) "Build argument list for calling internal diff functions." @@ -3243,6 +3258,53 @@ vc-update-change-log (vc-call-backend (vc-responsible-backend default-directory) 'update-changelog args)) +(defcustom vc-compose-patches-inline nil + "Non-nil means that `vc-compose-patch' creates a single message." + :type 'boolean + :safe #'booleanp) + +(declare-function message-goto-body "message" (&optional interactive)) +(declare-function message--name-table "message" (orig-string)) + +;;;###autoload +(defun vc-compose-patch (addressee subject revisions) + "Compose a message sending REVISIONS to ADDRESSEE with SUBJECT." + (interactive (save-current-buffer + (require 'message) + (vc-ensure-vc-buffer) + (let ((revs (vc-read-multiple-revisions "Revisions: ")) to) + (while (null (setq to (completing-read-multiple + "Whom to send: " + (message--name-table "")))) + (message "At least one addressee required.") + (sit-for 1)) + (list (string-join to ", ") + (read-string "Subject: " "[PATCH] " nil nil t) + revs)))) + (require 'message) + (save-current-buffer + (vc-ensure-vc-buffer) + (let ((patches (mapcar (lambda (rev) + (vc-call-backend + (vc-responsible-backend default-directory) + 'prepare-patch rev)) + revisions))) + (if (not vc-compose-patches-inline) + (dolist (patch patches) + (compose-mail addressee (plist-get patch :subject) + nil nil nil nil + `((exit-recursive-edit))) + (message-goto-body) + (save-excursion ;don't jump to the end + (insert (plist-get patch :body))) + (recursive-edit)) + (compose-mail addressee subject) + (message-goto-body) + (dolist (patch patches) + (mml-attach-file (plist-get patch :filename) "text/x-patch")) + (message-goto-body) + (open-line 2))))) + (defun vc-default-responsible-p (_backend _file) "Indicate whether BACKEND is responsible for FILE. The default is to return nil always." -- 2.37.3 --=-=-= Content-Type: text/plain The documentation is not complete yet, and I haven't tested it yet extensively, but it fundamentally does the right thing. I am not too sure about the generic interface and the plist that `prepare-patch' returns. There might be a better way to do this, generating less garbage, but I'm stuck between trying to be VC-generic and MUA-generic which is unsurprisingly tricky. > Once the file opens in message-mode, most likely we need to strip the > magic From header from the beginning of the mail. Then we ensure > don't do any nasty whitespace removal or wrapping. > > Most likely, depending on the backend, we should not require any > parameters besides the "set of changes". For instance, in Git you can > configure `git-format-patch` in the git configuration for several > attributes, like --to=, --annotate, --prefix, etc. > > I don't remember how Mercurial works with this. Probably similar. It > should generate mbox entries as well, I think. --=-=-=--