From: Jonathan Ganc <jonganc@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>,
npostavs@users.sourceforge.net, 26066@debbugs.gnu.org,
Stefan Monnier <monnier@IRO.UMontreal.CA>
Subject: bug#26066: 26.0.50; vc-git-status gives wrong result
Date: Mon, 10 Apr 2017 23:52:24 -0400 [thread overview]
Message-ID: <1a23269d-1ead-1771-1afd-e2c9c5840cb4@gmail.com> (raw)
In-Reply-To: <505388da-e642-8c98-35c0-261d09ff13e1@yandex.ru>
[-- Attachment #1: Type: text/plain, Size: 1424 bytes --]
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)) ).
[-- Attachment #2: 0001-update-vc-git.patch --]
[-- Type: text/x-patch, Size: 4643 bytes --]
From 8892f98fc0a8a956bc1adefcc0394ac6cf5e47d3 Mon Sep 17 00:00:00 2001
From: Jonathan Ganc <jonganc@gmail.com>
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
next prev parent reply other threads:[~2017-04-11 3:52 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-12 2:42 bug#26066: 26.0.50; vc-git-status gives wrong result Jonathan Ganc
2017-03-14 13:45 ` npostavs
2017-03-16 0:42 ` npostavs
2017-03-16 0:48 ` Dmitry Gutov
2017-03-16 2:40 ` Jonathan Ganc
2017-03-21 9:19 ` Dmitry Gutov
2017-03-21 16:10 ` Jonathan Ganc
2017-03-22 12:11 ` Michael Heerdegen
2017-03-22 16:20 ` Dmitry Gutov
2017-03-23 2:18 ` Jonathan Ganc
2017-03-31 3:16 ` Jonathan Ganc
2017-04-10 2:16 ` Jonathan Ganc
2017-04-10 2:58 ` npostavs
2017-04-10 3:26 ` Dmitry Gutov
2017-04-10 4:41 ` Jonathan Ganc
2017-04-10 6:05 ` Eli Zaretskii
2017-04-10 7:35 ` Thien-Thi Nguyen
2017-04-10 23:46 ` Dmitry Gutov
2017-04-10 4:43 ` Jonathan Ganc
2017-04-10 23:26 ` Dmitry Gutov
2017-04-11 0:07 ` Dmitry Gutov
2017-04-11 3:52 ` Jonathan Ganc [this message]
2017-04-11 13:08 ` Jonathan Ganc
2017-04-11 23:27 ` Dmitry Gutov
2017-04-11 23:36 ` Dmitry Gutov
2017-04-14 0:42 ` Jonathan Ganc
2017-04-23 18:21 ` Jonathan Ganc
2017-04-23 22:28 ` Noam Postavsky
2017-04-23 22:45 ` Stefan Monnier
2017-04-24 0:50 ` Jonathan Ganc
2017-04-24 9:20 ` Andreas Schwab
2017-04-25 15:38 ` Jonathan Ganc
2017-04-25 23:49 ` Dmitry Gutov
2017-04-26 3:18 ` Jonathan Ganc
2017-05-01 1:43 ` Dmitry Gutov
2019-06-24 23:01 ` Lars Ingebrigtsen
2020-08-10 15:05 ` Lars Ingebrigtsen
2017-05-01 1:57 ` Dmitry Gutov
2017-05-01 19:22 ` Jonathan Ganc
2017-05-01 19:42 ` Eli Zaretskii
2017-05-01 22:13 ` Dmitry Gutov
2017-03-18 2:38 ` Jonathan Ganc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1a23269d-1ead-1771-1afd-e2c9c5840cb4@gmail.com \
--to=jonganc@gmail.com \
--cc=26066@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=monnier@IRO.UMontreal.CA \
--cc=npostavs@users.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.