From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jonathan Ganc Newsgroups: gmane.emacs.bugs Subject: bug#26066: 26.0.50; vc-git-status gives wrong result Date: Mon, 10 Apr 2017 23:52:24 -0400 Message-ID: <1a23269d-1ead-1771-1afd-e2c9c5840cb4@gmail.com> References: <9bf82bf1-fefa-ab84-bac1-cf748ae5ccfb@gmail.com> <87efxy59wx.fsf@users.sourceforge.net> <0d87686b-c7d2-deab-ebe4-ab1c8aa4faca@yandex.ru> <29d4a5ae-0ca0-3a86-6b9a-ab616803f39e@gmail.com> <4741bddf-9765-0d94-d0cd-b94e3e4914e1@yandex.ru> <8530cd03-0158-f198-9b14-ade983e1c7f4@gmail.com> <022c0e0a-e039-24ef-66ff-82bcedbacd93@yandex.ru> <505388da-e642-8c98-35c0-261d09ff13e1@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1D6459AC6D25AF909738FB0B" X-Trace: blaine.gmane.org 1491882797 25038 195.159.176.226 (11 Apr 2017 03:53:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Apr 2017 03:53:17 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 To: Dmitry Gutov , npostavs@users.sourceforge.net, 26066@debbugs.gnu.org, Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 11 05:53:06 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxmrZ-0006L4-KN for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Apr 2017 05:53:05 +0200 Original-Received: from localhost ([::1]:37137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxmrf-0004Be-Ck for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Apr 2017 23:53:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxmrZ-0004BW-NF for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 23:53:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxmrW-0006O1-Fq for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 23:53:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43627) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxmrW-0006Nj-BK for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 23:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cxmrW-0006Ri-1g for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 23:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jonathan Ganc Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Apr 2017 03:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26066 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26066-submit@debbugs.gnu.org id=B26066.149188275324738 (code B ref 26066); Tue, 11 Apr 2017 03:53:01 +0000 Original-Received: (at 26066) by debbugs.gnu.org; 11 Apr 2017 03:52:33 +0000 Original-Received: from localhost ([127.0.0.1]:41826 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxmr2-0006Qw-Mm for submit@debbugs.gnu.org; Mon, 10 Apr 2017 23:52:32 -0400 Original-Received: from mail-qt0-f194.google.com ([209.85.216.194]:34574) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxmr1-0006Qk-Ih for 26066@debbugs.gnu.org; Mon, 10 Apr 2017 23:52:31 -0400 Original-Received: by mail-qt0-f194.google.com with SMTP id r49so8864826qta.1 for <26066@debbugs.gnu.org>; Mon, 10 Apr 2017 20:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=AwE0AV+Yw6DG9ShIPjrC+51aeURUDYcHGi1kv7eWYy8=; b=FQyFc3L0cabW6BRmWN5caBsIFOS7q/wfKGf1suTMqfhHNmuwt4qDe5NJH8GwzPk5rf zWQYE+2Vin03Kw4gnxLCWl6AK6bS/q4FmY5/06bRCasNueMrCsoGOPcDXzI2GuYBwt0P rgpA1CWIxA6RllRpA/tieFQS4ExsOjoBnHTkSyHmmbNJetXq7DTF4iObuxJWfA1chsJL mq4BcQ6NLkEwoG7/vud7YMDgMeDecQX7/oHbW2bhSD3RVEJjVCfBMZyqUqS0DRqlbkKM ih69gTUvK7de8mroWk2zWER/eoPJgoXlp27GNYMmKPejNHW02g+gIgdWvXzObjrzsmdc RffQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=AwE0AV+Yw6DG9ShIPjrC+51aeURUDYcHGi1kv7eWYy8=; b=bFKU7K+2/qK3Q7EVLfH9AJu9C3VoMlGEPQLYWxvOvhcbOPp6lZo4M76EEygAP8TIoQ A/3DP5JCMap2lNlZqEq/95g3cKEojOxauPCiK43XssHTI8hvu+/W9SH95B0wGt/l6ISa 5W7irFXKlnQ4a7QuR+Ahm13/XX10rQum6+I1nwcVOTAsv2vahoHnTDccLDIdeGGVWLCL 31kxGf3uUthauuq44+knUNU6FffbozgM/HZDcN661ccxtkd4Mb35qizToBhuyu5NWYBC oNLb3d/lBDgvaf0PbVMaZDNgMy6apxEfSvF2z3u2HbVcWWG4m5HavaVEfMYXgUxKsAX+ Md4w== X-Gm-Message-State: AN3rC/5bqLJGAkzJRGwFykHkNYL3GZY3CygKXJKcAW6A9TjMUzwL7FqgtEyAZTsTJE/Ydw== X-Received: by 10.237.44.99 with SMTP id f90mr6158925qtd.24.1491882745938; Mon, 10 Apr 2017 20:52:25 -0700 (PDT) Original-Received: from [192.168.1.198] (static-98-118-34-152.bstnma.fios.verizon.net. [98.118.34.152]) by smtp.gmail.com with ESMTPSA id 1sm5132602qtm.59.2017.04.10.20.52.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 20:52:25 -0700 (PDT) In-Reply-To: <505388da-e642-8c98-35c0-261d09ff13e1@yandex.ru> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:131455 Archived-At: This is a multi-part message in MIME format. --------------1D6459AC6D25AF909738FB0B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I've incorporated Thien-Thi's suggestion, as well as an if to check status for nil (which indicates unregistered). On 04/10/2017 08:07 PM, Dmitry Gutov wrote: > You are right. But we could set it in vc-state-refresh. > On 04/10/2017 07:46 PM, Dmitry Gutov wrote: > > Thanks. I guess the main thing left is to decide whether vc-git-state > should bind default-directory. For example, vc-bzr-state doesn't, > while vc-hg-state does. > > Does this binding affect the command output, in this particular case? The binding affects the output if default-directory is not set inside the file's repository. Since, in principle, the vc functions should be agnostic to the choice of vcs, either a) vc-state documentation should state that default-directory should be set to get generally correct responses or b) it should be set in some function (and I agree that vc-state-refresh makes sense). I think the overhead of setting the directory is rather low. In some admittedly rudimentary benchmarks, there is almost no difference in performance setting default-directory. There's also the question of how to handle default-directory. You cannot simply do (file-name-directory file), because that fails if FILE is given without a directory. I think the correct one is (file-name-directory (expand-file-name file)) (which, surprisingly, is slighly faster than (file-name-directory (concat default-directory file)) ). --------------1D6459AC6D25AF909738FB0B Content-Type: text/x-patch; name="0001-update-vc-git.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-update-vc-git.patch" >From 8892f98fc0a8a956bc1adefcc0394ac6cf5e47d3 Mon Sep 17 00:00:00 2001 From: Jonathan Ganc Date: Mon, 10 Apr 2017 00:38:52 -0400 Subject: [PATCH] update vc-git --- lisp/vc/vc-git.el | 79 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 1a3f1bf..7c16125 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -231,34 +231,61 @@ (defun vc-git--state-code (code) (?U 'edited) ;; FIXME (?T 'edited))) ;; FIXME +(defun vc-git--git-status-to-vc-state (code-list) + "Convert a list CODE-LIST of two-letter git status strings to a vc status. + +Each element of CODE-LIST comes from the first two characters of +a line returned by 'git status' and should be passed in the order given by 'git status'. + +\(It is necessary to allow CODE-LIST to be a list because +sometimes git status returns multiple lines, e.g. for a file that +is removed from the index but is present in the HEAD and working +tree.) " + (pcase code-list + ('nil 'up-to-date) + (`(,code) + (pcase code + ("!!" 'ignored) + ("??" 'unregistered) + ;; I have only seen this with a file that is only present in the + ;; index. Let us call this `removed' + ("AD" 'removed) + (_ (cond + ((string-match-p "^[ RD]+$" code) 'removed) + ((string-match-p "^[ M]+$" code) 'edited) + ((string-match-p "^[ A]+$" code) 'added) + ((string-match-p "^[ U]+$" code) 'conflict) + (t 'edited))))) + ;; I know of two times when git state returns more than one element, + ;; in both cases returning '("D " "??")': + ;; 1. when a file is removed from the index but present in the + ;; HEAD and working tree + ;; 2. when a file A is renamed to B in the index and then back to A + ;; in the working tree + ;; In both these instances, `unregistered' is a reasonable response. + (`("D " "??") 'unregistered) + ;; In other cases, let us return `edited'. + (_ 'edited))) + (defun vc-git-state (file) "Git-specific version of `vc-state'." - ;; FIXME: This can't set 'ignored or 'conflict yet - ;; The 'ignored state could be detected with `git ls-files -i -o - ;; --exclude-standard` It also can't set 'needs-update or - ;; 'needs-merge. The rough equivalent would be that upstream branch - ;; for current branch is in fast-forward state i.e. current branch - ;; is direct ancestor of corresponding upstream branch, and the file - ;; was modified upstream. But we can't check that without a network - ;; operation. - ;; This assumes that status is known to be not `unregistered' because - ;; we've been successfully dispatched here from `vc-state', that - ;; means `vc-git-registered' returned t earlier once. Bug#11757 - (let ((diff (vc-git--run-command-string - file "diff-index" "-p" "--raw" "-z" "HEAD" "--"))) - (if (and diff - (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\([ADMUT]\\)\0[^\0]+\0\\(.*\n.\\)?" - diff)) - (let ((diff-letter (match-string 1 diff))) - (if (not (match-beginning 2)) - ;; Empty diff: file contents is the same as the HEAD - ;; revision, but timestamps are different (eg, file - ;; was "touch"ed). Update timestamp in index: - (prog1 'up-to-date - (vc-git--call nil "add" "--refresh" "--" - (file-relative-name file))) - (vc-git--state-code diff-letter))) - (if (vc-git--empty-db-p) 'added 'up-to-date)))) + (let* ((default-directory (file-name-directory (expand-file-name file))) + (status + (vc-git--run-command-string file "status" "--porcelain" "-z" + "--untracked-files" "--ignored" "--")) + code-list) + (if (null status) + ;; If status is nil, there was an error running git, likely because + ;; the file is not in a git repo. + 'unregistered + ;; If this code is adapted to parse 'git status' for a directory, + ;; note that a renamed file takes up two null values and needs to be + ;; treated slightly more carefully. + (setq code-list + (mapcar (lambda (s) + (substring s 0 2)) + (delete "" (split-string status "\0")))) + (vc-git--git-status-to-vc-state code-list)))) (defun vc-git-working-revision (_file) "Git-specific version of `vc-working-revision'." -- 2.9.3 --------------1D6459AC6D25AF909738FB0B--