Function: majutsu-find-file-noselect

majutsu-find-file-noselect is a natively compiled function defined in majutsu-file.el.

Signature

(majutsu-find-file-noselect REV FILE &optional REVERT)

Documentation

Read FILE from REV into a buffer and return the buffer.

REV is a revset, or nil to visit the file directly from the filesystem. FILE may be absolute, or relative to the repository root. Non-nil REVERT means to revert the buffer. If ask-revert, then only after asking. A non-nil value for REVERT is ignored if REV is nil.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-file.el
(defun majutsu-find-file-noselect (rev file &optional revert)
  "Read FILE from REV into a buffer and return the buffer.
REV is a revset, or nil to visit the file directly from the filesystem.
FILE may be absolute, or relative to the repository root.
Non-nil REVERT means to revert the buffer.  If `ask-revert', then
only after asking.  A non-nil value for REVERT is ignored if REV is nil."
  (let* ((root (majutsu-file--root))
         (file-abs (if (file-name-absolute-p file)
                       file
                     (expand-file-name file root)))
         (file-rel (file-relative-name file-abs root))
         (defdir (file-name-directory file-abs)))
    (when (and rev (not (file-in-directory-p file-abs root)))
      (user-error "File is outside repository: %s" file))
    (if (null rev)
        ;; Visit filesystem file directly
        (progn
          (unless (file-exists-p file-abs)
            (user-error "File no longer exists: %s" file-abs))
          (find-file-noselect file-abs))
      ;; Visit blob from revision
      (let* ((rev-info (or (majutsu-file--resolve-single-rev-info rev)
                           (user-error "Revset does not resolve to a single revision")))
             (resolved (plist-get rev-info :change-id))
             (commit-id (plist-get rev-info :commit-id))
             (short-rev (majutsu-file--short-id resolved))
             (buf-name (majutsu-file--buffer-name short-rev file-rel))
             (buffer (get-buffer-create buf-name)))
        (with-current-buffer buffer
          (when (or revert
                    (eq revert 'ask-revert)
                    (not majutsu-buffer-blob-path))
            (when (or (not (eq revert 'ask-revert))
                      (y-or-n-p (format "%s already exists; revert it? "
                                        (buffer-name))))
              (setq majutsu-buffer-blob-root root)
              (setq majutsu-buffer-blob-revset rev)
              (setq majutsu-buffer-blob-revision resolved)
              (setq majutsu-buffer-blob-change-id resolved)
              (setq majutsu-buffer-blob-commit-id commit-id)
              (setq majutsu-buffer-blob-path file-rel)
              (setq default-directory (if (file-exists-p defdir) defdir root))
              (setq-local revert-buffer-function #'majutsu-file-revert-buffer)
              (majutsu-file-revert-buffer nil t)
              (run-hooks 'majutsu-find-file-hook))))
        buffer))))