【问题标题】:How to list locally-modified/unversioned files using svnkit?如何使用 svnkit 列出本地修改/未版本控制的文件?
【发布时间】:2012-08-04 19:11:26
【问题描述】:

我正在编写一段代码,一旦在 SVN 工作副本中的任何位置执行,它就会定位到根:

File workingDirectory = new File(".").getCanonicalFile();
File wcRoot = SVNWCUtil.getWorkingCopyRoot(workingDirectory, true);

在给定此根目录的情况下获取存储库 url,在给定此信息的情况下构建 SVNClientManager,现在我被困在如何获取工作副本中不在存储库中的任何内容的列表 - 这包括本地修改的文件,未解决的合并,未版本控制的文件,我很高兴听到我可能错过的任何其他内容。

我该怎么做? 这个 sn-p 似乎需要访问存储库本身,而不是 WC:

clientManager.getLookClient().doGetChanged(...)

【问题讨论】:

    标签: java svn svnkit


    【解决方案1】:
    public static List<File> listModifiedFiles(File path, SVNRevision revision) throws SVNException {
        SVNClientManager svnClientManager = SVNClientManager.newInstance();
        final List<File> fileList = new ArrayList<File>();
        svnClientManager.getStatusClient().doStatus(path, revision, SVNDepth.INFINITY, false, false, false, false, new ISVNStatusHandler() {
            @Override
            public void handleStatus(SVNStatus status) throws SVNException {
                SVNStatusType statusType = status.getContentsStatus();
                if (statusType != SVNStatusType.STATUS_NONE && statusType != SVNStatusType.STATUS_NORMAL
                        && statusType != SVNStatusType.STATUS_IGNORED) {
                    fileList.add(status.getFile());
                }
            }
        }, null);
        return fileList;
    }
    

    【讨论】:

    • 要包含我发现的未版本化文件,我必须从 if 语句中删除 statusType != SVNStatusType.STATUS_NONE
    【解决方案2】:

    这为您提供本地修改,即它不会查看存储库中已更改但不在您的工作副本中的内容

    static def isModded(SvnConfig svn, File path, SVNRevision rev) {
        SVNClientManager mgr = newInstance(null, svn.username, svn.password)
        logger.debug("Searching for modifications beneath $path.path @ $rev")
        mgr.statusClient.doStatus(path, rev, INFINITY, false, false, false, false, { SVNStatus status ->
            SVNStatusType statusType = status.contentsStatus
            if (statusType != STATUS_NONE && statusType != STATUS_NORMAL && statusType != STATUS_IGNORED) {
                lmodded = true
                logger.debug("$status.file.path --> lmodded: $statusType")
            }
        } as ISVNStatusHandler, null)
        lmodded
    }
    

    我为此编写的代码是 groovy,但希望 svnkit api 的使用足够明显,可以使用。 SvnConfig 只是一个本地值对象,包含有关存储库本身的各种详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 2017-11-24
      相关资源
      最近更新 更多