From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel 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) Message-ID: <200910131559.n9DFxcPD012765@godzilla.ics.uci.edu> References: <200910082047.n98KlkAB020482@godzilla.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1255450160 13866 80.91.229.12 (13 Oct 2009 16:09:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Oct 2009 16:09:20 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 13 18:09:09 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mxjvf-0004hx-FA for ged-emacs-devel@m.gmane.org; Tue, 13 Oct 2009 18:08:51 +0200 Original-Received: from localhost ([127.0.0.1]:45306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mxjve-0004O2-TZ for ged-emacs-devel@m.gmane.org; Tue, 13 Oct 2009 12:08:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mxjob-0000iS-0N for emacs-devel@gnu.org; Tue, 13 Oct 2009 12:01:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxjoS-0000eU-Lh for emacs-devel@gnu.org; Tue, 13 Oct 2009 12:01:28 -0400 Original-Received: from [199.232.76.173] (port=53880 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxjoR-0000e4-M7 for emacs-devel@gnu.org; Tue, 13 Oct 2009 12:01:23 -0400 Original-Received: from paul-mcgann-v0.ics.uci.edu ([128.195.1.147]:39762) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MxjoQ-0001Xu-Jy for emacs-devel@gnu.org; Tue, 13 Oct 2009 12:01:23 -0400 Original-Received: from godzilla.ics.uci.edu (godzilla.ics.uci.edu [128.195.10.101]) by paul-mcgann-v0.ics.uci.edu (8.13.8/8.13.8) with ESMTP id n9DFxdbj011444; Tue, 13 Oct 2009 08:59:39 -0700 Original-Received: (from dann@localhost) by godzilla.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id n9DFxcPD012765; Tue, 13 Oct 2009 08:59:38 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Fri, 09 Oct 2009 15:18:15 -0400") Original-Lines: 145 X-ICS-MailScanner-Information: Please send mail to helpdesk@ics.uci.edu or more information X-ICS-MailScanner-ID: n9DFxdbj011444 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=0.561, required 5, autolearn=disabled, ALL_TRUSTED -1.44, GAPPY_SUBJECT 2.00) X-ICS-MailScanner-From: dann@godzilla.ics.uci.edu X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:116109 Archived-At: Stefan Monnier 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")))))