How to find a git commit branch enabled? (Using libgit2sharp)

As part of a research project, I'm trying to replicate a graph representation in version control software such as SourceTree or TortoiseGit.

The graphical representation I'm trying to implement The graph view I'm trying to implement

The biggest problem I am facing is finding which branch the commit belongs to. If I have this, I can assign a fix point to the column and color. This is complicated because under the hood, Git does not store the branch in which the commit was committed.

Looking at other solutions in StackOverflow, I found that I could get a list of branches containing a commit, but I needed a method for selecting one that would appear on my graph. In the same way, SourceTree or TortoiseGit somehow manages to do this.

My problem is also identical to this. Find out the branch to which the commit in LibGit2Sharp belongs?

Looks like they found the actual solution in a private discussion room. However, I do not have a reputation to comment and ask what they found.

Does anyone have any ideas on how I can do this?

Or, @nulltoken, if by chance you see this and remember, do you know what you guys found in this discussion room?

+6
source share
2 answers

It turns out that to generate the SourceTree graph, you don’t need to know which branch the commit is in.

The first commit in a graph always has a column of 0. In addition, you can get a list of the parent commits of this commit. Starting from the first commit and repeating it in the opposite direction, they can generate a beautiful graph using only this information.

0
source

Not sure how helpful this answer would be. The equivalent LibGit2Sharp call for " git branch --contains $SHA1 " is the requested function on GitHub open !

Once upon a time, I used a query to all links, like this one , but for your use case it might be too slow.

I tried to come up with possible ways to mitigate this problem; I could not come up with a single guiding light. :( And then I found this comment stating that you need to go through the DAG and check the actual branch in which there is a commit. All of this hints that you will need to use a slow traversal approach for all links.

+2
source

Source: https://habr.com/ru/post/1273334/


All Articles