How to retrieve all object IDs?

心不动则不痛 提交于 2019-12-21 01:59:17

问题


I am trying to get a list of all object IDs in a git repository, using libgit2. I can't seem to find any method for this. Does libgit2 have a method to get all object IDs (or iterate through them), or do I need to read them manually?


回答1:


What you may be looking for is the revision walking API.

  • Description of the feature can be found here.
  • A test demonstrating different walking strategies may also provide you with some help

Edit: A thread in the libgit2 mailing list specifically deals with this.

A more precise answer from Vicent Marti (libgit2 maintainer) is

... Just push every single HEAD into the the walker. You won't get any duplicate commits.

All you have to do is to push every branch and tag oids into the revision walker to recursively walk the commit history. Please note this won't retrieve dangling commits (commits or chain of commits that are not referenced by a branch nor a tag).

Edit 2: This behavior (similar to git log --all) has been successfully implemented in libgit2sharp (libgit2 .Net bindings).

Edit 3: A new feature has recently been merged which would allow to enumerate all the objects (commits, trees, blobs, ...) stored in the object database: git_odb_foreach().

This would be more in line with the git fsck scenario @MatrixFrog was talking about.

  • git_odb_foreach() documentation
  • A simple test demonstrating how to use the API


来源:https://stackoverflow.com/questions/5249149/how-to-retrieve-all-object-ids

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!