rbong / vim-flog

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

View git log graph only for changes to a subdirectory #47

Closed TamaMcGlinn closed 3 years ago

TamaMcGlinn commented 3 years ago

I would like to open vim-flog populated with a graph of only the changes to a particular subdirectory.

In GitExtensions, the File Browser allows this by right clicking a directory and choosing "View history".

The idea is to make a graph which omits all commits that did not change anything inside the directory desired, but carries through all the usual lines as if those commits simply didn't exist. With vim-fugitive, you can do :Git log -- some/dir to get the right commits, but I would like to open a vim-flog graph with all the usual keybindings instead, and to be able to do this through a keybinding while browsing a tree object representing that directory.

I use this workflow all the time when I am searching for a particular commit. Often, I next want to go back to the full commit graph, but with the cursor remaining on the same commit, so that I can see it in context (which branch was it on? was it subsequently reverted? etc.)

rbong commented 3 years ago

You can do this currently when :Flog -path=path/to/dir. You can also view history just for the directory by opening the diff view with <tab> instead of <enter>.

Give it a try and let me know if there's anything it's lacking.

TamaMcGlinn commented 3 years ago

Wow, great! That is what I was looking for. Here are a couple of ways that you come to a directory, and each should have it's own way of turning that into a mapping to Flog (I don't want to type the path explicitly):

1) when examining a tree in fugitive, by pressing enter on the line starting with tree 863116a08e15ad03bedb996790138a1b43f5e999 I can browse from the root down directories into the one I am interested in. Presumably I can nose around fugitive and find a function for 'get current tree' and then 'get directory given tree hash'.

2) the directory of the current buffer's file; sometimes, I would also want X levels up, so that I get both the src/ and include/ of a project, but perhaps that should be done via the file browser.

3) the NetRW file browser is also an obvious one where you are looking at a current directory.

TamaMcGlinn commented 3 years ago

Unfortunately, there's a pretty important bug in this; vim-flog shows the branches only if the commit on the tip of that branch itself touches the directory. That means that in a large repository with changes made all over the place, you might see absolutely no branches displayed, when examining the history of a directory, and hence it is impossible to tell which commits are on which branches. Instead, I would expect each branch to be displayed on the latest commit in the current graph that is in the branch.

rbong commented 3 years ago

Sorry about that, I think I know what's going on. Will try to get a fix up soon.

rbong commented 3 years ago

Should be fixed.

TamaMcGlinn commented 3 years ago

You mean with '[4093a18] {rbong} Fix complete_ref > complete_rev' ? It doesn't fix the issue, you seem to have just renamed a function.

rbong commented 3 years ago

I also pushed https://github.com/rbong/vim-flog/commit/e27ba0227caf983c169e0575cec979fa77d28f6e which fixes the issue

TamaMcGlinn commented 3 years ago

No, I don't use that mapping; the bug happens from just running :Flog -path=X, nothing else is needed.

TamaMcGlinn commented 3 years ago

Here's an example asciicast; given the smallish repository of Alire, compare :Flog with :Flog -path=doc. The latter claims that the master branch does not exist.

rbong commented 3 years ago

Sorry, I didn't read your original post closely enough. I had a superficially similar bug sometimes so I assumed it was the same issue. Didn't have much time to look into it. My mistake.

Flog just shows the output of git log right now. Unless if there's an option in git log to show which branches a commit is an ancestor of, as long as no commits above are ancestors, I don't know if there's a way to do this. I don't think there is such an option. Please let me know if I'm wrong.

rbong commented 3 years ago

I did a quick search of the git-log manual before to see if there is anything that can help with this, but I am doing a deep dive now - I found the format specifier %S. It doesn't exactly do what you want, but it can help in certain cases. From the git-log manual:

%S ref name given on the command line by which the commit was reached (like git log --source), only works with git log

So in the case of -all, this will show the branch name(s?) that the commit was reached by... however, without -all, it will just show HEAD, since git reached all of those commits via the head.

You can enable it this way. This format is approximately equivalent to the default format specifier with %S added.

Flog -format=%ad\ [%h]\ {%an}%d\ (%S)\ %s -path=foo -all
TamaMcGlinn commented 3 years ago

That's close enough that I will be using that in my mapping until a better answer comes along on stackoverflow. Thanks a lot!

rbong commented 3 years ago

I am going to close this for now, since I don't believe there would be a better option even if we were building commit history ourselves because of optimization issues.