emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vc-git] Showing ‘.git/*’ files in vc-dir


From: Dan Nicolaescu
Subject: Re: [vc-git] Showing ‘.git/*’ files in vc-dir
Date: Sun, 04 Jul 2010 15:30:57 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Eric James Michael Ritz <address@hidden> writes:

> On 07/01/2010 02:44 AM, Dan Nicolaescu wrote:
>> Miles Bader <address@hidden> writes:
>>
>>> Dan Nicolaescu <address@hidden> 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 <address@hidden>
> +
> +     * 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  <address@hidden>  (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]