rbong / vim-flog

A blazingly fast, stunningly beautiful, exceptionally powerful git branch viewer for Vim/Neovim.
750 stars 22 forks source link

Upgrading from v1 to v2 #105

Closed TamaMcGlinn closed 1 year ago

TamaMcGlinn commented 1 year ago

I'm finally getting around to updating my flog based plugins to v2, and encountering some function renames not mentioned in the migration guide. In case it helps anyone else, and since #91 is locked, I will list them here as I find the replacements.

flog#previous_commit() is now flog#floggraph#nav#PrevCommit()
flog#next_commit() is now flog#floggraph#nav#NextCommit()
flog#get_initial_workdir() is now flog#state#GetWorkdir(flog#state#GetBufState())
flog#get_commit_at_line() is now flog#floggraph#commit#GetAtLine(...)
flog#get_fugitive_git_dir() is gone, use FugitiveGitDir()
flog#get_status_summary() is gone, use b:flog_status_summary, trigger refresh with flog#floggraph#buf#UpdateStatus()
flog#get_commit_selection() is gone, see similar flog#cmd#floggit#args#CompleteContext()
flog#populate_graph_buffer() is now flog#floggraph#buf#Update()
flog#get_state() is now flog#state#GetBufState()
flog#next_ref() is now flog#floggraph#nav#NextRefCommit()
flog#previous_ref() is now flog#floggraph#nav#PrevRefCommit()

As a sidenote; The migration guide says "Please see ftplugin/floggraph.vim for updated examples" but the link is broken because of deleting the dev branch.

TamaMcGlinn commented 1 year ago

Flogjump is gone; the deprecation message says to use / or ? but this is something totally different, as that does a search rather than jumping to the line of the git ref. For cases where you were passing the hash anyway, you can use flog#floggraph#nav#JumpToCommit(hash) but to resolve it if necessary, you need to some magic with e.g. system() and flog#fugitive#GetGitCommand(). For example, if you used :Flogjump HEAD previously, that would now be call flog#floggraph#nav#JumpToCommit(systemlist(flog#fugitive#GetGitCommand() . " rev-parse HEAD")[0][0:6]). You have to call git rev-parse in the right directory, then truncate to 6 characters, and pass that to JumpToCommit.

TamaMcGlinn commented 1 year ago

~While trying to replace calls to flog#run_tmp_command, the help for ExecTmp claims that focus and static would be optional, but they are not:~ edit: fixed in 6f0c17d.

I am having some trouble figuring out how to migrate my visual mode diff mappings to the new function:

autocmd FileType floggraph vno <buffer> D :<C-U>call flog#run_tmp_command("below Git diff %(h'>) %(h'<)")<CR>

If I just replace with ExecTmp(..., v:true, v:true) it opens an empty split with no diff shown. Could you link to one of your new similar mappings so I can take inspiration from that? That one lets me visually select from one to another commit and show the diff between them.

rbong commented 1 year ago

I will list them here

Thanks for the list.

the link is broken

Thanks, fixed. The wiki should be completely open to edits I believe by the way, let me know if I'm wrong.

Flogjump is gone

The big issue with Flogjump is that completion was just way too expensive. It's limited to just refs in the current draw area. There's a smarter way to do completion, I can't remember if I tested whether it's viable yet, but I thought it just wasn't that important to keep. Let me know if you really want this command back and I'll do some tests.

ExecTmp claims that focus and static would be optional, but they are not

Sorry this got mangled when switching back to legacy vimscript. Should be fixed.

having some trouble figuring out how to migrate my visual mode diff

I can give an example for the mapping you shared:

autocmd FileType floggraph vno <buffer> D :<C-U>call flog#run_tmp_command("below Git diff %(h'>) %(h'<)")<CR>

There are a couple ways to do this, first is:

autocmd FileType floggraph vno <buffer> D :<C-U>call flog#ExecTmp(flog#Format("below Git diff %(h'>) %(h'<)"), 0, 1)<CR>

Main things of note here are:

But you don't actually usually need to call flog#ExecTmp directly, most of my commands now look like this:

autocmd FileType floggraph vno <buffer> D :<C-U>exec flog#Format("below Floggit -s -t diff %(h'>) %(h'<)")<CR>

Note that this is using Floggit instead of flog#ExecTmp. Any time you're using call flog#Exec* with Git, you can also just use exec flog#Format with Floggit.

The -s option tells Floggit that the command is static, just like the third option to flog#ExecTmp.

The -t option tells Floggit that the command should open in a temp window, which is the same as using flog#ExecTmp instead of flog#Exec.

Hope that helps. Sorry for the delay, let me know if there are any more problems migrating.

TamaMcGlinn commented 1 year ago

Wow. I am blown away by the quick and comprehensive answer and fixes. Thanks so much!

I'm not sure about the need for FlogJump inside flog; I have my workaround in place now, and I guess people will find it in the comment above if they go looking. Personally I never used FlogJump apart from this one mapping to jump to the HEAD, so I won't miss it.