1 ;;; vc-arch.el --- VC backend for the Arch version-control system
3 ;; Copyright (C) 1995,98,99,2000,01,02,03,2004 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; The home page of the Arch version control system is at
29 ;; http://www.gnuarch.org/
31 ;; This is derived from vc-mcvs.el as follows:
32 ;; - cp vc-mcvs.el vc-arch.el and then M-% mcvs RET arch RET
34 ;; Then of course started the hacking.
36 ;; What has been partly tested:
38 ;; - C-x v = without any prefix arg.
39 ;; - C-x v v to commit a change to a single file.
43 ;; - *VC-log*'s initial content lacks the `Summary:' lines.
44 ;; - All files under the tree are considered as "under Arch's control"
45 ;; without regards to =tagging-method and such.
46 ;; - Files are always considered as `edited'.
47 ;; - C-x v l does not work.
48 ;; - C-x v i does not work.
49 ;; - C-x v ~ does not work.
50 ;; - C-x v u does not work.
51 ;; - C-x v s does not work.
52 ;; - C-x v r does not work.
53 ;; - VC-dired does not work.
58 (eval-when-compile (require 'vc
) (require 'cl
))
61 ;;; Customization options
64 (defvar vc-arch-command
65 (let ((candidates '("tla")))
66 (while (and candidates
(not (executable-find (car candidates
))))
67 (setq candidates
(cdr candidates
)))
68 (or (car candidates
) "tla")))
70 ;; Clear up the cache to force vc-call to check again and discover
71 ;; new functions when we reload this file.
72 (put 'Arch
'vc-functions nil
)
74 ;;;###autoload (defun vc-arch-registered (file)
75 ;;;###autoload (let ((dir file))
76 ;;;###autoload (while (and (stringp dir)
77 ;;;###autoload (not (equal
78 ;;;###autoload dir (setq dir (file-name-directory dir))))
80 ;;;###autoload (setq dir (if (file-directory-p
81 ;;;###autoload (expand-file-name "{arch}" dir))
82 ;;;###autoload t (directory-file-name dir))))
83 ;;;###autoload (if (eq dir t)
85 ;;;###autoload (load "vc-arch")
86 ;;;###autoload (vc-arch-registered file)))))
88 (defun vc-arch-add-tagline ()
89 "Add an `arch-tag' to the end of the current file."
91 (comment-normalize-vars)
92 (goto-char (point-max))
94 (unless (bolp) (insert "\n"))
96 (idfile (and buffer-file-name
99 (file-name-nondirectory buffer-file-name
)
101 (file-name-directory buffer-file-name
)))))
102 (insert "arch-tag: ")
103 (if (and idfile
(file-exists-p idfile
))
104 ;; If the file is unreadable, we do want to get an error here.
106 (insert-file-contents idfile
)
108 (delete-file idfile
))
110 (call-process "uuidgen" nil t
)
111 (file-error (insert (format "%s <%s> %s"
112 (current-time-string)
114 (+ (nth 2 (current-time))
116 (comment-region beg
(point))))
118 (defconst vc-arch-tagline-re
"^\\W*arch-tag:[ \t]*\\(.*[^ \t\n]\\)")
120 (defun vc-arch-file-source-p (file)
121 "Can return nil, `maybe' or a non-nil value.
122 Only the value `maybe' can be trusted :-(."
123 ;; FIXME: Check the tag and name of parent dirs.
124 (unless (string-match "\\`[,+]" (file-name-nondirectory file
))
125 (or (string-match "\\`{arch}/"
126 (file-relative-name file
(vc-arch-root file
)))
128 ;; Check the presence of an ID file.
130 (concat ".arch-ids/" (file-name-nondirectory file
) ".id")
131 (file-name-directory file
)))
132 ;; Check the presence of a tagline.
133 (with-current-buffer (find-file-noselect file
)
135 (goto-char (point-max))
136 (or (re-search-backward vc-arch-tagline-re
(- (point) 1000) t
)
138 (goto-char (point-min))
139 (re-search-forward vc-arch-tagline-re
(+ (point) 1000) t
)))))
140 ;; FIXME: check =tagging-method to see whether untagged files might
143 (find-file-noselect (expand-file-name "{arch}/=tagging-method"
144 (vc-arch-root file
)))
145 (let ((untagged-source t
)) ;Default is `names'.
147 (goto-char (point-min))
148 (if (re-search-forward "^[ \t]*\\(\\(tagline\\|implicit\\|names\\)\\|explicit\\)" nil t
)
149 (setq untagged-source
(match-end 2)))
150 (if (re-search-forward "^[ \t]*untagged-source[ \t]+\\(\\(source\\)\\|precious\\|backup\\|junk\\|unrecognized\\)" nil t
)
151 (setq untagged-source
(match-end 2))))
152 (if untagged-source
'maybe
))))))
154 (defun vc-arch-file-id (file)
155 ;; Don't include the kind of ID this is because it seems to be too messy.
156 (let ((idfile (expand-file-name
157 (concat ".arch-ids/" (file-name-nondirectory file
) ".id")
158 (file-name-directory file
))))
159 (if (file-exists-p idfile
)
161 (insert-file-contents idfile
)
162 (looking-at ".*[^ \n\t]")
164 (with-current-buffer (find-file-noselect file
)
166 (goto-char (point-max))
167 (if (or (re-search-backward vc-arch-tagline-re
(- (point) 1000) t
)
169 (goto-char (point-min))
170 (re-search-forward vc-arch-tagline-re
(+ (point) 1000) t
)))
172 (concat "./" (file-relative-name file
(vc-arch-root file
))))))))
174 (defun vc-arch-tagging-method (file)
177 (expand-file-name "{arch}/=tagging-method" (vc-arch-root file
)))
179 (goto-char (point-min))
180 (if (re-search-forward
181 "^[ \t]*\\(tagline\\|implicit\\|names\\|explicit\\)" nil t
)
182 (intern (match-string 1))
185 (defun vc-arch-root (file)
186 "Return the root directory of a Arch project, if any."
187 (or (vc-file-getprop file
'arch-root
)
192 (equal file
(setq file
(file-name-directory file
)))
194 ;; Check the =tagging-method, in case someone naively manually
195 ;; creates a {arch} directory somewhere.
196 (if (file-exists-p (expand-file-name "{arch}/=tagging-method" file
))
198 (setq file
(directory-file-name file
))))
201 (defun vc-arch-register (file &optional rev comment
)
202 (if rev
(error "Explicit initial revision not supported for Arch"))
203 (let ((tagmet (vc-arch-tagging-method file
)))
204 (if (and (memq tagmet
'(tagline implicit
)) comment-start
)
205 (with-current-buffer (find-file-noselect file
)
206 (if (buffer-modified-p)
207 (error "Save %s first" (buffer-name)))
208 (vc-arch-add-tagline)
210 (vc-arch-command nil
0 file
"add"))))
212 (defun vc-arch-registered (file)
213 ;; Don't seriously check whether it's source or not. Checking would
214 ;; require running TLA, so it's better to not do it, so it also works if
215 ;; TLA is not installed.
216 (and (vc-arch-root file
)
217 (vc-arch-file-source-p file
)))
219 (defun vc-arch-default-version (file)
220 (or (vc-file-getprop (vc-arch-root file
) 'arch-default-version
)
221 (let* ((root (vc-arch-root file
))
222 (f (expand-file-name "{arch}/++default-version" root
)))
223 (if (file-readable-p f
)
225 root
'arch-default-version
227 (insert-file-contents f
)
228 ;; Strip the terminating newline.
229 (buffer-substring (point-min) (1- (point-max)))))))))
231 (defun vc-arch-workfile-unchanged-p (file)
232 "Check if FILE is unchanged by diffing against the master version.
233 Return non-nil if FILE is unchanged."
236 (defun vc-arch-state (file)
237 ;; There's no checkout operation and merging is not done from VC
238 ;; so the only operation that's state dependent that VC supports is commit
239 ;; which is only activated if the file is `edited'.
240 (let* ((root (vc-arch-root file
))
241 (ver (vc-arch-default-version file
))
242 (pat (concat "\\`" (subst-char-in-string ?
/ ?% ver
)))
243 (dir (expand-file-name ",,inode-sigs/"
244 (expand-file-name "{arch}" root
)))
246 (dolist (f (if (file-directory-p dir
) (directory-files dir t pat
)))
247 (if (or (not sigfile
) (file-newer-than-file-p f sigfile
))
250 'edited
;We know nothing.
251 (let ((id (vc-arch-file-id file
)))
252 (setq id
(replace-regexp-in-string "[ \t]" "_" id
))
253 (with-current-buffer (find-file-noselect sigfile
)
254 (goto-char (point-min))
255 (while (and (search-forward id nil
'move
)
256 (progn (goto-char (- (match-beginning 0) 2))
257 ;; Ignore E_ entries used for foo.id files.
258 (or (not (bolp)) (looking-at "E_")))))
261 (if (equal (file-name-nondirectory sigfile
)
262 (subst-char-in-string
263 ?
/ ?%
(vc-arch-workfile-version file
)))
265 ;; Might be `added' or `up-to-date' as well.
266 ;; FIXME: Check in the patch logs to find out.
268 ;; Found the ID, let's check the inode.
269 (if (not (re-search-forward
270 "\t.*mtime=\\([0-9]+\\):size=\\([0-9]+\\)"
271 (line-end-position) t
))
272 ;; Buh? Unexpected format.
274 (let ((ats (file-attributes file
)))
275 (if (and (eq (nth 7 ats
) (string-to-number (match-string 2)))
276 (equal (format-time-string "%s" (nth 5 ats
))
281 (defun vc-arch-workfile-version (file)
282 (let* ((root (expand-file-name "{arch}" (vc-arch-root file
)))
283 (defbranch (vc-arch-default-version file
)))
284 (when (and defbranch
(string-match "\\`\\(.+@[^/\n]+\\)/\\(\\(\\(.*\\)--.*\\)--.*\\)\\'" defbranch
))
285 (let* ((archive (match-string 1 defbranch
))
286 (category (match-string 4 defbranch
))
287 (branch (match-string 3 defbranch
))
288 (version (match-string 2 defbranch
))
289 (sealed nil
) (rev-nb 0)
292 (setq logdir
(expand-file-name category root
))
293 (setq logdir
(expand-file-name branch logdir
))
294 (setq logdir
(expand-file-name version logdir
))
295 (setq logdir
(expand-file-name archive logdir
))
296 (setq logdir
(expand-file-name "patch-log" logdir
))
297 ;; Revision names go: base-0, patch-N, version-0, versionfix-N.
298 (dolist (file (directory-files logdir
))
299 (when (and (eq (aref file
0) ?v
) (not sealed
))
300 (setq sealed t rev-nb
0))
301 (if (and (string-match "-\\([0-9]+\\)\\'" file
)
302 (setq tmp
(string-to-number (match-string 1 file
)))
303 (or (not sealed
) (eq (aref file
0) ?v
))
305 (setq rev-nb tmp rev file
)))
306 (concat defbranch
"--" rev
)))))
309 (defcustom vc-arch-mode-line-rewrite
310 '(("\\`.*--\\(.*--.*\\)--\\(v?\\).*-\\([0-9]+\\)\\'" .
"\\2\\3[\\1]"))
311 "Rewrite rules to shorten Arch's revision names on the mode-line."
312 :type
'(repeat (cons regexp string
))
315 (defun vc-arch-mode-line-string (file)
316 "Return string for placement in modeline by `vc-mode-line' for FILE."
317 (let ((rev (vc-workfile-version file
)))
318 (dolist (rule vc-arch-mode-line-rewrite
)
319 (if (string-match (car rule
) rev
)
320 (setq rev
(replace-match (cdr rule
) t nil rev
))))
322 (case (vc-state file
)
323 ((up-to-date needs-patch
) ?-
)
328 (defun vc-arch-diff3-rej-p (rej)
329 (let ((attrs (file-attributes rej
)))
330 (and attrs
(< (nth 7 attrs
) 60)
332 (insert-file-contents rej
)
333 (goto-char (point-min))
334 (looking-at "Conflicts occured, diff3 conflict markers left in file\\.")))))
336 (defun vc-arch-delete-rej-if-obsolete ()
337 "For use in `after-save-hook'."
339 (let ((rej (concat buffer-file-name
".rej")))
340 (when (and buffer-file-name
(vc-arch-diff3-rej-p rej
))
341 (if (not (re-search-forward "^<<<<<<< " nil t
))
342 ;; The .rej file is obsolete.
343 (condition-case nil
(delete-file rej
) (error nil
)))))))
345 (defun vc-arch-find-file-hook ()
346 (let ((rej (concat buffer-file-name
".rej")))
347 (when (and buffer-file-name
(file-exists-p rej
))
348 (if (vc-arch-diff3-rej-p rej
)
350 (goto-char (point-min))
351 (if (not (re-search-forward "^<<<<<<< " nil t
))
352 ;; The .rej file is obsolete.
353 (condition-case nil
(delete-file rej
) (error nil
))
355 (add-hook 'after-save-hook
356 'vc-arch-delete-rej-if-obsolete nil t
)
357 (message "There are unresolved conflicts in this file")))
358 (message "There are unresolved conflicts in %s"
359 (file-name-nondirectory rej
))))))
361 (defun vc-arch-find-file-not-found-hook ()
362 ;; Do nothing. We are not sure whether the file is `source' or not,
363 ;; so we shouldn't ask the user whether she wants to check it out.
366 (defun vc-arch-checkout-model (file) 'implicit
)
368 (defun vc-arch-checkin (file rev comment
)
369 (if rev
(error "Committing to a specific revision is unsupported."))
370 (let ((summary (file-relative-name file
(vc-arch-root file
))))
371 ;; Extract a summary from the comment.
372 (when (or (string-match "\\`Summary:[ \t]*\\(.*[^ \t\n]\\)\\([ \t]*\n\\)*" comment
)
373 (string-match "\\`[ \t]*\\(.*[^ \t\n]\\)[ \t]*\\(\n?\\'\\|\n\\([ \t]*\n\\)+\\)" comment
))
374 (setq summary
(match-string 1 comment
))
375 (setq comment
(substring comment
(match-end 0))))
376 (vc-arch-command nil
0 file
"commit" "-s" summary
"-L" comment
"--"
377 (vc-switches 'Arch
'checkin
))))
379 (defun vc-arch-diff (file &optional oldvers newvers buffer
)
380 "Get a difference report using Arch between two versions of FILE."
382 (vc-up-to-date-p file
)
383 (equal newvers
(vc-workfile-version file
)))
384 ;; Newvers is the base revision and the current file is unchanged,
385 ;; so we can diff with the current file.
388 (error "Diffing specific revisions not implemented.")
389 (let* ((async (fboundp 'start-process
))
390 ;; Run the command from the root dir.
391 (default-directory (vc-arch-root file
))
394 (or buffer
"*vc-diff*")
397 ;; Arch does not support the typical flags.
398 ;; (vc-switches 'Arch 'diff)
399 (file-relative-name file
)
400 (if (equal oldvers
(vc-workfile-version file
))
403 (if async
1 status
)))) ; async diff, pessimistic assumption.
405 (defun vc-arch-delete-file (file)
406 (vc-arch-command nil
0 file
"rm"))
408 (defun vc-arch-rename-file (old new
)
409 (vc-arch-command nil
0 new
"mv" (file-relative-name old
)))
411 (defalias 'vc-arch-responsible-p
'vc-arch-root
)
413 (defun vc-arch-command (buffer okstatus file
&rest flags
)
414 "A wrapper around `vc-do-command' for use in vc-arch.el."
415 (apply 'vc-do-command buffer okstatus vc-arch-command file flags
))
417 (defun vc-arch-init-version () nil
)
421 ;;; arch-tag: a35c7c1c-5237-429d-88ef-3d718fd2e704
422 ;;; vc-arch.el ends here