JGIT库可以通过git.status().call()来获取当前working copy的文件变动情况,功能类似与命令行的git status,以下从源码角度简析git status的实现原理:
public Status call() throws GitAPIException, NoWorkTreeException {
if (workingTreeIt == null)
workingTreeIt = new FileTreeIterator(repo);
try {
IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIt);
if (ignoreSubmoduleMode != null)
diff.setIgnoreSubmoduleMode(ignoreSubmoduleMode);
if (paths != null)
diff.setFilter(PathFilterGroup.createFromStrings(paths));
if (progressMonitor == null)
diff.diff();
else
diff.diff(progressMonitor, ProgressMonitor.UNKNOWN,
ProgressMonitor.UNKNOWN, ""); //$NON-NLS-1$
return new Status(diff);
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
}
}</

本文简析了JGIT库中git.status().call()的实现过程,包括获取工作目录迭代器、设置Diff条件、生成Diff以及将Diff转换为Status,与git命令行的status功能相似。
最低0.47元/天 解锁文章
900

被折叠的 条评论
为什么被折叠?



