Skip to content

Is there a way of getting the latest commit for a file on a specific branch. #943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
busyLambda opened this issue Apr 2, 2023 · 1 comment

Comments

@busyLambda
Copy link

#588 is a simmilar issue to this one but it just requests a way to get the latest commit but i want to get the latest commit for a specific branch. I already know that revwalk is the way to go but i don't really have other ideas.

@Some1and2-XC
Copy link

This seems like more of an implementation issue than a library issue.

This being said here is how I would approach this.

  1. Get the newest commit.
  2. Look for the file through the trees and find the OID (the sha1 hash of the file)
  3. Go to the previous commit
  4. Find the file again
  5. See if the OID changed
  6. Repeat 3,4 and 5 until the file doesn't exist or the OID is different.
  7. Profit?

Because trees also have OIDs you can also do some caching to get some okay performance but this algorithm isn't very intensive.
You can also do things like making sure branches work correctly as well as looking in other directories for your file but this depends on your needs.

Hope this helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants