+2008-02-19 Thien-Thi Nguyen <ttn@gnuvola.org>
+
+ * vc-hooks.el (vc-find-root): Take optional arg INVERT.
+ If non-nil, reverse the sense of the check.
+ * vc-rcs.el (vc-rcs-root): New func.
+ * vc-cvs.el (vc-cvs-root): New func.
+ * vc-svn.el (vc-svn-root): New func.
+
2008-02-18 Kenichi Handa <handa@ni.aist.go.jp>
* language/japan-util.el (setup-japanese-environment-internal):
(set-buffer-modified-p nil)
t))
-(defun vc-find-root (file witness)
+(defun vc-find-root (file witness &optional invert)
"Find the root of a checked out project.
The function walks up the directory tree from FILE looking for WITNESS.
-If WITNESS if not found, return nil, otherwise return the root."
+If WITNESS if not found, return nil, otherwise return the root.
+Optional arg INVERT non-nil reverses the sense of the check;
+the root is the last directory for which WITNESS *is* found."
;; Represent /home/luser/foo as ~/foo so that we don't try to look for
;; witnesses in /home or in /.
(while (not (file-directory-p file))
(setq file (file-name-directory (directory-file-name file))))
(setq file (abbreviate-file-name file))
(let ((root nil)
- (user (nth 2 (file-attributes file))))
+ (prev-file file)
+ (user (nth 2 (file-attributes file)))
+ try)
(while (not (or root
(null file)
;; As a heuristic, we stop looking up the hierarchy of
;; files inside a project belong to the same user.
(not (equal user (nth 2 (file-attributes file))))
(string-match vc-ignore-dir-regexp file)))
- (if (file-exists-p (expand-file-name witness file))
- (setq root file)
- (if (equal file
- (setq file (file-name-directory (directory-file-name file))))
- (setq file nil))))
+ (setq try (file-exists-p (expand-file-name witness file)))
+ (cond ((and invert (not try)) (setq root prev-file))
+ ((and (not invert) try) (setq root file))
+ ((equal file (setq prev-file file
+ file (file-name-directory
+ (directory-file-name file))))
+ (setq file nil))))
+ ;; Handle the case where ~/WITNESS exists and the original FILE is "~".
+ ;; (This occurs, for example, when placing dotfiles under RCS.)
+ (when (and (not root) invert prev-file)
+ (setq root prev-file))
root))
;; Access functions to file properties