From d32dd5f3760ae3ba1a24d2c6f05a9667982a96ef Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 27 May 2020 17:51:25 -0700 Subject: [PATCH] =?UTF-8?q?Simplify=20and=20fix=20=E2=80=98vc-p4-is-in-cli?= =?UTF-8?q?ent=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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’. --- vc-p4.el | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/vc-p4.el b/vc-p4.el index 0c6acee..5215b49 100644 --- a/vc-p4.el +++ b/vc-p4.el @@ -892,17 +892,9 @@ If DIRNAME is not specified, uses `default-directory'." "Return true if FILE is inside the p4 client hierarchy." (let* ((default-directory (file-name-directory file)) (info (p4-lowlevel-info)) - (root-pair (assoc "Client root" info)) - (root (and root-pair (cdr root-pair))) - (quoted-root (and root (concat "^" (regexp-quote root)))) - (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)))) + (root (alist-get "Client root" info)) + (cwd (alist-get "Current directory" info))) + (string-prefix-p root cwd))) (defun vc-p4-has-unresolved-conflicts-p (file) "Search through FILE's buffer for unresolved P4 conflicts.