From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Ilya Ostapyshyn Newsgroups: gmane.emacs.devel Subject: [PATCH] Fix vc-working-revision return nil when default-directory is not inside repo Date: Sun, 17 May 2020 14:16:01 +0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="80089"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 17 14:50:34 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jaIkT-000Kin-GN for ged-emacs-devel@m.gmane-mx.org; Sun, 17 May 2020 14:50:33 +0200 Original-Received: from localhost ([::1]:45966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaIkS-0001vJ-JF for ged-emacs-devel@m.gmane-mx.org; Sun, 17 May 2020 08:50:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaHH5-0002Mj-7u for emacs-devel@gnu.org; Sun, 17 May 2020 07:16:07 -0400 Original-Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:46081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jaHH4-00035c-DA for emacs-devel@gnu.org; Sun, 17 May 2020 07:16:06 -0400 Original-Received: by mail-lj1-x243.google.com with SMTP id f18so6756444lja.13 for ; Sun, 17 May 2020 04:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=ha2CEsdHiqwei6JFRKLDcJ/6rNqIFbB7OCU1Msdz3PE=; b=lK0fIYb0E/mpnzoq9yAm4f3gKTEtzvwV6TDy4FPHdlxIANVTOxPFTbR02v6Av5YVgW S+V42Jn8IwGlEQjWzGXyUFonM4H3rca36oNEbqWOYQOFncBQeA7bP1g9rpOf7XB/CfAj 3RverR07LjXadqOyYiYQ9h82neeiFfB+dvPToryFRNkSovAXxtQ+GC8caOGeNa+FMWHO yDKYALYlXYAEKVKXf4vtUUAC2uqluazZMv1L1ELPVzwPakeTuRDvsCRFGmvQScxPllZc GpRMGxOqQvs5b1fuOjNEW8ZDiqsOVGkFGaHwpegCACtszu6cxTme8tIkqinlswrZ8DyR 9jFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=ha2CEsdHiqwei6JFRKLDcJ/6rNqIFbB7OCU1Msdz3PE=; b=c03X6UEeAYaRTOz5pU6+BddvybYOOcN4C622Z9OthHUYEgHPQWMyTPUrQOF1WbMwNt 4zgkjbBUztyZy0X74KNjSbA/TgClO74EIrlweNPHG/3pHsQTk1tAeakp2xYrpHFqJu3b kBimygcef/MotYtXt7KOoGwZGwxX01TYjdhBGQvINJwIqHDR2lQsTDcOoQtCbnu+3llb /hbD1xPy9QaV7rMBNJJXcMvshegga8KD0B2uW0I3kE5f5NVYCxfg3SMEx7iwgGfRZYWx Kc05BmSc/iOd7SiXsBrmCfg1J7v7++KUMbxjAODCMkF/Bx+ZziMcmvyPyWM1kVXVjjHU 3LaQ== X-Gm-Message-State: AOAM530RidOwHSX7NxLA+4h9FnCc7HXORN9Guw/rmmMViK2u2OBh/Zsu 84KTMwJ9tTcS6lxzfbFazPLjrJfWy9I= X-Google-Smtp-Source: ABdhPJy5in4Qa7DzPOFVnSlARL26daVRv+EgvcDcilFzAkjQLDlzEA2E6LHB2+owBGRYjpyyCSo4Wg== X-Received: by 2002:a2e:3c10:: with SMTP id j16mr7208511lja.2.1589714163892; Sun, 17 May 2020 04:16:03 -0700 (PDT) Original-Received: from ilya-mbp.lan ([195.114.146.13]) by smtp.gmail.com with ESMTPSA id t20sm2654308lfl.17.2020.05.17.04.16.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 04:16:03 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::243; envelope-from=ilya.ostapyshyn@gmail.com; helo=mail-lj1-x243.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Mailman-Approved-At: Sun, 17 May 2020 08:49:23 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:250592 Archived-At: --=-=-= Content-Type: text/plain 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? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-vc-vc-hooks.el-Set-default-directory-to-be-insi.patch Content-Description: PATCH >From d651b5f38734c8972aa115ccb05b55bbd767d319 Mon Sep 17 00:00:00 2001 From: Ilya Ostapyshyn 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 --=-=-=--