+(defconst vc-arch-tagline-re "^\\W*arch-tag:[ \t]*\\(.*[^ \t\n]\\)")
+
+(defun vc-arch-file-source-p (file)
+ "Can return nil, `maybe' or a non-nil value.
+Only the value `maybe' can be trusted :-(."
+ ;; FIXME: Check the tag and name of parent dirs.
+ (unless (string-match "\\`[,+]" (file-name-nondirectory file))
+ (or (string-match "\\`{arch}/"
+ (file-relative-name file (vc-arch-root file)))
+ (file-exists-p
+ ;; Check the presence of an ID file.
+ (expand-file-name
+ (concat ".arch-ids/" (file-name-nondirectory file) ".id")
+ (file-name-directory file)))
+ ;; Check the presence of a tagline.
+ (with-current-buffer (find-file-noselect file)
+ (save-excursion
+ (goto-char (point-max))
+ (or (re-search-backward vc-arch-tagline-re (- (point) 1000) t)
+ (progn
+ (goto-char (point-min))
+ (re-search-forward vc-arch-tagline-re (+ (point) 1000) t)))))
+ ;; FIXME: check =tagging-method to see whether untagged files might
+ ;; be source or not.
+ (with-current-buffer
+ (find-file-noselect (expand-file-name "{arch}/=tagging-method"
+ (vc-arch-root file)))
+ (let ((untagged-source t)) ;Default is `names'.
+ (save-excursion
+ (goto-char (point-min))
+ (if (re-search-forward "^[ \t]*\\(\\(tagline\\|implicit\\|names\\)\\|explicit\\)" nil t)
+ (setq untagged-source (match-end 2)))
+ (if (re-search-forward "^[ \t]*untagged-source[ \t]+\\(\\(source\\)\\|precious\\|backup\\|junk\\|unrecognized\\)" nil t)
+ (setq untagged-source (match-end 2))))
+ (if untagged-source 'maybe))))))
+
+(defun vc-arch-file-id (file)
+ ;; Don't include the kind of ID this is because it seems to be too messy.
+ (let ((idfile (expand-file-name
+ (concat ".arch-ids/" (file-name-nondirectory file) ".id")
+ (file-name-directory file))))
+ (if (file-exists-p idfile)
+ (with-temp-buffer
+ (insert-file-contents idfile)
+ (looking-at ".*[^ \n\t]")
+ (match-string 0)))
+ (with-current-buffer (find-file-noselect file)
+ (save-excursion
+ (goto-char (point-max))
+ (if (or (re-search-backward vc-arch-tagline-re (- (point) 1000) t)
+ (progn
+ (goto-char (point-min))
+ (re-search-forward vc-arch-tagline-re (+ (point) 1000) t)))
+ (match-string 1)
+ (concat "./" (file-relative-name file (vc-arch-root file))))))))
+
+(defun vc-arch-tagging-method (file)
+ (with-current-buffer
+ (find-file-noselect
+ (expand-file-name "{arch}/=tagging-method" (vc-arch-root file)))
+ (save-excursion
+ (goto-char (point-min))
+ (if (re-search-forward
+ "^[ \t]*\\(tagline\\|implicit\\|names\\|explicit\\)" nil t)
+ (intern (match-string 1))
+ 'names))))
+