From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: Re: [vc-git] Showing =?utf-8?b?4oCYLmdpdC8q4oCZ?= files in vc-dir Date: Sun, 04 Jul 2010 15:30:57 -0400 Message-ID: References: <4C2A5279.2080706@cybersprocket.com> <4C30C459.6050904@cybersprocket.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1278271869 19874 80.91.229.12 (4 Jul 2010 19:31:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 4 Jul 2010 19:31:09 +0000 (UTC) Cc: emacs-devel@gnu.org, Stefan Monnier , Miles Bader To: Eric James Michael Ritz Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 04 21:31:07 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OVUu9-0004Hn-Nz for ged-emacs-devel@m.gmane.org; Sun, 04 Jul 2010 21:31:06 +0200 Original-Received: from localhost ([127.0.0.1]:54810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OVUu8-0007DN-V3 for ged-emacs-devel@m.gmane.org; Sun, 04 Jul 2010 15:31:05 -0400 Original-Received: from [199.232.76.173] (port=45068 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OVUu3-0007DI-Ph for emacs-devel@gnu.org; Sun, 04 Jul 2010 15:30:59 -0400 Original-Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1OVUu2-0001Cv-1O for emacs-devel@gnu.org; Sun, 04 Jul 2010 15:30:59 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]:60259) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1OVUu1-0001Cr-P3 for emacs-devel@gnu.org; Sun, 04 Jul 2010 15:30:57 -0400 Original-Received: from dann by fencepost.gnu.org with local (Exim 4.69) (envelope-from ) id 1OVUu1-0000pU-Kg; Sun, 04 Jul 2010 15:30:57 -0400 In-Reply-To: <4C30C459.6050904@cybersprocket.com> (Eric James Michael Ritz's message of "Sun\, 04 Jul 2010 13\:26\:49 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:126760 Archived-At: Eric James Michael Ritz writes: > On 07/01/2010 02:44 AM, Dan Nicolaescu wrote: >> Miles Bader writes: >> >>> Dan Nicolaescu writes: >>>>>> Not sure what the best solution is: make vc-git-state return >>>>>> nil, or make vc-dir ignore files in .git, or something else ... >>>>> >>>>> Maybe find-file shouldn't add unregistered files to vc-dir buffers. >>>> >>>> Sure it should, one wants to be able to register those files. >>> >>> One can visit the file and "register" it that way, right (C-x v v)? >> >> This is going on the wrong track. >> >> The problem is not unrelated to adding 'unregistered files. >> >> The issue is that vc-git-state says 'unregistered for files that it >> should not say 'unregistered. >> >> (vc-git-state "SOME_FILE_THAT_DOES_NOT_EXIST") says 'unregistered >> >> (vc-git-state ".git/HEAD") says 'unregistered >> >> >> This patch seems to fix it: >> >> [...] >> >> It would be nice if someone more familiar with the git low level >> commands would take a look at this function and try to make it a bit better. >> As the comment there says, it should be able to return 'ignored. >> It would be nice if it could be able to return 'conflict too. > > After looking into this a little more, and learning a little more > about the internals of vc-mode in general, I put together a patch that > fixes the original problem that I was having. It also causes things like > > (vc-git-state ".git/HEAD") > > to return nil instead of 'unregistered. It also causes ignored files > to return 'ignored. It still does nothing to return 'conflict in > the right situations. Below is the patch. > > ---------------------------------------------------------------------- > > * vc-git.el (vc-git-state): Return nil for files in the core `.git' > directories, and also return 'ignored for files that are being > ignored. > > When using vc-dir to work with a directory under source control by > Git, it is possible for vc-dir to show files under the top-level > `.git' directory as being unregistered. As correctly guessed by Dan > Nicolescu, this is caused when a user has $EDITOR configured to be > emacsclient, and he performs certain Git operations outside of > vc-mode, e.g. running `git-commit' from the command line. > > It is unlikely that any user would want to perform operations on a > file inside of the `.git' directory via vc-dir. Therefore we can > prevent those files from appearing by teaching `vc-git-state' to > return nil for any file in those directories. > --- > lisp/ChangeLog | 6 ++++++ > lisp/vc-git.el | 36 ++++++++++++++++++++++++++---------- > 2 files changed, 32 insertions(+), 10 deletions(-) > > diff --git a/lisp/ChangeLog b/lisp/ChangeLog > index 953c04e..5f84e52 100644 > --- a/lisp/ChangeLog > +++ b/lisp/ChangeLog > @@ -1,3 +1,9 @@ > +2010-07-04 Eric James Michael Ritz > + > + * vc-git.el (vc-git-state): Return nil for files in the core > + `.git' directories, and also return 'ignored for files that are > + being ignored. > + > 2010-06-27 Oleksandr Gavenko (tiny change) > > * generic-x.el (bat-generic-mode): Fix regexp for command line > diff --git a/lisp/vc-git.el b/lisp/vc-git.el > index 24062a0..ee94ee4 100644 > --- a/lisp/vc-git.el > +++ b/lisp/vc-git.el > @@ -171,16 +171,32 @@ If nil, use the value of `vc-diff-switches'. If t, use no switches." > > (defun vc-git-state (file) > "Git-specific version of `vc-state'." > - ;; FIXME: This can't set 'ignored yet > - (if (not (vc-git-registered file)) > - 'unregistered > - (vc-git--call nil "add" "--refresh" "--" (file-relative-name file)) > - (let ((diff (vc-git--run-command-string > - file "diff-index" "-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" > - diff)) > - (vc-git--state-code (match-string 1 diff)) > - (if (vc-git--empty-db-p) 'added 'up-to-date))))) > + ;; A file in a '.git/' directory. > + (cond ((string-match-p (rx string-start > + (zero-or-more anything) > + (optional "/") > + ".git/" > + (optional (zero-or-more anything))) > + file) > + nil) Nothing else in vc-git.el uses `rx', for consistency it would be better to avoid it here too. Does this work on MS windows too? I'd like a second opinion about this: should we go for file name matching as above, or just use "git ls-files"? > + ;; Unregistered or ignored file. > + ((not (vc-git-registered file)) > + (if (vc-git-file-is-ignored (file-relative-name file)) > + 'ignored > + 'unregistered)) > + (t > + (vc-git--call nil "add" "--refresh" "--" (file-relative-name file)) > + (let ((diff (vc-git--run-command-string > + file "diff-index" "-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" > + diff)) > + (vc-git--state-code (match-string 1 diff)) > + (if (vc-git--empty-db-p) 'added 'up-to-date)))))) > + > +(defun vc-git-file-is-ignored (file) > + "Returns non-nil if the `file' is not being ignored." > + (vc-git--run-command-string > + file "ls-files" "--others" "--ignored" "--exclude-standard" "--")) > > (defun vc-git-working-revision (file) > "Git-specific version of `vc-working-revision'." > -- > 1.7.2.rc1