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: Tue, 25 Apr 2017 11:38:39 -0400 Message-ID: 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> <1a23269d-1ead-1771-1afd-e2c9c5840cb4@gmail.com> <30d8b181-d869-de24-9c86-cc1dc6ec461b@gmail.com> <6ea0d89d-1a24-30fe-dd9a-26a0157a4eae@yandex.ru> <01922284-4265-6510-feee-dcc7301787ad@gmail.com> <7346fb37-f0b2-77dc-c227-cacfbd372775@gmail.com> <874lxef9fq.fsf@linux-m68k.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------160953F263EE16EE2334073F" X-Trace: blaine.gmane.org 1493134768 395 195.159.176.226 (25 Apr 2017 15:39:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 25 Apr 2017 15:39:28 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cc: Noam Postavsky , 26066@debbugs.gnu.org, Stefan Monnier , Dmitry Gutov To: Andreas Schwab Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 25 17:39:23 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 1d32Yj-0008MD-Uk for geb-bug-gnu-emacs@m.gmane.org; Tue, 25 Apr 2017 17:39:22 +0200 Original-Received: from localhost ([::1]:49965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d32Yp-0007tB-GZ for geb-bug-gnu-emacs@m.gmane.org; Tue, 25 Apr 2017 11:39:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d32YV-0007mw-T9 for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2017 11:39:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d32YQ-0007p1-PP for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2017 11:39:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41744) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d32YQ-0007od-Jg for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2017 11:39:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d32YQ-0001HA-56 for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2017 11:39: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, 25 Apr 2017 15:39:02 +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: patch Original-Received: via spool by 26066-submit@debbugs.gnu.org id=B26066.14931347284885 (code B ref 26066); Tue, 25 Apr 2017 15:39:02 +0000 Original-Received: (at 26066) by debbugs.gnu.org; 25 Apr 2017 15:38:48 +0000 Original-Received: from localhost ([127.0.0.1]:39943 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d32YC-0001Gj-EN for submit@debbugs.gnu.org; Tue, 25 Apr 2017 11:38:48 -0400 Original-Received: from mail-qk0-f181.google.com ([209.85.220.181]:32861) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d32YA-0001GV-Hz for 26066@debbugs.gnu.org; Tue, 25 Apr 2017 11:38:46 -0400 Original-Received: by mail-qk0-f181.google.com with SMTP id h123so62562596qke.0 for <26066@debbugs.gnu.org>; Tue, 25 Apr 2017 08:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=BwASEmj97Un7+AqzpmBoOzVa1TkQD536ikc3jgAV+0c=; b=i5IY2F57aMI4txFCiB1jW5VNWrhbjjiwoyaZhLGgPMmLpDzQ9CfZOlsykOYucu2clg pS9QehmbCcCFaE/Z7pjnBs63AS7WcaINERq9t//QkVYmhP5Awv+VGBmIfAOqn5buok2t wc/k347G4LJKUYFEdUmTIW9Aq6I5gE6vKj/Cy3Qm/Hse3EbPmW/m3QMm600+J0/i40aY rxJiOrqCc33075URFw4qQx9uFMOTYil/S3OvdGyh/oe9jU0qV7Tm3kBNRBrMXHGCWaFa BJeWnF/QOhPqs1XpzWK/6HBBlCVFoWlx7OF/OilfuYYj5r6bjAYNtANUAvFeg4CJ0P2G dv6Q== 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:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=BwASEmj97Un7+AqzpmBoOzVa1TkQD536ikc3jgAV+0c=; b=ZhV109ji79Xov32sdufEtSfKS+XysAQ8oRw/FuzNZv5rjQJNH69l4iwVf78waHoE/A fW7Ih+QoS/nevlV7qvN/F8QMrSBTxSZPVzMEogqnKG2Mh2M/EgieE0Ia+vgf/tAM8YTm gZV0ZfJl9fPZawAwi+S5yOIx3D+rD0mn9P4XZFiz1lJ8rtNnbBtBDNnraoGCaAmL9yVf I14Uzw/jHvf0blPJr2T9Z6W2YO6T7I84iZ326FzPNVa/gEbbwXB1uMg9mJmzQxrBLqJA UrdGtxh/9oinGwlMF2/MN5uNtD/RrgPRzlzkC5/RLo2vKOZhL1pMQfh/lpQ0zdgrYELb Rqgw== X-Gm-Message-State: AN3rC/53x2KZsviwX+Lj4awFs6xK+fZEzpRuBI1bggliYqT8AkGQgfHm CZRPdjJ2nxJ4qA== X-Received: by 10.55.148.194 with SMTP id w185mr29085096qkd.58.1493134720925; Tue, 25 Apr 2017 08:38:40 -0700 (PDT) Original-Received: from [10.250.197.77] ([38.122.127.226]) by smtp.gmail.com with ESMTPSA id t45sm13738196qtt.9.2017.04.25.08.38.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 08:38:39 -0700 (PDT) In-Reply-To: <874lxef9fq.fsf@linux-m68k.org> 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:131963 Archived-At: This is a multi-part message in MIME format. --------------160953F263EE16EE2334073F Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Good point. Changed. On 04/24/2017 05:20 AM, Andreas Schwab wrote: > On Apr 23 2017, Jonathan Ganc wrote: > >> +(defun vc-git--git-status-to-vc-state (code-list) >> + "Convert CODE-LIST 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.) " > I think the last paragraph could just be a code comment, given that you > even put it in parens to de-emphasize it. Also, extra space at the end. > > Andreas. > --------------160953F263EE16EE2334073F Content-Type: text/x-patch; name="0001-Update-vc-git-state-to-use-git-status.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Update-vc-git-state-to-use-git-status.patch" >From 6407a6dee770a3981977625c9b0648ca29c4f99c Mon Sep 17 00:00:00 2001 From: Jonathan Ganc Date: Mon, 10 Apr 2017 00:38:52 -0400 Subject: [PATCH] Update vc-git-state to use 'git status' * lisp/vc/vc-git.el (vc-git-state, vc-git--git-status-to-vc-state): Update 'vc-git-state' to use 'git status', so that 'vc-git-state' can now return 'ignored', 'conflict', or 'unregistered' if appropriate. Related to bug#26066. --- lisp/vc/vc-git.el | 76 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 1a3f1bf..6604220 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -231,34 +231,58 @@ (defun vc-git--state-code (code) (?U 'edited) ;; FIXME (?T 'edited))) ;; FIXME +(defun vc-git--git-status-to-vc-state (code-list) + "Convert CODE-LIST 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 ((status + (vc-git--run-command-string file "status" "--porcelain" "-z" + "--untracked-files" "--ignored" "--"))) + (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. + (vc-git--git-status-to-vc-state + (mapcar (lambda (s) + (substring s 0 2)) + (split-string status "\0" t)))))) + (defun vc-git-working-revision (_file) "Git-specific version of `vc-working-revision'." -- 2.9.3 --------------160953F263EE16EE2334073F--