Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

(vc-responsible-backend): When a directory is passed for

for registration create a VC repository if no backend is
responsible for the directory argument.
(vc-deduce-fileset): Tell vc-responsible-backend to register.
  • Loading branch information...
commit 4f9151b97c882ecdda88e7fc145c3530abd3ef64 1 parent 97a3a8b
Dan Nicolaescu authored
Showing with 58 additions and 14 deletions.
  1. +5 −0 etc/NEWS
  2. +6 −1 lisp/ChangeLog
  3. +47 −13 lisp/vc.el
View
5 etc/NEWS
@@ -185,6 +185,11 @@ new connection methods "dav", "davs", "obex" and "synce".
** VC and related modes
+*** When using C-x v v or C-x v i on a unregistered file that is in a
+directory not controlled by any VCS, ask the user what VC backend to
+use to create a repository, create a new repository and register the
+file.
+
*** FIXME: add info about the new VC functions: vc-root-diff and
vc-root-print-log once they stabilize.
View
7 lisp/ChangeLog
@@ -1,4 +1,9 @@
-2009-10-13 Dan Nicolaescu <dann@ics.uci.edu>
+2009-10-14 Dan Nicolaescu <dann@ics.uci.edu>
+
+ * vc.el (vc-responsible-backend): When a directory is passed for
+ for registration create a VC repository if no backend is
+ responsible for the directory argument.
+ (vc-deduce-fileset): Tell vc-responsible-backend to register.
* vc.el: Move comments about RCS and SCCS ...
* vc-rcs.el:
View
60 lisp/vc.el
@@ -551,9 +551,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.
;;
@@ -805,11 +802,14 @@ The optional argument REGISTER means that a backend suitable for
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
@@ -829,13 +829,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.
@@ -896,13 +930,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")))))
Please sign in to comment.
Something went wrong with that request. Please try again.