rbong / vim-flog

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

wrong graph #96

Closed 4volodin closed 1 year ago

4volodin commented 1 year ago

repository https://github.com/veevidify/laravel-apache-docker.git There is a wrong graph between • │ 2020-03-10 20:40:54 +1100 [d692de9] {V Ng} Merge pull request #5 from veevidify/dependabot/composer/symfony/http-foundation-4.4.1 ├─┤ <----- HERE IS AN ISSUE • │ 2019-12-03 19:56:12 +0000 [20ab97e] {dependabot[bot]} Build(deps): bump symfony/http-foundation from 4.2.5 to 4.4.1

more info here:

• 2020-03-10 20:53:52 +1100 [c058737] {V Ng} Merge pull request #6 from HonkingGoose/patch-1 ├─╮ │ • 2020-02-16 15:10:15 +0100 [4b84270] {HonkingGoose} Update dockerfile with best practices • │ 2020-03-10 20:49:14 +1100 [c585e47] {V Ng} (origin/laravel-5) Merge remote-tracking branch 'origin/dependabot/composer/symfony/http-foundation-4.4.5' ├─┊─╮ │ │ • 2020-03-10 09:42:00 +0000 [c68fa1f] {dependabot[bot]} Build(deps): bump symfony/http-foundation from 4.2.5 to 4.4.5 │ ├─╯ • │ 2020-03-10 20:40:54 +1100 [d692de9] {V Ng} Merge pull request #5 from veevidify/dependabot/composer/symfony/http-foundation-4.4.1 ├─┤ • │ 2019-12-03 19:56:12 +0000 [20ab97e] {dependabot[bot]} Build(deps): bump symfony/http-foundation from 4.2.5 to 4.4.1 ├─╯ • 2019-11-19 15:59:25 +1100 [352719a] {V Ng} Merge pull request #3 from samnockels/patch-1 ├─╮ │ • 2019-09-04 09:44:18 +0100 [4f42f53] {Sam Nockels} Update readme.md, to add .env file ├─╯

rbong commented 1 year ago

It's not wrong, or even ambiguous once you know how to read it. Let me explain the differences in the graph.

Here's how git log --graph --format='[%h] parents: %p' looks:

| * [4b84270] parents: 352719a
* |   [c585e47] parents: d692de9 c68fa1f
|\ \  
| * | [c68fa1f] parents: 352719a
| |/  
* |   [d692de9] parents: 352719a 20ab97e
|\ \  
| |/  
|/|   
| * [20ab97e] parents: 352719a
|/  
*   [352719a] parents: 8f8d246 4f42f53

Let's simplify this a bit to make it easier to read:

| A   parents: F
B |   parents: D C
|\ \  
| C | parents: F
| |/  
D |   parents: F E
|\ \  
| |/  
|/|   
| E   parents: F
|/  
F

Here's that same branch structure in Flog:

│ A   parents: F
B │   parents: D C
├─┊─╮
│ │ C parents: F
│ ├─╯
D │   parents: F E
├─┤
E │   parents: F
├─╯
F

So let me explain the differences. First, let's untangle C by moving it to the right:

| A   parents: F
B |   parents: D C
|-┊-. 
| | C parents: F
| |-' 
D |   parents: F E
|\ \  
| |/  
|/|   
| E   parents: F
|/  
F

Much better. Now, let's untangle E by moving it to the left:

| A   parents: F
B |   parents: D C
|-┊-. 
| | C parents: F
| |-' 
D |   parents: F E
|\|
| |   
E |   parents: F
| |   
|/
F

Now instead of using slashes, let's use straight characters like in Flog:

| A   parents: F
B |   parents: D C
|-┊-. 
| | C parents: F
| |-' 
D |   parents: F E
|-|
E |   parents: F
|-'   
F

Now compare Flog's output again:

│ A   parents: F
B │   parents: D C
├─┊─╮
│ │ C parents: F
│ ├─╯
D │   parents: F E
├─┤
E │   parents: F
├─╯
F

It's the same. If you check the parents of every commit in every diagram I've posted, you'll see that every branch is connected to its parents, and the parents are all correct.

Flog prioritizes using straight lines to avoid the tangle of git log --graph. The downside is that we lose the directionality of slashes, but all the information you need to read the graph is still in there.

You have to read branches using this knowledge:

1) A commit before a merge always means that the parent branches in the merge are being merged into that commit. It does not mean that all parent branches in the merge are being merged into eachother. 2) A commit with more than one parent will always have a merge before it that shows how many unique parents it has. 3) Branches will continue down straight whenever possible.

Let's read the structure using this knowledge:

│ A
D │
├─┤
E │
├─╯
F

Read this as: F and E are merged into D; also, A has a single parent, which is F.

This never means that both E and F are parents of A.

Let's break this down using our three points:

1) D has a merge with two parent branches (├─┤), so that means the branch on the right (F) is being merged with the other branch (E) into D. It does not mean E is being merged into F, because F is not the commit on the previous line. 2) There is a single branch below A (), so it has one parent (F). 3) Since Flog prioritizes straight lines, A's single parent continues straight down past D, and we can see it eventually ends at F, so we know F is its only parent.

If both E and F were parents of A, here's how it would look instead:

│ A   parents: E F
│ ├─╮
D │ │ parents: E F
╰─┼─┤
  E │
    F

Let's figure out the branch structure again based on the same ideas:

1) D has a merge with two parent branches (╰─┼─┤), so that means the two branches are being merged (E and F into D). Again, it does not mean E is being merged into F or vice versa. 2) This time there is also a merge below A (├─╮) and we can see it has two parents (E and F). 3) The parents E and F of A continue straight down past D. If there were other commits inbetween, it would continue straight past them.

Caveats:

If you have any questions, or if you can find an ambiguous case, please provide an example and I will reopen.

rbong commented 1 year ago

Actually, let me expand: in the last case, Flog will try to help you understand the structure of the graph by at least showing the direction of merges of commits caught in the middle of the graph:

│ A   parents: E F
│ ├─╮
D │ │ parents: E F
╰┬┊─┤
 ╰┤ │
  E │
    F

So really the problem is that we lack the characters to show the direction of merges for the leftmost and rightmost branches.

kdheepak commented 2 months ago

This is a difficult problem to solve given that there are no box drawing unicode characters that can appropriately solve this. I appreciate all the efforts to make the graph performant and still readable.

fwiw, I understand how I'm supposed to read it but I still find myself getting confused every now and then. I'm wondering if it is possible to make use of to decrease ambiguity.

Consider this:

 │
─┤

versus:

 │
─⎨

It's not as elegant but atleast signals the difference more clearly?

kdheepak commented 2 months ago

Or something like this:

│ A
D │
├─┪
E │
├─╯
F
rbong commented 2 months ago

I plan to have optional custom expanded unicode characters in the graph to solve this issue soon. I probably won't touch the default box characters.