[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug#881: patch for bug #881

From: Dan Nicolaescu
Subject: Re: bug#881: patch for bug #881
Date: Thu, 7 Jan 2010 09:09:52 -0800 (PST)

Stefan Monnier <address@hidden> writes:

  > >> > How should it work? We don't have any nice generic mechanism/UI for
  > >> > doing VC backend specific things in the commit buffer.
  > >> It's a general concept, although it's not supported by all backends.
  > > The general concept is that backends want to do backend specific things 
  > That's another part.  But for "author", I think we should support it in
  > the generic part of the VC code.  After all, it's a concept we've been
  > using in ChangeLog for ages: the fact that only recent VCS support it is
  > no excuse ;-)
  > > This would be helpful, but not enough, we also want to have some key
  > > bindings, menu entries for backend specific things.
  > > So how about starting by replacing the call to `log-edit' in
  > > `vc-log-edit' with (vc-call-backend backend 'log-edit)
  > > and then each backend that so desires can implement a mode derived from
  > > log-edit and do whatever it wants (like we do for log-view).
  > Fine by me.  But please remember that whenever possible and meaningful,
  > it's better to add features to vc.el than to particular backends.

Here's a 100% untested version of this.  It serves all the needs I can
think off at the moment.
git can add "--amend" and "--signoff" to `log-edit-extra-flags'.
Author: "foo bar" address@hidden
can be dealt with using `log-edit-before-checkin-process'.
We can add a key binding to log-edit.el to insert Author: in the buffer.
The part that removes the extra markup (i.e. Author: ) from the buffer
is not implemented, but it should not be too hard.

What do you think?

Index: vc.el
RCS file: /cvsroot/emacs/emacs/lisp/vc.el,v
retrieving revision 1.746
diff -u -3 -p -r1.746 vc.el
--- vc.el       7 Dec 2009 09:02:16 -0000       1.746
+++ vc.el       7 Jan 2010 16:56:25 -0000
@@ -261,7 +261,7 @@
 ;;   Unregister FILE from this backend.  This is only needed if this
 ;;   backend may be used as a "more local" backend for temporary editing.
-;; * checkin (files rev comment)
+;; * checkin (files rev comment &rest args)
 ;;   Commit changes in FILES to this backend.  If REV is non-nil, that
 ;;   should become the new revision number (not all backends do
@@ -269,6 +269,7 @@
 ;;   implementation should pass the value of vc-checkin-switches to
 ;;   the backend command.  (Note: in older versions of VC, this
 ;;   command took a single file argument and not a list.)
+;;   ARGS should be passed to the backend command.
 ;; * find-revision (file rev buffer)
@@ -477,6 +478,12 @@
 ;;   Return the revision number that follows REV for FILE, or nil if no such
 ;;   revision exists.
+;; - log-edit-mode ()
+;;   Return a symbol that is the mode to use for editing the check in
+;;   log.  This defaults to `log-edit-mode' and is expected to be
+;;   changed (if at all) to a derived mode of `log-edit-mode'.
 ;; - check-headers ()
 ;;   Return non-nil if the current buffer contains any version headers.
@@ -1348,7 +1365,7 @@ Runs the normal hooks `vc-before-checkin
     files rev comment initial-contents
     "Enter a change comment."
-    (lambda (files rev comment)
+    (lambda (files rev comment extra-flags)
       (message "Checking in %s..." (vc-delistify files))
       ;; "This log message intentionally left almost blank".
       ;; RCS 5.7 gripes about white-space-only comments too.
@@ -1359,7 +1376,7 @@ Runs the normal hooks `vc-before-checkin
        ;; We used to change buffers to get local value of vc-checkin-switches,
        ;; but 'the' local buffer is not a well-defined concept for filesets.
-        (vc-call-backend backend 'checkin files rev comment)
+        (vc-call-backend backend 'checkin files rev comment extra-flags)
         (mapc 'vc-delete-automatic-version-backups files))
        `((vc-state . up-to-date)
         (vc-checkout-time . ,(nth 5 (file-attributes file)))
@@ -1729,7 +1746,7 @@ The headers are reset to their non-expan
    files rev oldcomment t
    "Enter a replacement change comment."
-   (lambda (files rev comment)
+   (lambda (files rev comment ignored)
       ;; Less of a kluge than it looks like; log-view mode only passes
       ;; this function a singleton list.  Arguments left in this form in
@@ -2414,6 +2431,8 @@ to provide the `find-revision' operation
 (defalias 'vc-default-check-headers 'ignore)
+(defun vc-default-log-edit-mode (backend) 'log-edit-mode)
 (defun vc-default-log-view-mode (backend) (log-view-mode))
 (defun vc-default-show-log-entry (backend rev)
Index: vc-dispatcher.el
RCS file: /cvsroot/emacs/emacs/lisp/vc-dispatcher.el,v
retrieving revision 1.71
diff -u -3 -p -r1.71 vc-dispatcher.el
--- vc-dispatcher.el    1 Oct 2009 03:32:27 -0000       1.71
+++ vc-dispatcher.el    7 Jan 2010 16:56:26 -0000
@@ -526,7 +526,9 @@ NOT-URGENT means it is ok to continue if
   (log-edit 'vc-finish-logentry
            `((log-edit-listfun . (lambda () ',fileset))
-             (log-edit-diff-function . (lambda () (vc-diff nil)))))
+             (log-edit-diff-function . (lambda () (vc-diff nil))))
+           nil
+           (vc-call-backend (car fileset) 'log-edit-mode))
   (set (make-local-variable 'vc-log-fileset) fileset)
   (make-local-variable 'vc-log-extra)
   (set-buffer-modified-p nil)
@@ -587,6 +589,15 @@ the buffer contents as a comment."
     (or (vc-dispatcher-browsing) (vc-buffer-sync)))
   (unless vc-log-operation
     (error "No log operation is pending"))
+  ;; FIXME: this should be a function in log-edit.el
+  (when log-edit-before-checkin-process
+    (dolist (crt log-edit-before-checkin-process)
+      ;; Remove all lines matching (car crt)
+      ;; Append to `log-edit-extra-flags' the results of (cdr crt).
+      )
+    )
   ;; save the parameters held in buffer-local variables
   (let ((logbuf (current-buffer))
        (log-operation vc-log-operation)
@@ -601,7 +612,8 @@ the buffer contents as a comment."
       (funcall log-operation
-              log-entry))
+              log-entry
+              log-edit-extra-flags))
     ;; Remove checkin window (after the checkin so that if that fails
     ;; we don't zap the log buffer and the typing therein).
     ;; -- IMO this should be replaced with quit-window
Index: log-edit.el
RCS file: /cvsroot/emacs/emacs/lisp/log-edit.el,v
retrieving revision 1.56
diff -u -3 -p -r1.56 log-edit.el
--- log-edit.el 2 Oct 2009 03:48:41 -0000       1.56
+++ log-edit.el 7 Jan 2010 16:56:26 -0000
@@ -185,6 +185,25 @@ 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-extra-flags nil
+  "List of extra flags to pass to the check in command.")
+(defvar log-edit-before-checkin-process nil
+  "Alist that contains instructions for processing the commit message before 
check in.
+The format is: (REGEXP . INSTRUCTIONS).
+All lines matching REGEXP are removed.
+For example:
+(\"^#.*\" . nil)
+means: just remove all lines starting with #.  This can be used
+to insert lines in the commit buffer that contain for example the
+list of files to be committed.
+(\"Author: \\(.*\\)\" . (list \"--author\" (match-string 1)))
+means: append (list \"--author\" (match-string 1)) to 
 (defvar log-edit-parent-buffer nil)
 ;;; Originally taken from VC-Log mode
@@ -315,9 +334,10 @@ automatically."
      (2 font-lock-function-name-face))))
-(defun log-edit (callback &optional setup params buffer &rest ignore)
+(defun log-edit (callback &optional setup params buffer mode &rest ignore)
   "Setup a buffer to enter a log message.
-\\<log-edit-mode-map>The buffer will be put in `log-edit-mode'.
+\\<log-edit-mode-map>The buffer will be put in mode MODE or `log-edit-mode'
+if MODE is nil.
 If SETUP is non-nil, the buffer is then erased and `log-edit-hook' is run.
 Mark and point will be set around the entire contents of the buffer so
 that it is easy to kill the contents of the buffer with \\[kill-region].
@@ -338,7 +358,9 @@ uses the current buffer."
     (when (and log-edit-setup-invert (not (eq setup 'force)))
       (setq setup (not setup)))
     (when setup (erase-buffer))
-    (log-edit-mode)
+    (if mode
+       (funcall mode)
+      (log-edit-mode))
     (set (make-local-variable 'log-edit-callback) callback)
     (if (listp params)
        (dolist (crt params)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]