all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dan Nicolaescu <dann@ics.uci.edu>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: emacs-devel@gnu.org
Subject: Re: allow C-x v i / C-x v v to create a repository if none is available
Date: Tue, 13 Oct 2009 08:59:38 -0700 (PDT)	[thread overview]
Message-ID: <200910131559.n9DFxcPD012765@godzilla.ics.uci.edu> (raw)
In-Reply-To: <jwvab00gz1x.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 09 Oct 2009 15:18:15 -0400")

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

  > > When doing C-x v i or C-x v v on an unregistered file that is in a
  > > directory not under any version control, the file will be registered
  > > with RCS.  That is not exactly what most users want.
  > 
  > Very good point.  In the past, there wasn't much choice anyway since
  > creating a CVS repository required a lot more work, but indeed, with
  > current DVCS such a behavior makes sense again.
  > 
  > Now, most relevant backends will also want to know where you want to put
  > the root of your new repository.  Should we let the backend function
  > `create-repo' prompt for this, or should we move it to the generic part
  > of the code?  You seem to have taken the first choice, whereas I'd lean
  > towards the second.

Here's an updated patch.  For the reasons that I showed in my previous
mail, I'm inclined to the first choice.  But if you really feel strongly
about this, I can change it.  Just outline how you want it done.

Index: vc.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/vc.el,v
retrieving revision 1.732
diff -u -3 -p -u -p -r1.732 vc.el
--- vc.el	3 Oct 2009 18:29:26 -0000	1.732
+++ vc.el	13 Oct 2009 15:49:45 -0000
@@ -564,9 +564,6 @@
 ;;
 ;;;; Default Behavior:
 ;;
-;; - do not default to RCS anymore when the current directory is not
-;;   controlled by any VCS and the user does C-x v v
-;;
 ;; - vc-responsible-backend should not return RCS if no backend
 ;;   declares itself responsible.
 ;;
@@ -634,7 +631,8 @@
 (require 'vc-dispatcher)
 
 (eval-when-compile
-  (require 'cl))
+  (require 'cl)
+  (require 'dired))
 
 (unless (assoc 'vc-parent-buffer minor-mode-alist)
   (setq minor-mode-alist
@@ -818,11 +816,14 @@ The optional argument REGISTER means tha
 registration should be found.
 
 If REGISTER is nil, then if FILE is already registered, return the
-backend of FILE.  If FILE is not registered, or a directory, then the
+backend of FILE.  If FILE is not registered, then the
 first backend in `vc-handled-backends' that declares itself
 responsible for FILE is returned.  If no backend declares itself
 responsible, return the first backend.
 
+If REGISTER is non-nil and FILE is a directory, create a VC
+repository that can be used to register FILE.
+
 If REGISTER is non-nil, return the first responsible backend under
 which FILE is not yet registered.  If there is no such backend, return
 the first backend under which FILE is not yet registered, but could
@@ -842,13 +843,47 @@ be registered."
 	(if (not register)
 	    ;; if this is not for registration, the first backend must do
 	    (car vc-handled-backends)
-	  ;; for registration, we need to find a new backend that
-	  ;; could register FILE
-	  (dolist (backend vc-handled-backends)
-	    (and (not (vc-call-backend backend 'registered file))
-		 (vc-call-backend backend 'could-register file)
-		 (throw 'found backend)))
-	  (error "No backend that could register")))))
+	  (if (file-directory-p file)
+	      (let* ((possible-backends
+		      (let (pos)
+			(dolist (crt vc-handled-backends)
+			  (when (vc-find-backend-function crt 'create-repo)
+			    (push crt pos)))
+			pos))
+		     (bk
+		      (intern
+		       ;; Read the VC backend from the user, only
+		       ;; complete with the backends that have the
+		       ;; 'create-repo method.
+		       (completing-read
+			(format "%s is not in a version controlled directory.\nUse VC backend: " file)
+			(mapcar 'symbol-name possible-backends) nil t)))
+		     (repo-dir
+		      (file-name-as-directory
+		       (let ((def-dir file))
+			 ;; read the directory where to create the
+			 ;; repository, make sure it's a parent of
+			 ;; file.
+			 (read-file-name
+			  (format "create %s repository in: " bk)
+			  default-directory nil t nil
+			  (lambda (arg)
+			    (and (file-directory-p arg)
+				 (vc-string-prefix-p (expand-file-name arg) def-dir))))))))
+		(let ((default-directory repo-dir))
+		  (vc-call-backend bk 'create-repo))
+		(throw 'found bk))
+
+	    ;; FIXME: this case does not happen with the current code.
+	    ;; Should we keep it?
+	    ;;
+	    ;; For registration, we need to find a new backend that
+	    ;; could register FILE.
+	    (dolist (backend vc-handled-backends)
+	      (and (not (vc-call-backend backend 'registered file))
+		   (vc-call-backend backend 'could-register file)
+		   (throw 'found backend))))
+	  (error "no backend that could register")))))
 
 (defun vc-expand-dirs (file-or-dir-list)
   "Expands directories in a file list specification.
@@ -889,6 +924,10 @@ current buffer."
     (cond
      ((derived-mode-p 'vc-dir-mode)
       (vc-dir-deduce-fileset state-model-only-files))
+     ((derived-mode-p 'dired-mode)
+      (if observer
+	  (vc-dired-deduce-fileset)
+	(error "state changing vc operations not supported in `dired-mode'")))
      ((setq backend (vc-backend buffer-file-name))
       (if state-model-only-files
 	(list backend (list buffer-file-name)
@@ -909,13 +948,13 @@ current buffer."
      ((and allow-unregistered (not (vc-registered buffer-file-name)))
       (if state-model-only-files
 	  (list (vc-responsible-backend
-		 (file-name-directory (buffer-file-name)))
+		 (file-name-directory (buffer-file-name)) t)
 		(list buffer-file-name)
 		(list buffer-file-name)
 		(when state-model-only-files 'unregistered)
 		nil)
 	(list (vc-responsible-backend
-	       (file-name-directory (buffer-file-name)))
+	       (file-name-directory (buffer-file-name)) t)
 	      (list buffer-file-name))))
      (t (error "No fileset is available here")))))
 




  parent reply	other threads:[~2009-10-13 15:59 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-08 20:47 allow C-x v i / C-x v v to create a repository if none is available Dan Nicolaescu
2009-10-08 21:10 ` Chong Yidong
2009-10-09 19:18 ` Stefan Monnier
2009-10-09 19:32   ` Dan Nicolaescu
2009-10-13 18:40     ` Stefan Monnier
2009-10-13 15:59   ` Dan Nicolaescu [this message]
2009-10-21 19:06   ` Dan Nicolaescu
2009-10-23  7:45     ` Dan Nicolaescu
2009-10-23 13:12       ` Stefan Monnier
2009-10-24  2:34       ` Miles Bader
2009-10-24  6:35         ` Dan Nicolaescu
2009-10-22 18:56   ` Code for converting between Elisp and Calc floats Jay Belanger
2009-10-22 20:04     ` James Cloos
2009-10-23  0:50     ` Stefan Monnier
2009-10-24 20:03       ` Jay Belanger
2009-10-25  0:56         ` Stefan Monnier
2009-10-25  5:36           ` David Kastrup
2009-10-25 11:36             ` Vincent Belaïche
2009-10-25 14:11               ` Chong Yidong
2009-10-25 19:29                 ` Vincent Belaïche
2009-10-26  2:30                   ` Stefan Monnier
2009-10-26 12:48                     ` Vincent Belaïche
2009-10-27  3:22                       ` Stefan Monnier
2009-10-25 13:57             ` Stefan Monnier
2009-10-25 18:35               ` Eli Zaretskii
2009-10-26  2:02                 ` Large files (was: Code for converting between Elisp and Calc floats) Stefan Monnier
2009-10-23 13:11     ` Code for converting between Elisp and Calc floats Richard Stallman
2009-10-23 13:26       ` David Kastrup
2009-10-24 17:34         ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200910131559.n9DFxcPD012765@godzilla.ics.uci.edu \
    --to=dann@ics.uci.edu \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.