如何检索所有对象ID? [英] How to retrieve all object IDs?

查看:164
本文介绍了如何检索所有对象ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个Git仓库所有的对象ID的列表,使用libgit2。我似乎无法找到此的任何方法。是否libgit2有一个方法来获取所有对象ID(或遍历它们),或者我需要手动读?

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?

推荐答案

你可能会寻找的是修订走 API。

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

编辑: A <一个href=\"http://librelist.com/browser//libgit2/2011/8/15/can-a-revision-walker-show-commits-from-all-branches/#1e4e6160975a8dca8cc3ea44c7b2336b\"相对=nofollow>在libgit2 邮件列表线程 特别是与此交易。

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

从维森特·马蒂(libgit2维护者)更precise答案

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.

所有您需要做的是分支或标签的OID推入修订沃克递归走提交历史。请注意,这将不检索晃来晃去提交(提交或不是由一个分支,也不是一个标签引用提交的链)。

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).

编辑2::此行为(类似于 git的日志--all )已经成功的在libgit2sharp实施(libgit2净绑定)。

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

修改3::一种新功能,最近被合并这将使枚举的所有的对象(提交,树木,斑点,...)存储在对象数据库: git_odb_foreach()

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().

这将是更符合混帐的fsck行情景@MatrixFrog在说什么。

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

这篇关于如何检索所有对象ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆