From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: Re: support for git commit --amend/--signoff Date: Sat, 19 Jun 2010 02:38:46 -0400 Message-ID: References: <87hblavx6f.fsf@mail.jurta.org> <874oh94kdh.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1276929539 1848 80.91.229.12 (19 Jun 2010 06:38:59 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 19 Jun 2010 06:38:59 +0000 (UTC) Cc: Juri Linkov , =?utf-8?B?xaB0xJtww6FuIE7Em21lYw==?= , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 19 08:38:58 2010 connect(): No such file or directory Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OPrhh-00067d-6w for ged-emacs-devel@m.gmane.org; Sat, 19 Jun 2010 08:38:57 +0200 Original-Received: from localhost ([127.0.0.1]:54683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OPrhg-0002Fe-FV for ged-emacs-devel@m.gmane.org; Sat, 19 Jun 2010 02:38:56 -0400 Original-Received: from [199.232.76.173] (port=49868 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OPrhZ-0002Ea-P6 for emacs-devel@gnu.org; Sat, 19 Jun 2010 02:38:49 -0400 Original-Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1OPrhY-0007zg-7Q for emacs-devel@gnu.org; Sat, 19 Jun 2010 02:38:49 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]:57700) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1OPrhX-0007zc-VH for emacs-devel@gnu.org; Sat, 19 Jun 2010 02:38:48 -0400 Original-Received: from dann by fencepost.gnu.org with local (Exim 4.69) (envelope-from ) id 1OPrhX-00016R-HO; Sat, 19 Jun 2010 02:38:47 -0400 In-Reply-To: (Stefan Monnier's message of "Sat\, 12 Jun 2010 16\:19\:43 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:126200 Archived-At: Stefan Monnier writes: >> We could have a log-edit-extra-flags function that computes a set of >> extra flags, and pass those flags to vc-git-checkin. > > If amend is triggered from a new command (like vc-amend), then there's no > need for any special support in log-edit. We could easily store the > relevant info in log-edit-callback or in vc-specific > buffer-local variables. The problem with that is that vc-amend does not integrate very well with C-x v v and it is very Git specific, and given the reluctance of some other VCs to change history, it does not seem that it will be generalized. More, it does not solve the problem of --signoff (which might be adopted by other VCs). Here's a solution that takes care of all problems and it is extensible. I adds one line to log-edit.el and two to vc.el. vc-git-log-edit-get-extra-flags-function does the work in vc-git.el === modified file 'lisp/vc/log-edit.el' --- lisp/vc/log-edit.el 2010-06-12 17:14:43 +0000 +++ lisp/vc/log-edit.el 2010-06-16 17:37:47 +0000 @@ -189,6 +189,7 @@ when this variable is set to nil.") (defvar log-edit-callback nil) (defvar log-edit-diff-function nil) (defvar log-edit-listfun nil) +(defvar log-edit-get-extra-flags-function nil) (defvar log-edit-parent-buffer nil) === modified file 'lisp/vc/vc.el' --- lisp/vc/vc.el 2010-06-11 19:09:57 +0000 +++ lisp/vc/vc.el 2010-06-16 19:09:37 +0000 @@ -1398,7 +1406,9 @@ Runs the normal hooks `vc-before-checkin ;; vc-checkin-switches, but 'the' local buffer is ;; not a well-defined concept for filesets. (progn - (vc-call-backend backend 'checkin files rev comment) + (vc-call-backend backend 'checkin files rev comment + (when log-edit-get-extra-flags-function + (funcall log-edit-get-extra-flags-function))) (mapc 'vc-delete-automatic-version-backups files)) `((vc-state . up-to-date) (vc-checkout-time . ,(nth 5 (file-attributes file))) === modified file 'lisp/vc/vc-annotate.el' === modified file 'lisp/vc/vc-bzr.el' === modified file 'lisp/vc/vc-git.el' --- lisp/vc/vc-git.el 2010-06-11 19:09:57 +0000 +++ lisp/vc/vc-git.el 2010-06-16 18:10:00 +0000 @@ -550,13 +550,65 @@ or an empty string if none." (declare-function log-edit-extract-headers "log-edit" (headers string)) -(defun vc-git-checkin (files rev comment) +(defvar vc-git-log-edit-signoff nil) + +(defvar vc-git-log-edit-amend nil) + +(defun vc-git-log-edit-toggle-signoff () + (interactive) + (setq vc-git-log-edit-signoff (not vc-git-log-edit-signoff))) + +(defun vc-git-log-edit-toggle-amend () + (interactive) + (unless vc-git-log-edit-amend + (vc-git-command (current-buffer) 1 nil + "log" "--max-count=1" "--pretty=format:%s" "HEAD")) + (setq vc-git-log-edit-amend (not vc-git-log-edit-amend))) + +(defvar vc-git-log-edit-map + (let ((map (make-sparse-keymap "Git-Log-Edit")) + (menu-map (make-sparse-keymap))) + + ;; FIXME: Are these key bindings OK? + (define-key map "\C-c\C-s" 'vc-git-log-edit-toggle-signoff) + (define-key map "\C-c\C-m" 'vc-git-log-edit-toggle-amend) + + ;; FIXME: This does not work. And it would be better if we could + ;; add items to the Log-Edit menu. + (define-key map [menu-bar vc-git-log-edit] (cons "Git-Log-Edit" menu-map)) + (define-key menu-map [ts] + '(menu-item "Signoff" vc-git-log-edit-toggle-signoff + :help "Toggle signoff" + :button (:toggle . vc-git-log-edit-signoff))) + (define-key menu-map [ta] + '(menu-item "Amend" vc-git-log-edit-toggle-amend + :help "Toggle amend, insert old log when turning it on" + :button (:toggle . vc-git-log-edit-amend))) + map)) + +(define-derived-mode vc-git-log-edit-mode log-edit-mode "*VC-log*" + "Major mode for editing Git log messages. +It is based on `log-edit-mode', it has Git specific extensions." + (set (make-local-variable 'log-edit-get-extra-flags-function) + 'vc-git-log-edit-get-extra-flags-function) + (make-local-variable 'vc-git-log-edit-signoff) + (make-local-variable 'vc-git-log-edit-amend)) + +(defun vc-git-log-edit-get-extra-flags-function () + (let (result) + (when vc-git-log-edit-amend + (push "--amend" result)) + (when vc-git-log-edit-signoff + (push "--signoff" result)))) + +(defun vc-git-checkin (files rev comment &optional extra-flags) (let ((coding-system-for-write vc-git-commits-coding-system)) (apply 'vc-git-command nil 0 files (nconc (list "commit" "-m") (log-edit-extract-headers '(("Author" . "--author") ("Date" . "--date")) comment) + extra-flags (list "--only" "--"))))) (defun vc-git-find-revision (file rev buffer)