sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
4.02k stars 111 forks source link

More informative bufname in diffview (feat. git conflict) #248

Closed wookayin closed 1 year ago

wookayin commented 1 year ago

Hi, thanks for the awesome plugin! It would be great if we can improve the bufname of diffview buffers.

Currently, bufname for diffview buffers would look like:

diffview:///PATH_TO_GIT_REPO/.git/:2:/file.txt
diffview:///PATH_TO_GIT_REPO/.git/:3:/file.txt

Here :2:, :3: would have no meaning other than internal identifiers. I think we can improve to make them to include more information like SHA-1 hash, or contextual information (e.g., ours, theirs in git conflicts) look like:

diffview:///PATH_TO_GIT_REPO/.git//06e1730047286ecd622e9ae0ca5e131d00012119/file.txt
diffview:///PATH_TO_GIT_REPO/.git//da0dd2e2574e26581241a34d1a0055fb61dafbc3/file.txt

or

diffview:///PATH_TO_GIT_REPO/.git/ours/...SHA1.../file.txt
diffview:///PATH_TO_GIT_REPO/.git/theirs/...SHA1.../file.txt

Motivation: For example, in the following 3-way diff:

diffview conflict

I am often confused whether the revision shown either in the left or right is ours or theirs. Per convention and :help diffview-conflict-versions, the left seems to be ours and the right seems to be theirs (I'm using the diff3_vertical layout). But it'd be nice this can be easily told from the buffer names.

This also applies to in normal diffview mode (no conflicts). In contrast, fugitive has some nice bufname when looking at diff, for instance:

fugitive:///PATH_TO_GIT_REPO/.git//a0787afc2c18cad74d4b45466346095f4...../file.txt
sindrets commented 1 year ago

:[0-3] are not just arbitrary internal identifiers. These are stage numbers in git. Stage 0 refers to the changes currently in the index (things you're about to commit). During a merge or rebase, the stage numbers 1-3 refer to the following versions of a file:

Diffview uses stage numbers to describe git objects when it's appropriate. Otherwise the commit SHA is used. Fugitive does this very similarly. It also uses stage numbers when showing 3-way diffs during a merge.

I understand that it can be a bit frustrating at first remembering what version of a file is displayed on what side during a conflict. But like you've pointed out, diffview is following the convention here (it's the same layout as in vimdiff and several IDE's). Look to the diagrams under :h diffview-conflict-versions when you get confused, and then I believe it shouldn't take too long to get used to the layout.

sindrets commented 1 year ago

Closing due to no follow-up from OP.