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: Sun, 23 Apr 2017 20:50:38 -0400 Message-ID: <7346fb37-f0b2-77dc-c227-cacfbd372775@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> <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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7303FD8667010B222A562449" X-Trace: blaine.gmane.org 1492995073 18655 195.159.176.226 (24 Apr 2017 00:51:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 24 Apr 2017 00:51:13 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cc: 26066@debbugs.gnu.org, Stefan Monnier , Dmitry Gutov To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 24 02:51:09 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 1d2SDd-0004jb-7d for geb-bug-gnu-emacs@m.gmane.org; Mon, 24 Apr 2017 02:51:09 +0200 Original-Received: from localhost ([::1]:41131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2SDh-0003zT-Bh for geb-bug-gnu-emacs@m.gmane.org; Sun, 23 Apr 2017 20:51:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46148) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2SDa-0003zM-7l for bug-gnu-emacs@gnu.org; Sun, 23 Apr 2017 20:51:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2SDX-0004Wu-2s for bug-gnu-emacs@gnu.org; Sun, 23 Apr 2017 20:51:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38748) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d2SDW-0004Wm-O2 for bug-gnu-emacs@gnu.org; Sun, 23 Apr 2017 20:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d2SDW-0005pG-Bi for bug-gnu-emacs@gnu.org; Sun, 23 Apr 2017 20:51: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, 24 Apr 2017 00:51: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.149299504922355 (code B ref 26066); Mon, 24 Apr 2017 00:51:02 +0000 Original-Received: (at 26066) by debbugs.gnu.org; 24 Apr 2017 00:50:49 +0000 Original-Received: from localhost ([127.0.0.1]:36947 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d2SDJ-0005oV-Cp for submit@debbugs.gnu.org; Sun, 23 Apr 2017 20:50:49 -0400 Original-Received: from mail-qt0-f193.google.com ([209.85.216.193]:36068) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d2SDH-0005o5-9l for 26066@debbugs.gnu.org; Sun, 23 Apr 2017 20:50:47 -0400 Original-Received: by mail-qt0-f193.google.com with SMTP id t52so18485793qtb.3 for <26066@debbugs.gnu.org>; Sun, 23 Apr 2017 17:50:47 -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=MUGWZEyZo3sYXKm3JYsOMTc3nSv/J37hwCtHzRKDizo=; b=AwBAInjIvT48/exqeEkDKCuGBPdTgXJetGQrBjZ+sBu+hYx/kQ52LyjfA5ObkgOfgV W5OVL1fi3Im8J39ocH1Tbxh2qteU4vJUAsEQL0IDRWD42aZ67ppVikMfHdXWxhL3MWXb YJshHl9QAzHmJWbZVBTzxmncjw/0VMyONz2OJhD9xwLWJ66oNTGjJW5CLioOHElaG9b/ dBV93us5nU8KJSRnM5yFyoGYjCZbc0GWMaoao3hY8NbkF575aX7YwsF/zm4OUv7NUOZ7 eeJl75UnNrZF1rO4HVNyUoBLBLRe3hhFtHeTA1z8Z4WWBOB83OcqTrOtYaxX4TMU4jLc yEVQ== 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=MUGWZEyZo3sYXKm3JYsOMTc3nSv/J37hwCtHzRKDizo=; b=DPnPdKwm+1ZtNbdm7DDo52dd4ZPC7LkYAw2ElSL2BMqbQmJE6YzcSzKXtPqKvzaIkn 1EKnaHYpOwQkTRw3iK9n3mlqV7d/Ivg0JpggFNQNrpDax56bK/kV8At8QsEe0uHwBuok sA4BFGM+U67UoU2XjEdvVoBv6cKu5XV/QzZ4V0gxTHZ6T7b1d/ilH/8gF/VeS2lU5s3f rJudk76bSPrSZc2lYqNFjP7aqk1N/sh07N3I5ieoiA18cLS2VBCUOcgM2vxEfDvvIqON 2kgu/QxwHGsESFxaY2+JsTyg8IDzD9+NKqNic1MgtNRON0svtAETPETxis5+vf3wjBbV ockA== X-Gm-Message-State: AN3rC/5MTR3drbblERpA9OVIih+1T8SCKQyiGW90+6ASByDuGmAZ4Mg9 pyCds+nDwsym/g== X-Received: by 10.200.44.130 with SMTP id 2mr24795748qtw.59.1492995041420; Sun, 23 Apr 2017 17:50:41 -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 r46sm11797361qtc.1.2017.04.23.17.50.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Apr 2017 17:50:40 -0700 (PDT) In-Reply-To: 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:131922 Archived-At: This is a multi-part message in MIME format. --------------7303FD8667010B222A562449 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for the feedback! Updated with the suggested changes. On 04/23/2017 06:28 PM, Noam Postavsky wrote: >> Subject: [PATCH] update vc-git >> >> --- > Could you add a meaningful commit message please? See CONTRIBUTE (under > "Commit messages") for details of Emacs' standard format. > > I think the patch is basically okay now, just a few minor nitpicks below. > >> +(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. > This line is too long, I think it should be fine to shorten to just > "Convert CODE-LIST to a vc status". You explain the format of > CODE-LIST in the next paragraph anyway. > >> +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'. > This paragraph looks unfilled, hit M-q on it. > >> + ;; I have only seen this with a file that is only present in the >> + ;; index. Let us call this `removed' > Missing period. > >> + (setq code-list >> + (mapcar (lambda (s) >> + (substring s 0 2)) >> + (delete "" (split-string status "\0")))) > If you pass a non-nil OMIT-NULLS parameter to split-string, the > (delete ""...) should become unnecessary. > >> + (vc-git--git-status-to-vc-state code-list)))) > I would suggest dropping the temporary code-list variable here, and > just do > > (vc-git--git-status-to-vc-state > (mapcar (lambda (s) (substring s 0 2)) > (split-string status "\0" t))) --------------7303FD8667010B222A562449 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 5c123593c110323edfe357c26ee136de31c14ab8 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 | 78 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 1a3f1bf..9fb35bd 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -231,34 +231,60 @@ (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 --------------7303FD8667010B222A562449--