我该如何使用libgit2遍历一个分支的所有提交?
我已经有了下面这段代码,但它无法编译。
我使用
我收到了以下错误信息:
我已经有了下面这段代码,但它无法编译。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <git2.h>
int main(int argc, char *argv[]){
git_repository *repo;
git_repository_open(&repo, ".");
git_odb *obj_db;
obj_db = git_repository_database(repo);
git_object commit;
git_revparse_single(&commit, repo, "HEAD");
git_repository_free(repo);
return 0;
}
GCC 报告:
log.c: In function ‘main’:
log.c:11:9: warning: assignment makes pointer from integer without a cast [enabled by default]
log.c:13:13: error: storage size of ‘commit’ isn’t known
我使用
-lgit2
参数编译了代码。有没有快速的方法可以从根提交开始浏览所有提交记录?
更新
新代码如下:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <git2.h>
int main(int argc, char *argv[]){
git_repository *repo;
git_repository_open(&repo, ".");
git_odb *obj_db;
obj_db = git_repository_database(repo);
git_object *commit;
git_revparse_single(&commit, repo, "HEAD");
git_repository_free(repo);
return 0;
}
我收到了以下错误信息:
log.c:11: undefined reference to `git_repository_database'
log.c:14: undefined reference to `git_revparse_single'
git_repository_database
不存在。可能你想要git_repository_odb
,但是你不应该需要它来获取日志。git_revparse_single
是在版本0.18中引入的,这表明你的系统上安装了一个古老的库。 - Carlos Martín Nietomaster
。也许git_revwalk
并没有为此设计? - Fuhrmanator