comparison lisp/vc.el @ 94488:d3100c0eddb7

(vc-deduce-fileset): Add new parameter. (vc-dir-marked-only-files): New function. (vc-next-action): Don't ignore directories, look at the files inside them. (vc-dir-mode): Document how the mark/unmark commands work.
author Dan Nicolaescu <dann@ics.uci.edu>
date Wed, 30 Apr 2008 05:40:25 +0000
parents ad6c174910db
children 027a58c5f305
comparison
equal deleted inserted replaced
94487:432e68e359fa 94488:d3100c0eddb7
611 ;; 611 ;;
612 ;; - vc-diff should be able to show the diff for all files in a 612 ;; - vc-diff should be able to show the diff for all files in a
613 ;; changeset, especially for VC systems that have per repository 613 ;; changeset, especially for VC systems that have per repository
614 ;; version numbers. log-view should take advantage of this. 614 ;; version numbers. log-view should take advantage of this.
615 ;; 615 ;;
616 ;; - a way to do repository wide log (instead of just per
617 ;; file/fileset) is needed.
618 ;;
619 ;; - the *VC-log* buffer needs font-locking. 616 ;; - the *VC-log* buffer needs font-locking.
620 ;; 617 ;;
621 ;; - make it easier to write logs. Maybe C-x 4 a should add to the log 618 ;; - make it easier to write logs. Maybe C-x 4 a should add to the log
622 ;; buffer, if one is present, instead of adding to the ChangeLog. 619 ;; buffer, if one is present, instead of adding to the ChangeLog.
623 ;; 620 ;;
624 ;; - make vc-state for all backends return 'unregistered instead of 621 ;; - make vc-state for all backends return 'unregistered instead of
625 ;; nil for unregistered files, then update vc-next-action. 622 ;; nil for unregistered files, then update vc-next-action.
623 ;;
624 ;; - vc-default-registered should return 'unregistered not nil for
625 ;; unregistered files.
626 ;; 626 ;;
627 ;; - vc-register should register a fileset at a time. The backends 627 ;; - vc-register should register a fileset at a time. The backends
628 ;; already support this, only the front-end needs to be changed to 628 ;; already support this, only the front-end needs to be changed to
629 ;; handle multiple files at a time. 629 ;; handle multiple files at a time.
630 ;; 630 ;;
631 ;; - add a mechanism for ignoring files. 631 ;; - add a mechanism for ignoring files.
632 ;; 632 ;;
633 ;; - vc-next-action should do something about 'missing files. Maybe 633 ;; - vc-next-action should do something about 'missing files. Maybe
634 ;; just warn, or offer to checkout. 634 ;; just warn, or offer to checkout.
635 ;; 635 ;;
636 ;; - display the directory names in vc-dir, similar to what PCL-CVS 636 ;; - When vc-next-action calls vc-checkin it could pre-fill the
637 ;; does. 637 ;; *VC-log* buffer with some obvious items: the list of files that
638 ;; were added, the list of files that were removed. If the diff is
639 ;; available, maybe it could even call something like
640 ;; `diff-add-change-log-entries-other-window' to create a detailed
641 ;; skeleton for the log...
642 ;;
643 ;; - Set `vc-dir-insert-directories' to t and check what operations
644 ;; and backends do not support directory arguments and fix them.
645 ;;
646 ;; - a way to do repository wide log (instead of just per
647 ;; file/fileset) is needed. Doing it per directory might be enough...
638 ;; 648 ;;
639 ;; - most vc-dir backends need more work. They might need to 649 ;; - most vc-dir backends need more work. They might need to
640 ;; provide custom headers, use the `extra' field and deal with all 650 ;; provide custom headers, use the `extra' field and deal with all
641 ;; possible VC states. 651 ;; possible VC states.
642 ;; 652 ;;
646 ;; 656 ;;
647 ;; - vc-dir needs more key bindings for VC actions. 657 ;; - vc-dir needs more key bindings for VC actions.
648 ;; 658 ;;
649 ;; - vc-dir toolbar needs more icons. 659 ;; - vc-dir toolbar needs more icons.
650 ;; 660 ;;
651 ;; - implement `vc-dir-parent-marked-p' and `vc-dir-children-marked-p'. 661 ;; - vc-dir-next-line should not print an "end of buffer" message when
652 ;; 662 ;; invoked with the cursor on the last file.
653 ;; - test operations on directories in vc-dir.
654 ;; 663 ;;
655 ;; - vc-diff, vc-annotate, etc. need to deal better with unregistered 664 ;; - vc-diff, vc-annotate, etc. need to deal better with unregistered
656 ;; files. Now that unregistered and ignored files are shown in 665 ;; files. Now that unregistered and ignored files are shown in
657 ;; vc-dired/vc-dir, it is possible that these commands are called 666 ;; vc-dired/vc-dir, it is possible that these commands are called
658 ;; for unregistered/ignored files. 667 ;; for unregistered/ignored files.
659 ;; 668 ;;
660 ;; - do not default to RCS anymore when the current directory is not 669 ;; - do not default to RCS anymore when the current directory is not
661 ;; controlled by any VCS and the user does C-x v v 670 ;; controlled by any VCS and the user does C-x v v
662 ;; 671 ;;
672 ;; - vc-cvs-delete-file should not do a "cvs commit" immediately after
673 ;; removing the file.
674 ;;
675 ;; - vc-create-snapshot and vc-retrieve-snapshot should update the
676 ;; buffers that might be visiting the affected files.
663 677
664 ;;; Code: 678 ;;; Code:
665 679
666 (require 'vc-hooks) 680 (require 'vc-hooks)
667 (require 'tool-bar) 681 (require 'tool-bar)
1424 (dolist (node file-or-dir-list) 1438 (dolist (node file-or-dir-list)
1425 (vc-file-tree-walk 1439 (vc-file-tree-walk
1426 node (lambda (f) (when (vc-backend f) (push f flattened))))) 1440 node (lambda (f) (when (vc-backend f) (push f flattened)))))
1427 (nreverse flattened))) 1441 (nreverse flattened)))
1428 1442
1429 (defun vc-deduce-fileset (&optional allow-directory-wildcard allow-unregistered) 1443 (defun vc-deduce-fileset (&optional allow-directory-wildcard allow-unregistered
1444 include-files-not-directories)
1430 "Deduce a set of files and a backend to which to apply an operation. 1445 "Deduce a set of files and a backend to which to apply an operation.
1431 1446
1432 Return (BACKEND . FILESET). 1447 Return (BACKEND . FILESET).
1433 If we're in VC-dired mode, the fileset is the list of marked files. 1448 If we're in VC-dired mode, the fileset is the list of marked files.
1434 Otherwise, if we're looking at a buffer visiting a version-controlled file, 1449 Otherwise, if we're looking at a buffer visiting a version-controlled file,
1435 the fileset is a singleton containing this file. 1450 the fileset is a singleton containing this file.
1436 If neither of these things is true, but ALLOW-DIRECTORY-WILDCARD is on 1451 If neither of these things is true, but ALLOW-DIRECTORY-WILDCARD is on
1437 and we're in a dired buffer, select the current directory. 1452 and we're in a dired buffer, select the current directory.
1438 If none of these conditions is met, but ALLOW_UNREGISTERED is in and the 1453 If none of these conditions is met, but ALLOW_UNREGISTERED is on and the
1439 visited file is not registered, return a singletin fileset containing it. 1454 visited file is not registered, return a singleton fileset containing it.
1455 If INCLUDE-FILES-NOT-DIRECTORIES then if directories are marked,
1456 return the list of files VC files in those directories instead of
1457 the directories themselves.
1440 Otherwise, throw an error." 1458 Otherwise, throw an error."
1441 (let (backend) 1459 (let (backend)
1442 (cond 1460 (cond
1443 (vc-dired-mode 1461 (vc-dired-mode
1444 (let ((marked (dired-map-over-marks (dired-get-filename) nil))) 1462 (let ((marked (dired-map-over-marks (dired-get-filename) nil)))
1452 (cons backend marked))) 1470 (cons backend marked)))
1453 ((eq major-mode 'vc-dir-mode) 1471 ((eq major-mode 'vc-dir-mode)
1454 ;; FIXME: Maybe the backend should be stored in a buffer-local 1472 ;; FIXME: Maybe the backend should be stored in a buffer-local
1455 ;; variable? 1473 ;; variable?
1456 (cons (vc-responsible-backend default-directory) 1474 (cons (vc-responsible-backend default-directory)
1457 (or (vc-dir-marked-files) 1475 (or
1458 (list (vc-dir-current-file))))) 1476 (if include-files-not-directories
1477 (vc-dir-marked-only-files)
1478 (vc-dir-marked-files))
1479 (list (vc-dir-current-file)))))
1459 ((setq backend (vc-backend buffer-file-name)) 1480 ((setq backend (vc-backend buffer-file-name))
1460 (cons backend (list buffer-file-name))) 1481 (cons backend (list buffer-file-name)))
1461 ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer) 1482 ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer)
1462 (with-current-buffer vc-parent-buffer 1483 (with-current-buffer vc-parent-buffer
1463 (or vc-dired-mode (eq major-mode 'vc-dir-mode))))) 1484 (or vc-dired-mode (eq major-mode 'vc-dir-mode)))))
1586 with the logmessage as change commentary. A writable file is retained. 1607 with the logmessage as change commentary. A writable file is retained.
1587 If the repository file is changed, you are asked if you want to 1608 If the repository file is changed, you are asked if you want to
1588 merge in the changes into your working copy." 1609 merge in the changes into your working copy."
1589 (interactive "P") 1610 (interactive "P")
1590 (let* ((vc-fileset (vc-deduce-fileset nil t)) 1611 (let* ((vc-fileset (vc-deduce-fileset nil t))
1612 (vc-fileset-only-files (vc-deduce-fileset nil t t))
1613 (only-files (cdr vc-fileset-only-files))
1591 (backend (car vc-fileset)) 1614 (backend (car vc-fileset))
1592 (files (cdr vc-fileset)) 1615 (files (cdr vc-fileset))
1593 state 1616 (state (vc-state (car only-files)))
1594 (model (vc-checkout-model backend files)) 1617 (model (vc-checkout-model backend files))
1595 revision) 1618 revision)
1596 ;; Check if there's at least one file present, and get `state' and
1597 ;; `model' from it.
1598 ;;FIXME: do something about the case when only directories are
1599 ;; present, or `files' is nil.
1600 (dolist (file files)
1601 (unless (file-directory-p file)
1602 (setq state (vc-state file))
1603 (return)))
1604 1619
1605 ;; Verify that the fileset is homogeneous 1620 ;; Verify that the fileset is homogeneous
1606 (dolist (file (cdr files)) 1621 (dolist (file (cdr only-files))
1607 ;; Ignore directories, they are compatible with anything. 1622 ;; Ignore directories, they are compatible with anything.
1608 (unless (file-directory-p file) 1623 (unless (file-directory-p file)
1609 (unless (vc-compatible-state (vc-state file) state) 1624 (unless (vc-compatible-state (vc-state file) state)
1610 (error "Fileset is in a mixed-up state")) 1625 (error "Fileset is in a mixed-up state %s %s" state (vc-state file)))
1611 (unless (eq (vc-checkout-model backend file) model) 1626 (unless (eq (vc-checkout-model backend file) model)
1612 (error "Fileset has mixed checkout models")))) 1627 (error "Fileset has mixed checkout models"))))
1613 ;; Check for buffers in the fileset not matching the on-disk contents. 1628 ;; Check for buffers in the fileset not matching the on-disk contents.
1614 (dolist (file files) 1629 (dolist (file files)
1615 (let ((visited (get-file-buffer file))) 1630 (let ((visited (get-file-buffer file)))
3034 3049
3035 (defvar vc-dir-process-buffer nil 3050 (defvar vc-dir-process-buffer nil
3036 "The buffer used for the asynchronous call that computes the VC status.") 3051 "The buffer used for the asynchronous call that computes the VC status.")
3037 3052
3038 (defun vc-dir-mode () 3053 (defun vc-dir-mode ()
3039 "Major mode for VC status. 3054 "Major mode for showing the VC status for a directory.
3055 Marking/Unmarking key bindings and actions:
3056 m - marks a file/directory or ff the region is active, mark all the files
3057 in region.
3058 Restrictions: - a file cannot be marked if any parent directory is marked
3059 - a directory cannot be marked if any child file or
3060 directory is marked
3061 u - marks a file/directory or if the region is active, unmark all the files
3062 in region.
3063 M - if the cursor is on a file: mark all the files with the same VC state as
3064 the current file
3065 - if the cursor is on a directory: mark all child files
3066 - with a prefix argument: mark all files
3067 U - if the cursor is on a file: unmark all the files with the same VC state
3068 as the current file
3069 - if the cursor is on a directory: unmark all child files
3070 - with a prefix argument: unmark all files
3071
3072
3040 \\{vc-dir-mode-map}" 3073 \\{vc-dir-mode-map}"
3041 (setq mode-name "VC Status") 3074 (setq mode-name "VC Status")
3042 (setq major-mode 'vc-dir-mode) 3075 (setq major-mode 'vc-dir-mode)
3043 (setq buffer-read-only t) 3076 (setq buffer-read-only t)
3044 (use-local-map vc-dir-mode-map) 3077 (use-local-map vc-dir-mode-map)
3542 (unless node 3575 (unless node
3543 (error "No file available.")) 3576 (error "No file available."))
3544 (expand-file-name (vc-dir-fileinfo->name (ewoc-data node))))) 3577 (expand-file-name (vc-dir-fileinfo->name (ewoc-data node)))))
3545 3578
3546 (defun vc-dir-marked-files () 3579 (defun vc-dir-marked-files ()
3547 "Return the list of marked files" 3580 "Return the list of marked files."
3548 (mapcar 3581 (mapcar
3549 (lambda (elem) (expand-file-name (vc-dir-fileinfo->name elem))) 3582 (lambda (elem) (expand-file-name (vc-dir-fileinfo->name elem)))
3550 (ewoc-collect vc-ewoc 'vc-dir-fileinfo->marked))) 3583 (ewoc-collect vc-ewoc 'vc-dir-fileinfo->marked)))
3584
3585 (defun vc-dir-marked-only-files ()
3586 "Return the list of marked files, for marked directories, return child files."
3587
3588 (let ((crt (ewoc-nth vc-ewoc 0))
3589 result)
3590 (while crt
3591 (let ((crt-data (ewoc-data crt)))
3592 (if (vc-dir-fileinfo->marked crt-data)
3593 (if (vc-dir-fileinfo->directory crt-data)
3594 (let* ((dir (vc-dir-fileinfo->directory crt-data))
3595 (dirlen (length dir))
3596 data)
3597 (while
3598 (and (setq crt (ewoc-next vc-ewoc crt))
3599 (string-equal
3600 (substring
3601 (progn
3602 (setq data (ewoc-data crt))
3603 (let ((crtdir (vc-dir-fileinfo->directory data)))
3604 (if crtdir
3605 crtdir
3606 (file-name-directory
3607 (expand-file-name
3608 (vc-dir-fileinfo->name data))))))
3609 0 dirlen)
3610 dir))
3611 (unless (vc-dir-fileinfo->directory data)
3612 (push (vc-dir-fileinfo->name data) result))))
3613 (push (expand-file-name (vc-dir-fileinfo->name crt-data)) result)
3614 (setq crt (ewoc-next vc-ewoc crt)))
3615 (setq crt (ewoc-next vc-ewoc crt)))))
3616 result))
3551 3617
3552 (defun vc-dir-hide-up-to-date () 3618 (defun vc-dir-hide-up-to-date ()
3553 "Hide up-to-date items from display." 3619 "Hide up-to-date items from display."
3554 (interactive) 3620 (interactive)
3555 (ewoc-filter 3621 (ewoc-filter