unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Fix vc-working-revision return nil when default-directory is not inside repo
@ 2020-05-17 11:16 Ilya Ostapyshyn
  2020-05-17 13:01 ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: Ilya Ostapyshyn @ 2020-05-17 11:16 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

Hello emacs-devel,

"vc-git-mode-line-string" (which is called automatically) failed
occasionally with an error message (wrong-type-argument arrayp nil) when
the default-directory is outside the repository.

I hunted the error down to "vc-working-revision" function, which
returned nil under those particular circumstances. The returned value
(nil) was then passed to as an argument to "substring", causing a type
error.

If there are better ways to resolve this issue, I would be very happy to
discover them. Nonetheless I've seen such approach of "let"-ing the
default-directory variable a few times across the emacs source code
tree.

Would doing this on a lower level, for example in "vc-call-backend" be a
better approach?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: PATCH --]
[-- Type: text/x-patch, Size: 1517 bytes --]

From d651b5f38734c8972aa115ccb05b55bbd767d319 Mon Sep 17 00:00:00 2001
From: Ilya Ostapyshyn <ilya.ostapyshyn@gmail.com>
Date: Sun, 17 May 2020 13:52:41 +0300
Subject: [PATCH] * lisp/vc/vc-hooks.el: Set default-directory to be inside
 repository

---
 lisp/vc/vc-hooks.el | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index 2ca9d3e620..ebe79311fe 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -497,13 +497,14 @@ status of this file.  Otherwise, the value returned is one of:
 (defun vc-working-revision (file &optional backend)
   "Return the repository version from which FILE was checked out.
 If FILE is not registered, this function always returns nil."
-  (or (vc-file-getprop file 'vc-working-revision)
-      (progn
-        (setq backend (or backend (vc-backend file)))
-        (when backend
-          (vc-file-setprop file 'vc-working-revision
-                           (vc-call-backend
-                            backend 'working-revision file))))))
+  (let ((default-directory (file-name-directory file)))
+    (or (vc-file-getprop file 'vc-working-revision)
+        (progn
+          (setq backend (or backend (vc-backend file)))
+          (when backend
+            (vc-file-setprop file 'vc-working-revision
+                             (vc-call-backend
+                              backend 'working-revision file)))))))
 
 ;; Backward compatibility.
 (define-obsolete-function-alias
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-18  0:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-17 11:16 [PATCH] Fix vc-working-revision return nil when default-directory is not inside repo Ilya Ostapyshyn
2020-05-17 13:01 ` Dmitry Gutov
2020-05-17 13:49   ` Ilya Ostapyshyn
2020-05-17 14:17     ` Ilya Ostapyshyn
2020-05-18  0:05       ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).