douqiaosu0280 2015-07-24 15:54
浏览 54

在git2go(libgit2)中查找包含指定blob对象的提交

Given a blob object, how can you find the (first) commit that contains that object?

One solution I think is to start a revwalk from the tip of a branch and walk your way down the graph, inspecting the tree for each commit and use something like git_tree_entry_byid to see if it contains your object. This would find commits accessible from a particular branch, but it is a solution in my case.

Is there a better way of doing this?

  • 写回答

1条回答 默认 最新

  • dos49618 2015-07-30 12:31
    关注

    If you want to check whether an object is contained in a particular commit, the only way to do that is to walk down the object graph and see if it's there.

    There is however one way you can re-use some of those searches. If you diff a pair of commits, and you know that the object in question is contained (or not) in one of them, you can look at the diff for the appearance/disappearance of that blob from the commit's tree, which would avoid walking down equal trees.

    git supports reachability bitmaps, which make this rather quick, but libgit2 does not support reading them.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看