{"thread":{"id":"11013","subject":"[RFC] best way to show diff of commit","startedAt":"2007-11-25T21:18:31Z","lastAt":"2007-11-26T15:27:30Z","messageCount":14,"participants":["Pierre Habouzit","J. Bruce Fields","Junio C Hamano","David Brown","Jan Hudec","Kristian Høgsberg"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"60867","messageId":"20071125211831.GA21121@artemis.corp","threadId":"11013","inReplyTo":null,"subject":"[RFC] best way to show diff of commit","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-25T21:18:31Z","receivedAt":"2007-11-25T21:18:31Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"  Hi there,\n\n  There is specific script I run in my vim with git, that tries to show\nfrom the 'status' git commit shows in the buffer which list of files has\nchanged, and builds a diff from it quite clumsily[0].\n\n  I wonder how hard it would be for git commit to \"stash\" the current\ncommit being sent somewhere editors would be able to have a look at (an\nalternate index is probably fine). Note that maybe I'm stupid and\noverlooked that such a thing already exists.  I'd like to have it in two\nflavors: normal and amend mode. normal mode would show what the\nresulting commit diff looks like, and the amend mode only shows the\nincrementall diff the amend adds to the previous commit.\n\n  My question is: what do you think is the best way to do that, and\nwhere ?\n\n\n\n  [0] the issue with this approach is that it's completely broken in\n      amending mode (does not shows the proper thing), and the generated\n      diffs aren't excellent, because as an editor plugin, it's hard to\n      treat renames and copies easily, so I generate really really nasty\n      diffs in that case too.\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"60868","messageId":"20071125212748.GB23820@fieldses.org","threadId":"11013","inReplyTo":"20071125211831.GA21121@artemis.corp","subject":"Re: [RFC] best way to show diff of commit","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2007-11-25T21:27:48Z","receivedAt":"2007-11-25T21:27:48Z","isPatch":false,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Sun, Nov 25, 2007 at 10:18:31PM +0100, Pierre Habouzit wrote:\n>   There is specific script I run in my vim with git, that tries to show\n> from the 'status' git commit shows in the buffer which list of files has\n> changed, and builds a diff from it quite clumsily[0].\n> \n>   I wonder how hard it would be for git commit to \"stash\" the current\n> commit being sent somewhere editors would be able to have a look at (an\n> alternate index is probably fine). Note that maybe I'm stupid and\n> overlooked that such a thing already exists.  I'd like to have it in two\n> flavors: normal and amend mode. normal mode would show what the\n> resulting commit diff looks like, and the amend mode only shows the\n> incrementall diff the amend adds to the previous commit.\n> \n>   My question is: what do you think is the best way to do that, and\n> where ?\n\nHave you checked whether \"git-commit -v\" already does what you want?\n\n--b.\n"},{"id":"60878","messageId":"20071125220902.GB21121@artemis.corp","threadId":"11013","inReplyTo":"20071125212748.GB23820@fieldses.org","subject":"Re: [RFC] best way to show diff of commit","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-25T22:09:02Z","receivedAt":"2007-11-25T22:09:02Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Sun, Nov 25, 2007 at 09:27:48PM +0000, J. Bruce Fields wrote:\n> On Sun, Nov 25, 2007 at 10:18:31PM +0100, Pierre Habouzit wrote:\n> >   There is specific script I run in my vim with git, that tries to show\n> > from the 'status' git commit shows in the buffer which list of files has\n> > changed, and builds a diff from it quite clumsily[0].\n> > \n> >   I wonder how hard it would be for git commit to \"stash\" the current\n> > commit being sent somewhere editors would be able to have a look at (an\n> > alternate index is probably fine). Note that maybe I'm stupid and\n> > overlooked that such a thing already exists.  I'd like to have it in two\n> > flavors: normal and amend mode. normal mode would show what the\n> > resulting commit diff looks like, and the amend mode only shows the\n> > incrementall diff the amend adds to the previous commit.\n> > \n> >   My question is: what do you think is the best way to do that, and\n> > where ?\n> \n> Have you checked whether \"git-commit -v\" already does what you want?\n\n  Hmm it doesn't because I would have to call git commit -v each time I\ncommit and well I _like_ having the status better. And moreover I want\nthe diff to go in a separated buffer too.\n\n  I'd rather have some kind of way to have git-commit let a trail of\nwhat he's doing if the user validate the commit, and use that from the\neditor. I'm sure it would be useful to simple GUIs as well (most\nadvanced GUIs would like to have fine control to what gets commited and\nare likely to have the command like used quite right).\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"60880","messageId":"7vfxyuj70i.fsf@gitster.siamese.dyndns.org","threadId":"11013","inReplyTo":"20071125220902.GB21121@artemis.corp","subject":"Re: [RFC] best way to show diff of commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-25T22:27:09Z","receivedAt":"2007-11-25T22:27:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> writes:\n\n>   Hmm it doesn't because I would have to call git commit -v each time I\n> commit and well I _like_ having the status better. And moreover I want\n> the diff to go in a separated buffer too.\n\nI've never felt it a problem while editing the log message in Emacs.\n\nDon't enhanced vi implementations let you split the same buffer into\ntwo allowing you to view different portions of it these days?\n"},{"id":"60883","messageId":"20071125223150.GD21121@artemis.corp","threadId":"11013","inReplyTo":"7vfxyuj70i.fsf@gitster.siamese.dyndns.org","subject":"Re: [RFC] best way to show diff of commit","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-25T22:31:50Z","receivedAt":"2007-11-25T22:31:50Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Sun, Nov 25, 2007 at 10:27:09PM +0000, Junio C Hamano wrote:\n> Pierre Habouzit <madcoder@debian.org> writes:\n> \n> >   Hmm it doesn't because I would have to call git commit -v each time I\n> > commit and well I _like_ having the status better. And moreover I want\n> > the diff to go in a separated buffer too.\n> \n> I've never felt it a problem while editing the log message in Emacs.\n> \n> Don't enhanced vi implementations let you split the same buffer into\n> two allowing you to view different portions of it these days?\n\n  Well, maybe I could write my plugin so that it cuts the diff out from\nthe main buffer indeed, though I will have to learn using git commit -v\ninstead of git commit :P\n\n  That and the fact that the syntax colorization of the diff doesn't\nwork, but it's probably not up to git to fix that.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"60885","messageId":"7v1waej5ub.fsf@gitster.siamese.dyndns.org","threadId":"11013","inReplyTo":"20071125223150.GD21121@artemis.corp","subject":"Re: [RFC] best way to show diff of commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-25T22:52:28Z","receivedAt":"2007-11-25T22:52:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> writes:\n\n> On Sun, Nov 25, 2007 at 10:27:09PM +0000, Junio C Hamano wrote:\n>> Pierre Habouzit <madcoder@debian.org> writes:\n>> \n>> >   Hmm it doesn't because I would have to call git commit -v each time I\n>> > commit and well I _like_ having the status better. And moreover I want\n>> > the diff to go in a separated buffer too.\n>> \n>> I've never felt it a problem while editing the log message in Emacs.\n>> \n>> Don't enhanced vi implementations let you split the same buffer into\n>> two allowing you to view different portions of it these days?\n>\n>   Well, maybe I could write my plugin so that it cuts the diff out from\n> the main buffer indeed, though I will have to learn using git commit -v\n> instead of git commit :P\n>\n>   That and the fact that the syntax colorization of the diff doesn't\n> work, but it's probably not up to git to fix that.\n\nOr you can use pre-commit hook (which will be run with GIT_INDEX_FILE\nset to the index file used for the commit) to generate the diff in a\nseparate file, and set EDITOR (or GIT_EDITOR) to a script around vim to\nopen the given COMMIT_EDITMSG as well as that file you create.\n"},{"id":"60889","messageId":"20071125234310.GA26458@old.davidb.org","threadId":"11013","inReplyTo":"7vfxyuj70i.fsf@gitster.siamese.dyndns.org","subject":"Re: [RFC] best way to show diff of commit","fromName":"David Brown","fromEmail":"git@davidb.org","sentAt":"2007-11-25T23:43:10Z","receivedAt":"2007-11-25T23:43:10Z","isPatch":false,"sender":{"key":"git@davidb.org","avatar":"https://gravatar.com/avatar/94c86a2938470a74c2eac5e2b69afc0871f79a660295c02219597aba8cb101c1?d=mp&s=160"},"body":"On Sun, Nov 25, 2007 at 02:27:09PM -0800, Junio C Hamano wrote:\n>Pierre Habouzit <madcoder@debian.org> writes:\n>\n>>   Hmm it doesn't because I would have to call git commit -v each time I\n>> commit and well I _like_ having the status better. And moreover I want\n>> the diff to go in a separated buffer too.\n>\n>I've never felt it a problem while editing the log message in Emacs.\n>\n>Don't enhanced vi implementations let you split the same buffer into\n>two allowing you to view different portions of it these days?\n\nYes, certainly with vim, which is what most distributions seem to include\nas the enhanced vim.  I have noticed that there seem to be fewer vim users\nthat figure out these kinds of things than emacs users, though.\n\nDave\n"},{"id":"60890","messageId":"20071125234719.GF21121@artemis.corp","threadId":"11013","inReplyTo":"7v1waej5ub.fsf@gitster.siamese.dyndns.org","subject":"Re: [RFC] best way to show diff of commit","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-25T23:47:20Z","receivedAt":"2007-11-25T23:47:20Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Sun, Nov 25, 2007 at 10:52:28PM +0000, Junio C Hamano wrote:\n> Pierre Habouzit <madcoder@debian.org> writes:\n> \n> > On Sun, Nov 25, 2007 at 10:27:09PM +0000, Junio C Hamano wrote:\n> >> Pierre Habouzit <madcoder@debian.org> writes:\n> >> \n> >> >   Hmm it doesn't because I would have to call git commit -v each time I\n> >> > commit and well I _like_ having the status better. And moreover I want\n> >> > the diff to go in a separated buffer too.\n> >> \n> >> I've never felt it a problem while editing the log message in Emacs.\n> >> \n> >> Don't enhanced vi implementations let you split the same buffer into\n> >> two allowing you to view different portions of it these days?\n> >\n> >   Well, maybe I could write my plugin so that it cuts the diff out from\n> > the main buffer indeed, though I will have to learn using git commit -v\n> > instead of git commit :P\n> >\n> >   That and the fact that the syntax colorization of the diff doesn't\n> > work, but it's probably not up to git to fix that.\n> \n> Or you can use pre-commit hook (which will be run with GIT_INDEX_FILE\n> set to the index file used for the commit) to generate the diff in a\n> separate file, and set EDITOR (or GIT_EDITOR) to a script around vim to\n> open the given COMMIT_EDITMSG as well as that file you create.\n\n  *ha* _that_ sounds more like the kind of things I was lurking for.\nSounds like a plan thanks :)\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"60892","messageId":"20071126002519.GA11133@efreet.light.src","threadId":"11013","inReplyTo":"20071125211831.GA21121@artemis.corp","subject":"Re: [RFC] best way to show diff of commit","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2007-11-26T00:25:19Z","receivedAt":"2007-11-26T00:25:19Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Sun, Nov 25, 2007 at 22:18:31 +0100, Pierre Habouzit wrote:\n>   Hi there,\n> \n>   There is specific script I run in my vim with git, that tries to show\n> from the 'status' git commit shows in the buffer which list of files has\n> changed, and builds a diff from it quite clumsily[0].\n> \n>   I wonder how hard it would be for git commit to \"stash\" the current\n> commit being sent somewhere editors would be able to have a look at (an\n> alternate index is probably fine). Note that maybe I'm stupid and\n> overlooked that such a thing already exists.  I'd like to have it in two\n> flavors: normal and amend mode. normal mode would show what the\n> resulting commit diff looks like, and the amend mode only shows the\n> incrementall diff the amend adds to the previous commit.\n\nSuch thing does already exist. When the editor is called, the index pointed\nto by GIT_INDEX_FILE (or the default index if unset) is exactly what will\nbe in the commit.\n\nHm, looking at the builtin-commit.c that is currently cooking in next, it\ndoes not seem to be the case there. It probably should, so the editor can\ninspect what will be commited.\n\n>   My question is: what do you think is the best way to do that, and\n> where ?\n\nAre you talking about the ftplugins/git.vim script from vim-scripts package,\nright?\n\nAll it needs to do is call 'git diff --cached'. The below patch seems to work\nhere (tried commit, commit -a, commit --amend, commit -a --amend and commit\nfrom subdirectory and they seemed to all work).\n\n>   [0] the issue with this approach is that it's completely broken in\n>       amending mode (does not shows the proper thing), and the generated\n\nI didn't find any issue with amending mode (showed incremental diff for me\nall right). The problem was when a file was being touched by the commit but\nwork tree had unstaged changes. Such changes were shown when they shouldn't.\n\n>       diffs aren't excellent, because as an editor plugin, it's hard to\n>       treat renames and copies easily, so I generate really really nasty\n>       diffs in that case too.\n\nWith --cached, detecting copies is just a matter of adding -C. In the patch\nbelow I added only one -C, but it should probably be user-configurable to use\nno, one or two (equivalent of --find-copies-harder).\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n\n---8<---\n--- vim-scripts/ftplugin/git.vim.orig\t2007-07-24 09:46:19.000000000 +0200\n+++ vim-scripts/ftplugin/git.vim\t2007-11-26 01:01:59.000000000 +0100\n@@ -14,41 +14,6 @@\n \"{{{ function Git_diff_windows\n \n function! Git_diff_windows(vertsplit, auto)\n-    let i = 0\n-    let list_of_files = ''\n-\n-    \" drop everything until '#  (will commit)' and the next empty line\n-    while i <= line('$')\n-        let line = getline(i)\n-        if line == '# Changes to be committed:'\n-            let i = i + 3\n-            break\n-        endif\n-\n-        let i = i + 1\n-    endwhile\n-\n-    \" read file names until we have EOF or an empty line\n-    while i <= line('$')\n-        let line = getline(i)\n-        if line =~ '^#\\s*[a-z ]*:.*->.*$'\n-            let file = substitute(line, '^#[^:]*:.*->\\s*\\(.*\\)\\s*$', '\\1', '')\n-            let list_of_files = list_of_files . ' '.file\n-            let file = substitute(line, '^#[^:]*:\\s*\\(.*\\)\\s*->.*$', '\\1', '')\n-            let list_of_files = list_of_files . ' '.file\n-        elseif line =~ '^#\\s*[a-z ]*:'\n-            let file = substitute(line, '^#[^:]*:\\s*\\(.*\\)\\s*$', '\\1', '')\n-            let list_of_files = list_of_files . ' '.file\n-        elseif line =~ '^#\\s*$'\n-            break\n-        endif\n-\n-        let i = i + 1\n-    endwhile\n-\n-    if list_of_files == \"\"\n-        return\n-    endif\n \n     if a:vertsplit\n         rightbelow vnew\n@@ -56,15 +21,8 @@\n         rightbelow new\n     endif\n     silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile\n-    let gitDir = system('git rev-parse --git-dir 2>/dev/null')\n-    let gitDir = substitute(gitDir, '.git\\n', '', '')\n-    let wd = getcwd()\n-    if gitDir != ''\n-        exe 'cd '.gitDir\n-    endif\n-    exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . \"\\n1Gdd\"\n-    exe 'normal :r!LANG=C git diff --stat HEAD -- ' . list_of_files . \"\\no\\<esc>1GddO\\<esc>\"\n-    exe 'cd '.wd\n+    exe \"normal :r!LANG=C git diff --cached -C\\n1Gdd\"\n+    exe \"normal :r!LANG=C git diff --stat --cached -C\\no\\<esc>1GddO\\<esc>\"\n     setlocal nomodifiable\n     noremap <buffer> q :bw<cr>\n     if a:auto\n"},{"id":"60916","messageId":"20071126084239.GA23373@artemis.corp","threadId":"11013","inReplyTo":"20071126002519.GA11133@efreet.light.src","subject":"Re: [RFC] best way to show diff of commit","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-26T08:42:39Z","receivedAt":"2007-11-26T08:42:39Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Mon, Nov 26, 2007 at 12:25:19AM +0000, Jan Hudec wrote:\n> On Sun, Nov 25, 2007 at 22:18:31 +0100, Pierre Habouzit wrote:\n> >   My question is: what do you think is the best way to do that, and\n> > where ?\n> \n> Are you talking about the ftplugins/git.vim script from vim-scripts package,\n> right?\n\n  Yes, its author.\n\n> All it needs to do is call 'git diff --cached'. The below patch seems to work\n> here (tried commit, commit -a, commit --amend, commit -a --amend and commit\n> from subdirectory and they seemed to all work).\n\n  Damn if that's so simple, I really feel like a big fool now.\n\n> >   [0] the issue with this approach is that it's completely broken in\n> >       amending mode (does not shows the proper thing), and the generated\n> \n> I didn't find any issue with amending mode (showed incremental diff for me\n> all right). The problem was when a file was being touched by the commit but\n> work tree had unstaged changes. Such changes were shown when they shouldn't.\n\n  Yep, that's the point.\n\n> >       diffs aren't excellent, because as an editor plugin, it's hard to\n> >       treat renames and copies easily, so I generate really really nasty\n> >       diffs in that case too.\n> \n> With --cached, detecting copies is just a matter of adding -C. In the patch\n> below I added only one -C, but it should probably be user-configurable to use\n> no, one or two (equivalent of --find-copies-harder).\n\n  Sure, I'll do that obviously.\n\n  Thanks a lot for the tip.\n> \n> -- \n> \t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n> \n> ---8<---\n> --- vim-scripts/ftplugin/git.vim.orig\t2007-07-24 09:46:19.000000000 +0200\n> +++ vim-scripts/ftplugin/git.vim\t2007-11-26 01:01:59.000000000 +0100\n> @@ -14,41 +14,6 @@\n>  \"{{{ function Git_diff_windows\n>  \n>  function! Git_diff_windows(vertsplit, auto)\n> -    let i = 0\n> -    let list_of_files = ''\n> -\n> -    \" drop everything until '#  (will commit)' and the next empty line\n> -    while i <= line('$')\n> -        let line = getline(i)\n> -        if line == '# Changes to be committed:'\n> -            let i = i + 3\n> -            break\n> -        endif\n> -\n> -        let i = i + 1\n> -    endwhile\n> -\n> -    \" read file names until we have EOF or an empty line\n> -    while i <= line('$')\n> -        let line = getline(i)\n> -        if line =~ '^#\\s*[a-z ]*:.*->.*$'\n> -            let file = substitute(line, '^#[^:]*:.*->\\s*\\(.*\\)\\s*$', '\\1', '')\n> -            let list_of_files = list_of_files . ' '.file\n> -            let file = substitute(line, '^#[^:]*:\\s*\\(.*\\)\\s*->.*$', '\\1', '')\n> -            let list_of_files = list_of_files . ' '.file\n> -        elseif line =~ '^#\\s*[a-z ]*:'\n> -            let file = substitute(line, '^#[^:]*:\\s*\\(.*\\)\\s*$', '\\1', '')\n> -            let list_of_files = list_of_files . ' '.file\n> -        elseif line =~ '^#\\s*$'\n> -            break\n> -        endif\n> -\n> -        let i = i + 1\n> -    endwhile\n> -\n> -    if list_of_files == \"\"\n> -        return\n> -    endif\n>  \n>      if a:vertsplit\n>          rightbelow vnew\n> @@ -56,15 +21,8 @@\n>          rightbelow new\n>      endif\n>      silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile\n> -    let gitDir = system('git rev-parse --git-dir 2>/dev/null')\n> -    let gitDir = substitute(gitDir, '.git\\n', '', '')\n> -    let wd = getcwd()\n> -    if gitDir != ''\n> -        exe 'cd '.gitDir\n> -    endif\n> -    exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . \"\\n1Gdd\"\n> -    exe 'normal :r!LANG=C git diff --stat HEAD -- ' . list_of_files . \"\\no\\<esc>1GddO\\<esc>\"\n> -    exe 'cd '.wd\n> +    exe \"normal :r!LANG=C git diff --cached -C\\n1Gdd\"\n> +    exe \"normal :r!LANG=C git diff --stat --cached -C\\no\\<esc>1GddO\\<esc>\"\n>      setlocal nomodifiable\n>      noremap <buffer> q :bw<cr>\n>      if a:auto\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"60917","messageId":"20071126084731.GB23373@artemis.corp","threadId":"11013","inReplyTo":"20071126002519.GA11133@efreet.light.src","subject":"Re: [RFC] best way to show diff of commit","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-26T08:47:31Z","receivedAt":"2007-11-26T08:47:31Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Mon, Nov 26, 2007 at 12:25:19AM +0000, Jan Hudec wrote:\n> Hm, looking at the builtin-commit.c that is currently cooking in next, it\n> does not seem to be the case there. It probably should, so the editor can\n> inspect what will be commited.\n\n  I confirm that it's broken now, but that it works at the top of main.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"60919","messageId":"20071126085927.GC23373@artemis.corp","threadId":"11013","inReplyTo":"20071126084731.GB23373@artemis.corp","subject":"[PATCH] Make builtin-commit.c export GIT_INDEX_FILE for launch_editor as well.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-26T08:59:27Z","receivedAt":"2007-11-26T08:59:27Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n\n  And here's the fix for this tiny problem …\n\n\n\n builtin-commit.c |    9 ++++++---\n builtin-tag.c    |    6 +++---\n strbuf.h         |    2 +-\n 3 files changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 5d27102..6e6b9f2 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -748,9 +748,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \n \t/* Get the commit message and validate it */\n \theader_len = sb.len;\n-\tif (!no_edit)\n-\t\tlaunch_editor(git_path(commit_editmsg), &sb);\n-\telse if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {\n+\tif (!no_edit) {\n+\t\tchar index[PATH_MAX];\n+\t\tconst char *env[2] = { index, NULL };\n+\t\tsnprintf(index, sizeof(index), \"GIT_INDEX_FILE=%s\", index_file);\n+\t\tlaunch_editor(git_path(commit_editmsg), &sb, env);\n+\t} else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {\n \t\trollback_index_files();\n \t\tdie(\"could not read commit message\\n\");\n \t}\ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex e89b201..8cc7f9c 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -23,7 +23,7 @@ static const char * const git_tag_usage[] = {\n \n static char signingkey[1000];\n \n-void launch_editor(const char *path, struct strbuf *buffer)\n+void launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n {\n \tconst char *editor, *terminal;\n \n@@ -49,7 +49,7 @@ void launch_editor(const char *path, struct strbuf *buffer)\n \tif (strcmp(editor, \":\")) {\n \t\tconst char *args[] = { editor, path, NULL };\n \n-\t\tif (run_command_v_opt(args, 0))\n+\t\tif (run_command_v_opt_cd_env(args, 0, NULL, env))\n \t\t\tdie(\"There was a problem with the editor %s.\", editor);\n \t}\n \n@@ -318,7 +318,7 @@ static void create_tag(const unsigned char *object, const char *tag,\n \t\t\twrite_or_die(fd, tag_template, strlen(tag_template));\n \t\tclose(fd);\n \n-\t\tlaunch_editor(path, buf);\n+\t\tlaunch_editor(path, buf, NULL);\n \n \t\tunlink(path);\n \t\tfree(path);\ndiff --git a/strbuf.h b/strbuf.h\nindex 8334a9b..36d61db 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -117,6 +117,6 @@ extern int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint);\n extern int strbuf_getline(struct strbuf *, FILE *, int);\n \n extern void stripspace(struct strbuf *buf, int skip_comments);\n-extern void launch_editor(const char *path, struct strbuf *buffer);\n+extern void launch_editor(const char *path, struct strbuf *buffer, const char *const *env);\n \n #endif /* STRBUF_H */\n-- \n1.5.3.6.2015.g9baba-dirty\n\n"},{"id":"60924","messageId":"20071126093851.GA30655@artemis.corp","threadId":"11013","inReplyTo":"20071126085927.GC23373@artemis.corp","subject":"Re: [PATCH] Make builtin-commit.c export GIT_INDEX_FILE for launch_editor as well.","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-26T09:38:51Z","receivedAt":"2007-11-26T09:38:51Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"  and here's the updated git.vim:\nhttp://www.vim.org/scripts/script.php?script_id=1934\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"60940","messageId":"1196090850.2875.13.camel@hinata.boston.redhat.com","threadId":"11013","inReplyTo":"20071126085927.GC23373@artemis.corp","subject":"Re: [PATCH] Make builtin-commit.c export GIT_INDEX_FILE for launch_editor as well.","fromName":"Kristian Høgsberg","fromEmail":"krh@redhat.com","sentAt":"2007-11-26T15:27:30Z","receivedAt":"2007-11-26T15:27:30Z","isPatch":true,"sender":{"key":"krh@redhat.com","avatar":"https://gravatar.com/avatar/763dee6f9594ac474f725b137a39565792928e583ddf59b32befc2907409027e?d=mp&s=160"},"body":"On Mon, 2007-11-26 at 09:59 +0100, Pierre Habouzit wrote:\n> Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n> ---\n> \n>   And here's the fix for this tiny problem …\n\nThat looks good to me.\n\nSigned-off-by: Kristian Høgsberg <krh@redhat.com>\n\n> \n> \n>  builtin-commit.c |    9 ++++++---\n>  builtin-tag.c    |    6 +++---\n>  strbuf.h         |    2 +-\n>  3 files changed, 10 insertions(+), 7 deletions(-)\n> \n> diff --git a/builtin-commit.c b/builtin-commit.c\n> index 5d27102..6e6b9f2 100644\n> --- a/builtin-commit.c\n> +++ b/builtin-commit.c\n> @@ -748,9 +748,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n>  \n>  \t/* Get the commit message and validate it */\n>  \theader_len = sb.len;\n> -\tif (!no_edit)\n> -\t\tlaunch_editor(git_path(commit_editmsg), &sb);\n> -\telse if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {\n> +\tif (!no_edit) {\n> +\t\tchar index[PATH_MAX];\n> +\t\tconst char *env[2] = { index, NULL };\n> +\t\tsnprintf(index, sizeof(index), \"GIT_INDEX_FILE=%s\", index_file);\n> +\t\tlaunch_editor(git_path(commit_editmsg), &sb, env);\n> +\t} else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {\n>  \t\trollback_index_files();\n>  \t\tdie(\"could not read commit message\\n\");\n>  \t}\n> diff --git a/builtin-tag.c b/builtin-tag.c\n> index e89b201..8cc7f9c 100644\n> --- a/builtin-tag.c\n> +++ b/builtin-tag.c\n> @@ -23,7 +23,7 @@ static const char * const git_tag_usage[] = {\n>  \n>  static char signingkey[1000];\n>  \n> -void launch_editor(const char *path, struct strbuf *buffer)\n> +void launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n>  {\n>  \tconst char *editor, *terminal;\n>  \n> @@ -49,7 +49,7 @@ void launch_editor(const char *path, struct strbuf *buffer)\n>  \tif (strcmp(editor, \":\")) {\n>  \t\tconst char *args[] = { editor, path, NULL };\n>  \n> -\t\tif (run_command_v_opt(args, 0))\n> +\t\tif (run_command_v_opt_cd_env(args, 0, NULL, env))\n>  \t\t\tdie(\"There was a problem with the editor %s.\", editor);\n>  \t}\n>  \n> @@ -318,7 +318,7 @@ static void create_tag(const unsigned char *object, const char *tag,\n>  \t\t\twrite_or_die(fd, tag_template, strlen(tag_template));\n>  \t\tclose(fd);\n>  \n> -\t\tlaunch_editor(path, buf);\n> +\t\tlaunch_editor(path, buf, NULL);\n>  \n>  \t\tunlink(path);\n>  \t\tfree(path);\n> diff --git a/strbuf.h b/strbuf.h\n> index 8334a9b..36d61db 100644\n> --- a/strbuf.h\n> +++ b/strbuf.h\n> @@ -117,6 +117,6 @@ extern int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint);\n>  extern int strbuf_getline(struct strbuf *, FILE *, int);\n>  \n>  extern void stripspace(struct strbuf *buf, int skip_comments);\n> -extern void launch_editor(const char *path, struct strbuf *buffer);\n> +extern void launch_editor(const char *path, struct strbuf *buffer, const char *const *env);\n>  \n>  #endif /* STRBUF_H */\n"}]}