comparison plugin/lawrencium.vim @ 51:671f5e18b515

Added "diff summary" commands to use `hg diff` instead of Vim's diff. Added documenation for the new commands. Got rid of the useless hard-coded revision numbers.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 10 Nov 2012 11:17:34 -0800
parents dffb41c2067c
children cd0b1cea326c
comparison
equal deleted inserted replaced
50:b484fe88c500 51:671f5e18b515
672 " }}} 672 " }}}
673 673
674 " Hgdiff {{{ 674 " Hgdiff {{{
675 675
676 function! s:HgDiff(filename, vertical, ...) abort 676 function! s:HgDiff(filename, vertical, ...) abort
677 " Default revisions to diff: the working directory (special Lawrencium 677 " Default revisions to diff: the working directory (null string)
678 " hard-coded syntax) and the parent of the working directory (using 678 " and the parent of the working directory (using Mercurial's revsets syntax).
679 " Mercurial's revsets syntax). 679 let l:rev1 = ''
680 let l:rev1 = 'lawrencium#_wdir_'
681 let l:rev2 = 'p1()' 680 let l:rev2 = 'p1()'
682 if a:0 == 1 681 if a:0 == 1
683 let l:rev2 = a:1 682 let l:rev2 = a:1
684 elseif a:0 == 2 683 elseif a:0 == 2
685 let l:rev1 = a:1 684 let l:rev1 = a:1
695 " We'll keep a list of buffers in this diff, so when one exits, the 694 " We'll keep a list of buffers in this diff, so when one exits, the
696 " others' 'diff' flag is turned off. 695 " others' 'diff' flag is turned off.
697 let l:diff_buffers = [] 696 let l:diff_buffers = []
698 697
699 " Get the first file and open it. 698 " Get the first file and open it.
700 if l:rev1 == 'lawrencium#_wdir_' 699 if l:rev1 == ''
701 if bufexists(l:path) 700 if bufexists(l:path)
702 execute 'buffer ' . fnameescape(l:path) 701 execute 'buffer ' . fnameescape(l:path)
703 else 702 else
704 execute 'edit ' . fnameescape(l:path) 703 execute 'edit ' . fnameescape(l:path)
705 endif 704 endif
722 " Get the second file and open it too. 721 " Get the second file and open it too.
723 let l:diffsplit = 'diffsplit' 722 let l:diffsplit = 'diffsplit'
724 if a:vertical 723 if a:vertical
725 let l:diffsplit = 'vertical diffsplit' 724 let l:diffsplit = 'vertical diffsplit'
726 endif 725 endif
727 if l:rev2 == 'lawrencium#_wdir_' 726 if l:rev2 == ''
728 execute l:diffsplit . ' ' . fnameescape(l:path) 727 execute l:diffsplit . ' ' . fnameescape(l:path)
729 else 728 else
730 let l:temp_file = tempname() 729 let l:temp_file = tempname()
731 call l:repo.RunCommand('cat', '-r', '"'.l:rev2.'"', '-o', '"'.l:temp_file.'"', '"'.l:path.'"') 730 call l:repo.RunCommand('cat', '-r', '"'.l:rev2.'"', '-o', '"'.l:temp_file.'"', '"'.l:path.'"')
732 execute l:diffsplit . ' ' . fnameescape(l:temp_file) 731 execute l:diffsplit . ' ' . fnameescape(l:temp_file)
811 autocmd BufWinLeave * call s:HgDiff_CleanUp() 810 autocmd BufWinLeave * call s:HgDiff_CleanUp()
812 augroup end 811 augroup end
813 812
814 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiff :call s:HgDiff('%:p', 0, <f-args>)") 813 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiff :call s:HgDiff('%:p', 0, <f-args>)")
815 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvdiff :call s:HgDiff('%:p', 1, <f-args>)") 814 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvdiff :call s:HgDiff('%:p', 1, <f-args>)")
815
816 " }}}
817
818 " HgdiffSummary {{{
819
820 function! s:HgDiffSummary(split, filename, ...) abort
821 " Default revisions to diff: the working directory (null string)
822 " and the parent of the working directory (using Mercurial's revsets syntax).
823 let l:revs = ''
824 if a:0 == 1
825 let l:revs = a:1
826 elseif a:0 >= 2
827 let l:revs = a:1 . ',' . a:2
828 endif
829
830 " Get the current repo, and expand the given filename in case it contains
831 " fancy filename modifiers.
832 let l:repo = s:hg_repo()
833 let l:path = expand(a:filename)
834 call s:trace("Diff'ing revisions: '".l:revs."' on file: ".l:path)
835 let l:special = l:repo.GetLawrenciumPath(l:path, 'diff', l:revs)
836 if a:split == 1
837 split
838 elseif a:split == 2
839 vsplit
840 endif
841 execute 'edit ' . l:special
842 " Open all folds by default.
843 " TODO: maybe set `nofoldenable` instead?
844 %foldopen!
845 endfunction
846
847 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiffsum :call s:HgDiffSummary(0, '%:p', <f-args>)")
848 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiffsumsplit :call s:HgDiffSummary(1, '%:p', <f-args>)")
849 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvdiffsumsplit :call s:HgDiffSummary(2, '%:p', <f-args>)")
816 850
817 " }}} 851 " }}}
818 852
819 " Hgcommit {{{ 853 " Hgcommit {{{
820 854
1113 elseif l:rev2 == '-' 1147 elseif l:rev2 == '-'
1114 call l:repo.ReadCommandOutput('diff', '-r', l:rev1, l:comps['path']) 1148 call l:repo.ReadCommandOutput('diff', '-r', l:rev1, l:comps['path'])
1115 else 1149 else
1116 call l:repo.ReadCommandOutput('diff', '-r', l:rev1, '-r', l:rev2, l:comps['path']) 1150 call l:repo.ReadCommandOutput('diff', '-r', l:rev1, '-r', l:rev2, l:comps['path'])
1117 endif 1151 endif
1152 elseif l:comps['value'] != ''
1153 call l:repo.ReadCommandOutput('diff', '-c', l:comps['value'], l:comps['path'])
1118 else 1154 else
1119 call l:repo.ReadCommandOutput('diff', '-c', l:comps['value'], l:comps['path']) 1155 call l:repo.ReadCommandOutput('diff', l:comps['path'])
1120 endif 1156 endif
1121 setlocal filetype=diff 1157 setlocal filetype=diff
1122 endif 1158 endif
1123 1159
1124 setlocal readonly 1160 setlocal readonly