pijul_org / pijul
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(eval-when-compile
(require 'cl-lib)
(require 'vc))
(defgroup vc-pijul nil
"VC Pijul backend."
:group 'vc)
(defcustom vc-pijul-program "pijul"
"Name of the Git executable (excluding any arguments)."
:type 'string)
(defcustom vc-pijul-commits-coding-system 'utf-8
"Default coding system for sending commit log messages to Git.
Should be consistent with the Git config value i18n.commitEncoding,
and should also be consistent with `locale-coding-system'."
:type '(coding-system :tag "Coding system to encode Git commit logs"))
(defcustom vc-pijul-log-output-coding-system 'utf-8
"Default coding system for receiving log output from Git.
Should be consistent with the Git config value i18n.logOutputEncoding."
:type '(coding-system :tag "Coding system to decode Git log output"))
;; Clear up the cache to force vc-call to check again and discover new
;; functions when we reload this file.
(put 'Pijul 'vc-functions nil)
(defun vc-pijul-root (file)
(or (vc-file-getprop file 'pijul-root)
(vc-file-setprop file 'pijul-root (vc-find-root file ".pijul"))))
(defun vc-pijul-command (buffer okstatus file-or-list &rest flags)
"A wrapper around `vc-do-command' for use in vc-git.el.
The difference to vc-do-command is that this function always invokes
`vc-pijul-program'."
(let ((coding-system-for-read (or coding-system-for-read vc-pijul-log-output-coding-system))
(coding-system-for-write (or coding-system-for-write vc-pijul-commits-coding-system)))
(apply 'vc-do-command (or buffer "*vc*") okstatus vc-pijul-program file-or-list flags)
))
(defun vc-pijul-create-repo ()
"Create a new Pijul repository."
(vc-pijul-command nil 0 nil "init"))
(defun vc-pijul--call (buffer command &rest args)
(let ((coding-system-for-read (or coding-system-for-read vc-pijul-log-output-coding-system))
(coding-system-for-write (or coding-system-for-write vc-pijul-commits-coding-system)))
(apply 'process-file vc-pijul-program nil buffer nil command args)))
(defun vc-pijul--out-ok (command &rest args)
(zerop (apply 'vc-pijul--call '(t nil) command args)))
(defun vc-pijul-registered (file)
"Check whether FILE is registered with pijul."
(let ((dir (vc-pijul-root file)))
(when dir
(with-temp-buffer
(let ((name (file-relative-name file dir)))
(ignore-errors
(cd dir)
(vc-pijul--out-ok "ls" name)))))))
(defun vc-pijul-state (file) 'unregistered)
(defun vc-pijul-checkout-model (_files) 'implicit)
(defun vc-pijul-working-revision (file)
"Pijul-specific version of `vc-working-revision'."
(with-temp-buffer
(let ((hash (vc-pijul-command (current-buffer) 0 nil "log" "--hash-only" "--last" "1" "--path" file)))
(ignore-errors
(goto-char (point-max))
(forward-line -1)
(buffer-substring-no-properties (line-beginning-position) (line-end-position) ))
)))
(provide 'vc-pijul)