Simplify and fix ‘vc-p4-is-in-client’

Quoting the string with Windows paths in it would double-quote the directory
separators. It also seems easier to use ‘string-prefix-p’ than an anchored
regular expression.

‘alist-get’ is a function that was introduced in Emacs 25 that is easier to use
than ‘assoc’ + ‘cdr’.
This commit is contained in:
Tom Willemse 2020-05-27 17:51:25 -07:00
parent d181ea1e1f
commit d32dd5f376

View file

@ -892,17 +892,9 @@ If DIRNAME is not specified, uses `default-directory'."
"Return true if FILE is inside the p4 client hierarchy." "Return true if FILE is inside the p4 client hierarchy."
(let* ((default-directory (file-name-directory file)) (let* ((default-directory (file-name-directory file))
(info (p4-lowlevel-info)) (info (p4-lowlevel-info))
(root-pair (assoc "Client root" info)) (root (alist-get "Client root" info))
(root (and root-pair (cdr root-pair))) (cwd (alist-get "Current directory" info)))
(quoted-root (and root (concat "^" (regexp-quote root)))) (string-prefix-p root cwd)))
(cwd-pair (assoc "Current directory" info))
(cwd (and cwd-pair (cdr cwd-pair))))
(if (or (not quoted-root) (not (string-match quoted-root cwd)))
nil
(setq cwd (replace-match "" nil nil cwd))
(if (or (string= cwd "") (string-match "^/" cwd))
t
nil))))
(defun vc-p4-has-unresolved-conflicts-p (file) (defun vc-p4-has-unresolved-conflicts-p (file)
"Search through FILE's buffer for unresolved P4 conflicts. "Search through FILE's buffer for unresolved P4 conflicts.