You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ma...@apache.org on 2012/08/16 19:40:00 UTC

svn commit: r1373942 - /subversion/trunk/contrib/client-side/emacs/dsvn.el

Author: mattiase
Date: Thu Aug 16 17:40:00 2012
New Revision: 1373942

URL: http://svn.apache.org/viewvc?rev=1373942&view=rev
Log:
When committing unversioned files or directories, add them after asking the
user. Doing so helps in the common situation when the user has forgotten to
add files before marking files for a commit and does not want to start all
over.

* contrib/client-side/emacs/dsvn.el
  (svn-add-unversioned-files-p): New function.
  (svn-commit): Gather unversioned files and, if any, add them after asking.
  (svn-actions): Rewrite, to allow actual use of the predicate.

Modified:
    subversion/trunk/contrib/client-side/emacs/dsvn.el

Modified: subversion/trunk/contrib/client-side/emacs/dsvn.el
URL: http://svn.apache.org/viewvc/subversion/trunk/contrib/client-side/emacs/dsvn.el?rev=1373942&r1=1373941&r2=1373942&view=diff
==============================================================================
--- subversion/trunk/contrib/client-side/emacs/dsvn.el (original)
+++ subversion/trunk/contrib/client-side/emacs/dsvn.el Thu Aug 16 17:40:00 2012
@@ -360,21 +360,55 @@ Argument ARG are the command line argume
 		       (append svn-diff-args (split-string arg))
 		       'diff-mode))
 
+(defun svn-add-unversioned-files-p (files)
+  "Ask the user whether FILES should be added; return the answer."
+  (let ((buf (get-buffer-create "*svn-unversioned-files*")))
+    (with-current-buffer buf
+      (setq buffer-read-only nil)
+      (erase-buffer)
+      (insert (mapconcat (lambda (f) f) files "\n"))
+      (setq buffer-read-only t)
+      (goto-char (point-min))
+      (save-selected-window
+        (pop-to-buffer buf)
+        (shrink-window-if-larger-than-buffer)
+        (let* ((n (length files))
+               (add-them (y-or-n-p
+                          (if (= n 1)
+                              "Add this item first? "
+                            (format "Add these %d items first? " n)))))
+          (let ((win (get-buffer-window buf)))
+            (if win
+                (condition-case nil
+                    (delete-window win)
+                  (error nil))))
+          (bury-buffer buf)
+          add-them)))))
+
 (defun svn-commit ()
   "Commit changes to one or more files."
   (interactive)
   (save-some-buffers)
-  (let ((status-buf (current-buffer))
-        (commit-buf (get-buffer-create "*svn commit*"))
-        (window-conf (and svn-restore-windows (current-window-configuration)))
-        (listfun (lambda () (with-current-buffer log-edit-parent-buffer
-                              (svn-action-files)))))
-    (log-edit 'svn-confirm-commit t
-              (if (< emacs-major-version 23)
-                  listfun
-                (list (cons 'log-edit-listfun listfun)))
-              commit-buf)
-    (set (make-local-variable 'saved-window-configuration) window-conf)))
+  (let ((unversioned-files (svn-action-files
+                            (lambda (pos) (eq (svn-file-status pos) ?\?)))))
+    (if unversioned-files
+        (if (svn-add-unversioned-files-p unversioned-files)
+            (progn
+              (message "Adding unversioned items. Please re-commit when ready.")
+              (svn-run 'add unversioned-files "Adding files"))
+          (message "Files not added; nothing committed."))
+      (let ((status-buf (current-buffer))
+            (commit-buf (get-buffer-create "*svn commit*"))
+            (window-conf (and svn-restore-windows
+                              (current-window-configuration)))
+            (listfun (lambda () (with-current-buffer log-edit-parent-buffer
+                                  (svn-action-files)))))
+        (log-edit 'svn-confirm-commit t
+                  (if (< emacs-major-version 23)
+                      listfun
+                    (list (cons 'log-edit-listfun listfun)))
+                  commit-buf)
+        (set (make-local-variable 'saved-window-configuration) window-conf)))))
 
 (defun svn-confirm-commit ()
   "Commit changes with the current buffer as commit message."
@@ -1643,27 +1677,24 @@ Set it if MARK is non-NIL, and clear it 
   "Return a list of lists (FILE POS) to act on.
 Optional argument PRED is a predicate function that is called with POS as
 argument."
-  (let ((files ())
-        (pos (next-single-property-change (point-min) 'svn-file)))
-    (while pos
-      (when (and (get-text-property pos 'svn-mark)
-                 (or (not pred)
-                     (funcall pred pos)))
-        (setq files (cons (list (get-text-property pos 'svn-file)
-                                pos)
-                          files)))
-      (setq pos (next-single-property-change pos 'svn-file)))
-    (if (null files)
-        (let ((file (svn-getprop (point) 'file)))
-          (unless file
-            (error "No file on this line"))
-          (when (and pred
-                     (not (funcall pred (line-beginning-position))))
-            (error "Invalid file"))
-          (list (list file
-                      (save-excursion
-                        (beginning-of-line)
-                        (point)))))
+  (let ((positions ()))
+    (let ((pos (next-single-property-change (point-min) 'svn-file)))
+      (while pos
+        (when (get-text-property pos 'svn-mark)
+          (setq positions (cons pos positions)))
+        (setq pos (next-single-property-change pos 'svn-file))))
+    (when (null positions)
+      (unless (svn-getprop (point) 'file)
+        (error "No file on this line"))
+      (setq positions (list (line-beginning-position))))
+
+    (let ((files ()))
+      (mapc (lambda (pos)
+              (when (or (not pred) (funcall pred pos))
+                (setq files (cons (list (get-text-property pos 'svn-file)
+                                        pos)
+                                  files))))
+            (reverse positions))
       (reverse files))))
 
 (defun svn-action-files (&optional pred)