Function: vc-deduce-fileset
vc-deduce-fileset is a byte-compiled function defined in vc.el.gz.
Signature
(vc-deduce-fileset &optional NOT-STATE-CHANGING ALLOW-UNREGISTERED STATE-MODEL-ONLY-FILES)
Documentation
Deduce a set of files and a backend to which to apply an operation.
Return a list of the form:
(BACKEND FILESET FILESET-ONLY-FILES STATE CHECKOUT-MODEL)
where the last 3 members are optional, and must be present only if STATE-MODEL-ONLY-FILES is non-nil.
NOT-STATE-CHANGING, if non-nil, means that the operation requesting the fileset doesn't intend to change the VC state, such as when printing the log or showing the diffs.
If the current buffer is in vc-dir or Dired mode, FILESET is the
list of marked files, or the file under point if no files are
marked.
Otherwise, if the current buffer is visiting a version-controlled
file or is an indirect buffer whose base buffer visits a
version-controlled file, FILESET is a single-file list containing
that file's name.
Otherwise, if ALLOW-UNREGISTERED is non-nil and the visited file
is unregistered, FILESET is a single-file list containing the
name of the visited file.
Otherwise, throw an error.
STATE-MODEL-ONLY-FILES, if non-nil, means that the caller needs
the FILESET-ONLY-FILES, STATE, and CHECKOUT-MODEL info, where
FILESET-ONLY-FILES means only files in similar VC states,
possible values of STATE are explained in vc-state, and MODEL in
vc-checkout-model. Otherwise, these 3 members may be omitted from
the returned list.
BEWARE: this function may change the current buffer.
Source Code
;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
(defun vc-deduce-fileset (&optional not-state-changing
allow-unregistered
state-model-only-files)
"Deduce a set of files and a backend to which to apply an operation.
Return a list of the form:
(BACKEND FILESET FILESET-ONLY-FILES STATE CHECKOUT-MODEL)
where the last 3 members are optional, and must be present only if
STATE-MODEL-ONLY-FILES is non-nil.
NOT-STATE-CHANGING, if non-nil, means that the operation
requesting the fileset doesn't intend to change the VC state,
such as when printing the log or showing the diffs.
If the current buffer is in `vc-dir' or Dired mode, FILESET is the
list of marked files, or the file under point if no files are
marked.
Otherwise, if the current buffer is visiting a version-controlled
file or is an indirect buffer whose base buffer visits a
version-controlled file, FILESET is a single-file list containing
that file's name.
Otherwise, if ALLOW-UNREGISTERED is non-nil and the visited file
is unregistered, FILESET is a single-file list containing the
name of the visited file.
Otherwise, throw an error.
STATE-MODEL-ONLY-FILES, if non-nil, means that the caller needs
the FILESET-ONLY-FILES, STATE, and CHECKOUT-MODEL info, where
FILESET-ONLY-FILES means only files in similar VC states,
possible values of STATE are explained in `vc-state', and MODEL in
`vc-checkout-model'. Otherwise, these 3 members may be omitted from
the returned list.
BEWARE: this function may change the current buffer."
(when (buffer-base-buffer)
(set-buffer (buffer-base-buffer)))
(let (backend)
(cond
((derived-mode-p 'vc-dir-mode)
(vc-dir-deduce-fileset state-model-only-files))
((derived-mode-p 'dired-mode)
(dired-vc-deduce-fileset state-model-only-files not-state-changing))
((and (derived-mode-p 'diff-mode) (not buffer-file-name))
(diff-vc-deduce-fileset))
((setq backend (vc-backend buffer-file-name))
(if state-model-only-files
(list backend (list buffer-file-name)
(list buffer-file-name)
(vc-state buffer-file-name)
(vc-checkout-model backend buffer-file-name))
(list backend (list buffer-file-name))))
((derived-mode-p 'log-view-mode)
;; 'log-view-mode' stashes the backend and the fileset in the
;; two special variables, so we use them to avoid any possible
;; mistakes from a decision made here ad-hoc.
(list log-view-vc-backend log-view-vc-fileset))
((and (buffer-live-p vc-parent-buffer)
;; FIXME: Why this test? --Stef
(or (buffer-file-name vc-parent-buffer)
(with-current-buffer vc-parent-buffer
(or (derived-mode-p 'vc-dir-mode)
(derived-mode-p 'dired-mode)
(derived-mode-p 'diff-mode)))))
(progn ;FIXME: Why not `with-current-buffer'? --Stef.
(set-buffer vc-parent-buffer)
(vc-deduce-fileset not-state-changing allow-unregistered state-model-only-files)))
((and (not buffer-file-name)
(setq backend (vc-responsible-backend default-directory)))
(list backend nil))
((and allow-unregistered (not (vc-registered buffer-file-name)))
(if state-model-only-files
(list (vc-backend-for-registration (buffer-file-name))
(list buffer-file-name)
(list buffer-file-name)
(when state-model-only-files 'unregistered)
nil)
(list (vc-backend-for-registration (buffer-file-name))
(list buffer-file-name))))
(t (error "File is not under version control")))))