我需要遍历存储库的提交并为每次提交获取受影响的文件。这是我目前巨大的性能瓶颈。
我有一个关于libgit函数的C ++包装器,但这段代码应该是可以理解的。
std::vector<std::string> Commit::getAffectedFiles() const {
git_tree* tree = nullptr;
git_tree* tree2 = nullptr;
int error = git_commit_tree(&tree, get());
throw_on_error(error);
try {
error = git_commit_tree(&tree2, parent(0).get());
} catch (GitException e) {
tree2 = nullptr; // probably initial commit
}
git_diff* diff = nullptr;
git_diff_tree_to_tree(&diff, getRepo(), tree2, tree, 0);
std::vector<std::string> ret;
git_diff_foreach(diff,
[](const git_diff_delta* entry, float progress, void* payload) {
std::string str = entry->old_file.path;
((std::vector<std::string>*)payload)->push_back(str);
return 0;
}, nullptr, nullptr, nullptr, &ret);
git_tree_free(tree);
git_tree_free(tree2);
git_diff_free(diff);
return ret;
}
我只能希望我在这里做一些根本错误的事情。
例如
git log --stat > /dev/null
速度更快,并提供相同的信息。
perf按顺序报告git__strncmp
,git_buf_rfind_next
和git_tree__parse
的大部分用法。
我知道这是IO很重,但我没有看到一种简单的方法来减少这种情况或并行运行。
答案 0 :(得分:1)