Function: vc-jj-state
vc-jj-state is a natively compiled function defined in vc-jj.el.
Signature
(vc-jj-state FILE)
Documentation
JJ implementation of vc-state for FILE.
There are several file states recognized by vc (see the docstring of
vc-state for the full list). Several of these are relevant to
jujutsu. They are:
- Added (new file)
- Removed (deleted file)
- Edited (modified file)
- Up-to-date (unmodified file)
- Conflict (merge conflict)
- Ignored (ignored by repository)
Other VCS backends would also recognize the "unregistered" state, but there is no such state in jj since jj automatically registers new files.
Source Code
;; Defined in /nix/store/j1ql1qsv99iszr5pqf5fk9yfcl5pq4nv-emacs-packages-deps/share/emacs/site-lisp/elpa/vc-jj-0.5/vc-jj.el
;;;; state
(defun vc-jj-state (file)
"JJ implementation of `vc-state' for FILE.
There are several file states recognized by vc (see the docstring of
`vc-state' for the full list). Several of these are relevant to
jujutsu. They are:
- Added (new file)
- Removed (deleted file)
- Edited (modified file)
- Up-to-date (unmodified file)
- Conflict (merge conflict)
- Ignored (ignored by repository)
Other VCS backends would also recognize the \"unregistered\" state, but
there is no such state in jj since jj automatically registers new files."
;; We can deduce all of the vc states listed above with two
;; commands:
;;
;; - "jj diff --summary FILE" gets us the "added" state (when output
;; starts with "A "), the "removed" state (when output starts with
;; "D ") and "edited" state (when output starts with "M "). No
;; output is also possible (this could mean the "conflict",
;; "ignored" or "unchanged" state), so we deduce these with the
;; next command:
;;
;; - "jj file list -T 'conflict' FILE" prints "true" when the file
;; is in "conflict" state, prints an empty string when the file is
;; in "ignored" state, and "false" for any other state -- but most
;; of these are already covered by the previous command, so we
;; deduce "up-to-date".
(let* ((default-directory (vc-jj-root file))
(file (vc-jj--filename-to-fileset file))
(changed (vc-jj--command-parseable "diff" "--summary" "--" file)))
(cond
((string-prefix-p "A " changed) 'added)
((string-prefix-p "D " changed) 'removed)
((string-prefix-p "M " changed) 'edited)
(t (let ((conflicted-ignored
(vc-jj--command-parseable "file" "list" "-T" "conflict" "--"
file)))
(cond
((string= conflicted-ignored "true") 'conflict)
((string-empty-p conflicted-ignored) 'ignored)
;; If the file hasn't matched anything yet, this leaves
;; only one possible state: up-to-date
((string= conflicted-ignored "false") 'up-to-date)
(t
(warn "VC state of %s is not recognized, assuming up-to-date" file)
'up-to-date)))))))