当文件在多模块项目中移动时,如何获取 IFile Eclipse Team IFileHistoryProvider 的完整历史记录?

发布于 2025-01-12 14:12:57 字数 1570 浏览 2 评论 0原文

我正在尝试从 Eclipse 插件以编程方式访问 IFile 对象的完整存储库历史记录。当文件从未被重命名或移动时,以下代码片段将起作用:

public long getFileHistoryTimestamp(IFile file, IProgressMonitor monitor, boolean lastModified) {
    IProject project = file.getProject();
    RepositoryProvider rProv = RepositoryProvider.getProvider(project);
    long createdMillis, lastModifiedMillis;
    if (rProv !=null) {
        IFileHistoryProvider fhp = rProv.getFileHistoryProvider();
        if (fhp != null) {
            IFileHistory fHist = fhp.getFileHistoryFor((IResource) file, 
                    IFileHistoryProvider.NONE, null);
            IFileRevision[] revs = fHist.getFileRevisions();
            Arrays.sort(revs, new Comparator<IFileRevision>(){
                   public int compare(IFileRevision o1, IFileRevision o2) {
                       return Long.compare(o1.getTimestamp(), o2.getTimestamp());
                   }
            });
            for (IFileRevision rev : revs) {
                if (rev.getTimestamp() >= 0) {
                    createdMillis = rev.getTimestamp();
                    break;
                }
            }
            if (revs.length > 0) {
                lastModifiedMillis = revs[revs.length - 1].getTimestamp();
            }
       }

       return lastModified ? lastModifiedMillis : createdMillis;
}

但是,如果文件已被移动(例如,将多模块 Maven 项目移动到新的或不同的模块/项目),则上面返回的值是 < em>仅对于当前位置的文件 - 即它不跟踪任何重命名/移动。 Eclipse 团队历史记录视图中的同一文件确实跟踪完整的版本历史记录。

如何在 Eclipse Team API 中访问完整的历史记录?

I am trying to access the full repository history of an IFile object programatically from an Eclipse plugin. When the file has never been renamed or moved, the following code snippet works:

public long getFileHistoryTimestamp(IFile file, IProgressMonitor monitor, boolean lastModified) {
    IProject project = file.getProject();
    RepositoryProvider rProv = RepositoryProvider.getProvider(project);
    long createdMillis, lastModifiedMillis;
    if (rProv !=null) {
        IFileHistoryProvider fhp = rProv.getFileHistoryProvider();
        if (fhp != null) {
            IFileHistory fHist = fhp.getFileHistoryFor((IResource) file, 
                    IFileHistoryProvider.NONE, null);
            IFileRevision[] revs = fHist.getFileRevisions();
            Arrays.sort(revs, new Comparator<IFileRevision>(){
                   public int compare(IFileRevision o1, IFileRevision o2) {
                       return Long.compare(o1.getTimestamp(), o2.getTimestamp());
                   }
            });
            for (IFileRevision rev : revs) {
                if (rev.getTimestamp() >= 0) {
                    createdMillis = rev.getTimestamp();
                    break;
                }
            }
            if (revs.length > 0) {
                lastModifiedMillis = revs[revs.length - 1].getTimestamp();
            }
       }

       return lastModified ? lastModifiedMillis : createdMillis;
}

But, if the file has been moved (e.g. with a multi-module maven project to a new or different module/project), then the values returned above are only for the file in it's current location - i.e. it does not track any rename/moves. The same file in the Eclipse Team History view does track the full version history.

How can I access this full history within the Eclipse Team API?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文