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 00:41:15 -0400 Message-ID: <39da25d7-95d1-5b23-f5b1-c6b996aaece7@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> <7fccafd3-e2c2-204a-05a0-a930a4cbb7e4@gmail.com> <85978a9c-8b2f-484b-1330-be915fe05085@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------4F537D67227018580F1D0513" X-Trace: blaine.gmane.org 1491799337 24846 195.159.176.226 (10 Apr 2017 04:42:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 10 Apr 2017 04:42: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 Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 10 06:42:11 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 1cxR9X-0006Ht-CR for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Apr 2017 06:42:11 +0200 Original-Received: from localhost ([::1]:60553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxR9Y-0002nO-He for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Apr 2017 00:42:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxR9R-0002n7-RI for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 00:42:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxR9O-0001ob-IY for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 00:42:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxR9O-0001oX-DY for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 00:42:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cxR9O-0001n2-52 for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 00:42: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: Mon, 10 Apr 2017 04:42: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: Original-Received: via spool by 26066-submit@debbugs.gnu.org id=B26066.14917992846834 (code B ref 26066); Mon, 10 Apr 2017 04:42:02 +0000 Original-Received: (at 26066) by debbugs.gnu.org; 10 Apr 2017 04:41:24 +0000 Original-Received: from localhost ([127.0.0.1]:40424 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxR8m-0001mA-E2 for submit@debbugs.gnu.org; Mon, 10 Apr 2017 00:41:24 -0400 Original-Received: from mail-qt0-f193.google.com ([209.85.216.193]:34522) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxR8k-0001lx-6D for 26066@debbugs.gnu.org; Mon, 10 Apr 2017 00:41:22 -0400 Original-Received: by mail-qt0-f193.google.com with SMTP id r49so4750035qta.1 for <26066@debbugs.gnu.org>; Sun, 09 Apr 2017 21:41:22 -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=TR1miUIinQmx6rni6Mk6W9CYwlJuejRgn2J+iEmhHIk=; b=n7n740qG+/XYuxtsEkjztZ3T4Xn3CPStwsZ8n6PTR0x1CAbETMTnHo1U9TSH2MKZkX agGVh2nmvQb4B/+2d7siWrHlSM2bX74XnhJzzjxdCKp6cOoRz5hhL5wXkompiPV4ECtg G/sTc1njY7jzJBqe1oI08EkbDLm6HWihZZ81LJXIyv2tP3ZiRcsrJ3r7qUx5+k/jsbxo jpk0Vzw40pNawD80De06LzGL5E35La+MfitpRxOIppr5YfPPPctFdfoo77PpePHZoWJa fjOCQG5f2yfjBikbS4SeWPrxpZqoAwPxSen0iWw620JB6uwfYYxCQcui1Ub4Sfu+cu4+ CiEA== 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=TR1miUIinQmx6rni6Mk6W9CYwlJuejRgn2J+iEmhHIk=; b=iqvxI1z+gTun19pj4c8TukIwTAXe5iA07nuidX+yg2ho+YDvGX6k0hxg+EADPhQsGK qYwG5t4mqPwUP7qunAZEXO8+g/RhPilVLa0d7rNvFer0S9zy1akLGElhV7vPIFpUilWD Eaim54TT4Y/ji7bsK5PkvMKfbFdZh8WQn/r+CKOrNCIrIf1hlVPNFnVOJ2d3OqqPbhxs aYM/p/CyIDN0tO/wzAAKdtCwZJ/q9wZkY5khuTrVPzjSL8D7dEoAakRMZDpRrwjmlTrw 0hoEz8QsA1ZKkzaCjt8udR431lWHQk4X22Y4PKEe8WCksN8zq2MQpYw6BQRoL5hvBU7w zAxA== X-Gm-Message-State: AFeK/H2TibY3OcREeC7fzKMJ82Hx8H8cpuUWxWGZv9S5fY+Fg6GCa8fsK4iZLvOmIzobHg== X-Received: by 10.237.33.251 with SMTP id m56mr55538830qtc.121.1491799276676; Sun, 09 Apr 2017 21:41:16 -0700 (PDT) Original-Received: from [192.168.1.200] (static-98-118-34-152.bstnma.fios.verizon.net. [98.118.34.152]) by smtp.gmail.com with ESMTPSA id 44sm8126057qts.15.2017.04.09.21.41.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Apr 2017 21:41:15 -0700 (PDT) In-Reply-To: <85978a9c-8b2f-484b-1330-be915fe05085@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:131433 Archived-At: This is a multi-part message in MIME format. --------------4F537D67227018580F1D0513 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I agree with the suggestions from both of you and have made the corrections. I have attached a new patch. Please let me know if you have further thoughts. I will gladly sign a copyright assignment, if you point me to where I can do that. On 04/09/2017 11:26 PM, Dmitry Gutov wrote: > On 31.03.2017 06:16, Jonathan Ganc wrote: >> + (save-match-data >> + (let* ((default-directory (file-name-directory (expand-file-name >> file))) > > We don't require or expect that any particular function keeps the > match data intact. I don't think that save-match-data is needed here. > > Aside from this an Noam's comments, the patch is long enough to > require a copyright assignment. I didn't find yours on file. > > Will you sign one? --------------4F537D67227018580F1D0513 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 78bcdd00927bc8f14ef2999b8bf0b4ad25ab6dac 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 | 75 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 1a3f1bf..a8d686a 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -231,34 +231,57 @@ (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 (next-match 0)) + ;; 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. + (while (string-match "\\(..\\) [^\0]+\0" status next-match) + (push (match-string 1 status) code-list) + (setq next-match (match-end 0))) + (setq code-list (nreverse code-list)) + (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 --------------4F537D67227018580F1D0513--