git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Habouzit <madcoder@debian.org>
To: Jan Hudec <bulb@ucw.cz>
Cc: "Git ML" <git@vger.kernel.org>, "Kristian Høgsberg" <krh@redhat.com>
Subject: Re: [RFC] best way to show diff of commit
Date: Mon, 26 Nov 2007 09:42:39 +0100	[thread overview]
Message-ID: <20071126084239.GA23373@artemis.corp> (raw)
In-Reply-To: <20071126002519.GA11133@efreet.light.src>

[-- Attachment #1: Type: text/plain, Size: 4079 bytes --]

On Mon, Nov 26, 2007 at 12:25:19AM +0000, Jan Hudec wrote:
> On Sun, Nov 25, 2007 at 22:18:31 +0100, Pierre Habouzit wrote:
> >   My question is: what do you think is the best way to do that, and
> > where ?
> 
> Are you talking about the ftplugins/git.vim script from vim-scripts package,
> right?

  Yes, its author.

> All it needs to do is call 'git diff --cached'. The below patch seems to work
> here (tried commit, commit -a, commit --amend, commit -a --amend and commit
> from subdirectory and they seemed to all work).

  Damn if that's so simple, I really feel like a big fool now.

> >   [0] the issue with this approach is that it's completely broken in
> >       amending mode (does not shows the proper thing), and the generated
> 
> I didn't find any issue with amending mode (showed incremental diff for me
> all right). The problem was when a file was being touched by the commit but
> work tree had unstaged changes. Such changes were shown when they shouldn't.

  Yep, that's the point.

> >       diffs aren't excellent, because as an editor plugin, it's hard to
> >       treat renames and copies easily, so I generate really really nasty
> >       diffs in that case too.
> 
> With --cached, detecting copies is just a matter of adding -C. In the patch
> below I added only one -C, but it should probably be user-configurable to use
> no, one or two (equivalent of --find-copies-harder).

  Sure, I'll do that obviously.

  Thanks a lot for the tip.
> 
> -- 
> 						 Jan 'Bulb' Hudec <bulb@ucw.cz>
> 
> ---8<---
> --- vim-scripts/ftplugin/git.vim.orig	2007-07-24 09:46:19.000000000 +0200
> +++ vim-scripts/ftplugin/git.vim	2007-11-26 01:01:59.000000000 +0100
> @@ -14,41 +14,6 @@
>  "{{{ function Git_diff_windows
>  
>  function! Git_diff_windows(vertsplit, auto)
> -    let i = 0
> -    let list_of_files = ''
> -
> -    " drop everything until '#  (will commit)' and the next empty line
> -    while i <= line('$')
> -        let line = getline(i)
> -        if line == '# Changes to be committed:'
> -            let i = i + 3
> -            break
> -        endif
> -
> -        let i = i + 1
> -    endwhile
> -
> -    " read file names until we have EOF or an empty line
> -    while i <= line('$')
> -        let line = getline(i)
> -        if line =~ '^#\s*[a-z ]*:.*->.*$'
> -            let file = substitute(line, '^#[^:]*:.*->\s*\(.*\)\s*$', '\1', '')
> -            let list_of_files = list_of_files . ' '.file
> -            let file = substitute(line, '^#[^:]*:\s*\(.*\)\s*->.*$', '\1', '')
> -            let list_of_files = list_of_files . ' '.file
> -        elseif line =~ '^#\s*[a-z ]*:'
> -            let file = substitute(line, '^#[^:]*:\s*\(.*\)\s*$', '\1', '')
> -            let list_of_files = list_of_files . ' '.file
> -        elseif line =~ '^#\s*$'
> -            break
> -        endif
> -
> -        let i = i + 1
> -    endwhile
> -
> -    if list_of_files == ""
> -        return
> -    endif
>  
>      if a:vertsplit
>          rightbelow vnew
> @@ -56,15 +21,8 @@
>          rightbelow new
>      endif
>      silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
> -    let gitDir = system('git rev-parse --git-dir 2>/dev/null')
> -    let gitDir = substitute(gitDir, '.git\n', '', '')
> -    let wd = getcwd()
> -    if gitDir != ''
> -        exe 'cd '.gitDir
> -    endif
> -    exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . "\n1Gdd"
> -    exe 'normal :r!LANG=C git diff --stat HEAD -- ' . list_of_files . "\no\<esc>1GddO\<esc>"
> -    exe 'cd '.wd
> +    exe "normal :r!LANG=C git diff --cached -C\n1Gdd"
> +    exe "normal :r!LANG=C git diff --stat --cached -C\no\<esc>1GddO\<esc>"
>      setlocal nomodifiable
>      noremap <buffer> q :bw<cr>
>      if a:auto

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2007-11-26  8:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-25 21:18 [RFC] best way to show diff of commit Pierre Habouzit
2007-11-25 21:27 ` J. Bruce Fields
2007-11-25 22:09   ` Pierre Habouzit
2007-11-25 22:27     ` Junio C Hamano
2007-11-25 22:31       ` Pierre Habouzit
2007-11-25 22:52         ` Junio C Hamano
2007-11-25 23:47           ` Pierre Habouzit
2007-11-25 23:43       ` David Brown
2007-11-26  0:25 ` Jan Hudec
2007-11-26  8:42   ` Pierre Habouzit [this message]
2007-11-26  8:47   ` Pierre Habouzit
2007-11-26  8:59     ` [PATCH] Make builtin-commit.c export GIT_INDEX_FILE for launch_editor as well Pierre Habouzit
2007-11-26  9:38       ` Pierre Habouzit
2007-11-26 15:27       ` Kristian Høgsberg

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=20071126084239.GA23373@artemis.corp \
    --to=madcoder@debian.org \
    --cc=bulb@ucw.cz \
    --cc=git@vger.kernel.org \
    --cc=krh@redhat.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).