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 21:55:35 +0000 Message-ID: <87mtacvag8.fsf@posteo.net> References: <84v8qgn1z9.fsf@iki.fi> <87h71zo3p8.fsf@posteo.net> <87sfljmgwz.fsf@posteo.net> <87y1twvima.fsf@posteo.net> <878rlw681a.fsf@gnus.org> <87r0zovbzr.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="33989"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 57400@debbugs.gnu.org, Antoine Kalmbach To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 04 00:29:53 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 1ofTwe-0008ha-Tp for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 04 Oct 2022 00:29:53 +0200 Original-Received: from localhost ([::1]:55736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofTwd-0000sQ-2L for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 03 Oct 2022 18:29:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofTPu-0000Pw-Lj for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2022 17:56:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofTPu-0001km-DG for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2022 17:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ofTPu-00050n-0o for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2022 17:56: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 21:56:01 +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.166483414819244 (code B ref 57400); Mon, 03 Oct 2022 21:56:01 +0000 Original-Received: (at 57400) by debbugs.gnu.org; 3 Oct 2022 21:55:48 +0000 Original-Received: from localhost ([127.0.0.1]:51854 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ofTPg-00050K-4r for submit@debbugs.gnu.org; Mon, 03 Oct 2022 17:55:48 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:55449) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ofTPc-000503-VM for 57400@debbugs.gnu.org; Mon, 03 Oct 2022 17:55:46 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id E3C15240101 for <57400@debbugs.gnu.org>; Mon, 3 Oct 2022 23:55:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1664834138; bh=uZudC1F1RLBQLAObj+lEEKAWvD9sWfJtYeUaeLr+DF4=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=JV+/BcSLRtfJTtMk3WeZiQZlBsohWVwZUMdrWBLeooHYBcrc4HR7Lbh4ifCKIMq8A LeHC4I8nZBKmWibItadO/43tSTvIGV9TCaEdHK8Lzzr+yiVRwcd+Hl48c/3ZQZb9Wi 5Ub6jJHDmVQPXUQmTmfn6fDJbl/kpiT5I7iHpHhrPruKKj9niq5NcG2/z3Oc/I/Fkb ty2zOElKUTlRb0YFEQRd2lVgdJXfk3lgnNtu9jJymnjjHDe3n2qy8kfZyeAYvDKCqG WC+Z/n/fqKH0GIuo2miF9BCAtLnNjxAyIKNGF8c3D909Wl4WuEIJrys9RqMB2i6p1K q1nM87dD+b+fA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MhF550SN6z6tnW; Mon, 3 Oct 2022 23:55:35 +0200 (CEST) In-Reply-To: <87r0zovbzr.fsf@posteo.net> (Philip Kaludercic's message of "Mon, 03 Oct 2022 23:22:16 +0200") 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:244337 Archived-At: --=-=-= Content-Type: text/plain Philip Kaludercic writes: > Eli Zaretskii writes: > >>> Cc: 57400@debbugs.gnu.org, Antoine Kalmbach >>> From: Lars Ingebrigtsen >>> Date: Mon, 03 Oct 2022 21:06:57 +0200 >>> >>> Do many other VCs have commands to prepare patches like this? >> >> Hg and bzr do have such commands. > > Yes, and I would plan to implement it for these as well (even though I > have never used bzr). > >> Others should indeed run vc-diff, I >> think. > > That seem possible, but for that to work I will need a generic way to > detect the predecessor of a commit and extract a commit message. > Currently, I am not sure if this can be done. I had forgotten about `previous-revision', so that was easy and I decided to fall back to a generic subject as that can be easily revised: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-a-command-to-send-patches.patch >From cfb24a0bd74d4af4e4ed86f5a0029cb7f2cf1aed 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-default-prepare-patch): Add a default implementation. (vc-compose-patch): Add command. (bug#57400) --- lisp/vc/vc-git.el | 27 ++++++++++++++ lisp/vc/vc.el | 90 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 113 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..70f1f75d00 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,73 @@ 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)) + +(defun vc-default-prepare-patch (rev) + (let ((backend (vc-backend buffer-file-name)) + filename) + (with-temp-buffer + (vc-diff-internal + nil (list backend) rev + (vc-call-backend backend 'previous-revision + buffer-file-name rev) + nil t) + (when vc-compose-patches-inline + (setq filename (make-temp-file "vc-default-prepare-patch")) + (write-region nil nil filename)) + (list :filename filename :body (buffer-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 + (or (plist-get patch :subject) + (concat + "Patch for " ;guess + (file-name-nondirectory + (directory-file-name + (vc-root-dir))))) + 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 --=-=-=--