[Top][All Lists]

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

Re: allow C-x v i / C-x v v to create a repository if none is available

From: Dan Nicolaescu
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)

Stefan Monnier <address@hidden> 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)
-  (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) 
+               (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."
      ((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)
        (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")))))

reply via email to

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