`
huraky
  • 浏览: 31709 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

查看末提交文件的SVN状态

    博客分类:
  • JAVA
阅读更多

     使用SVNKit.jar提供的API,我们可以很轻松的查看没有提交的Working Copy中的文件的SVN状态,主要的做法是使用SVNClientManager实例的getStatusClient().doStatus()方法来调用自定义的ISVNStatusHandler的handleStatus(SVNStatus status)方法查看文件的状态,从而来进行判断。

     主要代码如下:

private static void setupLibrary() {
    /*
       * For using over http:// and https://
       */
    DAVRepositoryFactory.setup();
    /*
       * For using over svn:// and svn+xxx://
       */
    SVNRepositoryFactoryImpl.setup();

    /*
       * For using over file:///
       */
    FSRepositoryFactory.setup();
  }

public static void main(String[] args) throws SVNException {
    setupLibrary();

    SVNURL repositoryURL = null;
    try {
     //设置SVN服务器的URL
      repositoryURL =
          SVNURL.parseURIEncoded("https://192.168.88.88:8443/svn/test");
    } catch (SVNException e) {
      error("get respository url error!", e);
    }
   //设置登录用户与密码
    String name = "king";
    String password = "88888888";
    String myWorkingCopyPath = "F:\\arc";

    ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
    ISVNAuthenticationManager authManager =
      SVNWCUtil.createDefaultAuthenticationManager(name, password);
    File wcDir = new File(myWorkingCopyPath);
    if (!wcDir.exists()) {
      error("the work copy directory '" + wcDir.getAbsolutePath() +
            "' was not exists!", null);
      return;
    }
    ourClientManager = SVNClientManager.newInstance(options, authManager);

    //查询状态
    boolean isRecursive = true;
    boolean isRemote = true;
    boolean isReportAll = false;
    boolean isIncludeIgnored = true;
    boolean isCollectParentExternals = false;
    File[] unVF = null;
    System.out.println("Status for '" + wcDir.getAbsolutePath() + "':");
    try {
      List unVerFiles =
        showStatus(wcDir, isRecursive, isRemote, isReportAll, isIncludeIgnored,
                   isCollectParentExternals);
    } catch (SVNException svne) {
      error("error while recursively performing status for '" +
            wcDir.getAbsolutePath() + "'", svne);
    }

    //copy to temp file
    if (unVF != null) {
      File anImportDir = new File(importFile);
      createLocalDir(anImportDir, unVF);
    }
  }
/**
*主要是查询状态
*/
private static void showStatus(File wcPath, boolean isRecursive,
                                 boolean isRemote, boolean isReportAll,
                                 boolean isIncludeIgnored,
                                 boolean isCollectParentExternals) throws SVNException {
   //定义状态管理类
    StatusHandler sh = new StatusHandler(isRemote);
    ourClientManager.getStatusClient().doStatus(wcPath, isRecursive, isRemote,
                                                isReportAll, isIncludeIgnored,
                                                isCollectParentExternals, sh);
  }
 

StatusHandler类的主要方法:

public void handleStatus(SVNStatus status) {
        /*
         * Gets  the  status  of  file/directory/symbolic link  text  contents. 
         * It is  SVNStatusType  who  contains  information on the state of  an 
         * item. 
         */
        SVNStatusType contentsStatus = status.getContentsStatus();

        String pathChangeType = " ";
        
        boolean isAddedWithHistory = status.isCopied();
        if (contentsStatus == SVNStatusType.STATUS_MODIFIED) {
            /*
             * The contents of the file have been Modified.
             */
            pathChangeType = "M";
        } else if (contentsStatus == SVNStatusType.STATUS_CONFLICTED) {
            /*
             * The  file  item  is  in a state of  Conflict. That  is,  changes 
             * received from the server during an  update  overlap  with  local 
             * changes the user has in his working copy. 
             */
            pathChangeType = "C";
        } else if (contentsStatus == SVNStatusType.STATUS_DELETED) {
            /*
             * The file, directory or symbolic link item has been scheduled for 
             * Deletion from the repository.
             */
            pathChangeType = "D";
        } else if (contentsStatus == SVNStatusType.STATUS_ADDED) {
            /*
             * The file, directory or symbolic link item has been scheduled for 
             * Addition to the repository.
             */
            pathChangeType = "A";
        } else if (contentsStatus == SVNStatusType.STATUS_UNVERSIONED) {
            /*
             * The file, directory or symbolic link item is not  under  version 
             * control.
             */
            pathChangeType = "?";
        } else if (contentsStatus == SVNStatusType.STATUS_EXTERNAL) {
            /*
             * The item is unversioned, but is used by an eXternals definition.
             */
            pathChangeType = "X";
        } else if (contentsStatus == SVNStatusType.STATUS_IGNORED) {
            /*
             * The file, directory or symbolic link item is not  under  version 
             * control, and is configured to be Ignored during 'add',  'import' 
             * and 'status' operations. 
             */
            pathChangeType = "I";
        } else if (contentsStatus == SVNStatusType.STATUS_MISSING
                || contentsStatus == SVNStatusType.STATUS_INCOMPLETE) {
            /*
             * The file, directory or  symbolic  link  item  is  under  version 
             * control but is missing or somehow incomplete. The  item  can  be 
             * missing if it is removed using a command incompatible  with  the 
             * native Subversion command line client (for example, just removed 
             * from the filesystem). In the case the item is  a  directory,  it 
             * can  be  incomplete if the user happened to interrupt a checkout 
             * or update.
             */
            pathChangeType = "!";
        } else if (contentsStatus == SVNStatusType.STATUS_OBSTRUCTED) {
            /*
             * The file, directory or symbolic link item is in  the  repository 
             * as one kind of object, but what's actually in the user's working 
             * copy is some other kind. For example, Subversion  might  have  a 
             * file in the repository,  but  the  user  removed  the  file  and 
             * created a directory in its place, without using the 'svn delete' 
             * or 'svn add' command (or SVNKit analogues for them).
             */
            pathChangeType = "~";
        } else if (contentsStatus == SVNStatusType.STATUS_REPLACED) {
            /*
             * The file, directory or symbolic link item was  Replaced  in  the 
             * user's working copy; that is, the item was deleted,  and  a  new 
             * item with the same name was added (within  a  single  revision). 
             * While they may have the same name, the repository considers them 
             * to be distinct objects with distinct histories.
             */
            pathChangeType = "R";
        } else if (contentsStatus == SVNStatusType.STATUS_NONE
                || contentsStatus == SVNStatusType.STATUS_NORMAL) {
            /*
             * The item was not modified (normal).
             */
            pathChangeType = " ";
        }
}
 
分享到:
评论

相关推荐

    SVN常用操作----查看代码提交以及改动记录方法

    **SVN常用操作——查看代码提交及改动记录方法** 在软件开发过程中,版本控制系统如Subversion(SVN)是团队协作的重要工具。它允许开发者跟踪和管理代码的修改历史,以便于协同工作、回溯错误并理解代码的发展过程...

    svn 删除文件 update 又出来了 怎么回事

    当你执行`svn update`,系统会将仓库的最新状态与你的本地副本同步,如果仓库中该文件还未被删除,那么这个文件就有可能会被重新拉取回来。 解决这个问题的一个方法是使用`svn revert`命令。`svn revert`可以用来...

    svn提交失败

    运行`svn update`命令,将本地代码更新到服务器上的最新状态,然后再尝试提交。 8. **解决冲突的策略**: 对于文件冲突,可以采用合并、重置或放弃更改等策略。合并将尝试自动合并更改,但可能需要人工介入;重置...

    Svn 提交过程中的错误

    在使用Subversion(简称Svn)进行版本控制时,可能会遇到一些常见的问题,尤其是在提交文件的过程中。本篇文章将深入解析“Svn提交过程中的错误”,包括“文件提交失败”和“警告:已经存在”的问题,并提供相应的...

    SVN自动更新提交脚本.zip(windows版本)

    脚本通过执行`svn update`命令实现这一功能,确保你的工作环境始终保持最新状态,减少因代码不一致导致的冲突。 2. **SVN自动提交**: 自动提交脚本则帮助开发者定时将本地的修改推送到SVN服务器,无需手动执行`...

    svn安装文件及操作文件

    7. **查看状态(Status)**:使用`svn status`命令可以查看工作副本中文件的状态,了解哪些文件被修改、新增或删除。 8. **日志(Log)**:通过`svn log`可以查看仓库的历史提交记录,了解每次提交的详情。 9. **...

    如何删除SVN连接,即工程下的所有.svn文件

    `.svn`文件和目录是SVN工作副本的标志,它们包含了版本信息、状态、配置等数据。 **为何要删除.SVN文件** 1. **节省磁盘空间**:`.svn`目录通常包含大量的版本信息,删除它们可以释放一定的磁盘空间。 2. **隐私...

    svn 自动 lock 自动锁

    锁定状态会在svn服务器上记录,直到用户执行`svn unlock`命令释放锁。此机制可以防止数据丢失和代码不一致。 3. **自动锁定需求** 在某些情况下,手动锁定文件可能会导致效率降低,因为用户需要记住在开始编辑前先...

    SVN文件下载

    7. 版本号(Revision):每次提交都会增加版本号,表示文件或目录的历史状态。 二、SVN的功能 1. 版本控制:记录文件的每次修改,便于追踪历史和回滚。 2. 团队协作:多人可以同时编辑同一项目,避免冲突。 3. ...

    clearSVN清除svn文件

    6. **查看结果**:清理完成后,检查工作副本的状态,确保所有不需要的文件都被正确删除。 7. **更新工作副本**:为了确保与服务器同步,通常还需要执行 `svn update` 命令来获取最新的项目版本。 `clearSVN` 的...

    清楚svn目录下生成的.svn文件夹

    - **谨慎操作**:清理`.svn`文件夹会丢失版本控制信息,这意味着你无法再使用SVN进行版本控制操作,如提交、更新和回滚。 - **备份**:在清理之前,确保你有项目的备份,以防万一需要恢复到某个版本。 - **不适用...

    svn在linux下的使用(svn命令)

    svn status 命令用于查看文件或者目录的状态。例如:svn status path(显示目录下的文件和子目录的状态) 7. 删除文件 svn delete 命令用于删除文件。例如:svn delete test.php 8. 查看日志 svn log 命令用于...

    SVN目录下.svn文件批量删除

    在SVN的工作目录中,`.svn`文件夹是SVN用来存储元数据和版本信息的地方,包括每个文件的修订版本、差异信息以及与其他用户的同步状态。这些`.svn`文件夹对于SVN的正常运行至关重要,但有时可能因为某些原因需要进行...

    svn上删除文件和文件夹

    在Eclipse这个强大的集成开发环境中,svn插件提供了对svn的强大支持,包括添加、更新、提交以及我们今天要讨论的主题——删除文件和文件夹。下面,我们将深入探讨如何在Eclipse中使用svn进行文件和文件夹的删除操作...

    获取svn最新版本号示例 以及svn常用命令

    5. **`svn status` (简写:`svn st`)**:查看本地工作副本的状态,哪些文件被修改、添加或删除,格式为`svn status [PATH]`。 6. **`svn revert`**:撤销本地更改,恢复到上次提交的状态,格式为`svn revert [PATH]`...

    windows下删除.svn文件

    `.svn`文件是Subversion的工作副本的一部分,它们包含了版本库的信息,包括每个文件的版本历史、状态以及与远程仓库的通信信息。当你在一个项目中使用SVN时,这些文件会自动创建并更新,帮助你进行版本控制操作,如...

    AnkhSVN 在VS中管理SVN

    3. **提交对话框**:AnkhSVN提供了一个详细的提交对话框,允许用户选择要提交的文件,添加提交注释,并查看即将提交的改动预览。 4. **冲突解决工具**:当多个用户同时修改同一文件时,AnkhSVN会提示存在冲突。它...

    svn清理sqlite3

    在svn中,SQLite3数据库存储了仓库的所有元数据,包括文件和目录的状态、版本历史等。当svn遇到问题时,检查和修复SQLite3数据库通常能解决问题。 当svn的SQLite3数据库出现问题时,可以尝试以下步骤进行解决: 1....

    快速清理svn文件夹

    这通常涉及到删除`.svn`隐藏文件夹,它们是SVN存储元数据的地方,包括提交历史、状态信息等。手动清理这些文件夹既耗时又容易出错,而通过自动化工具或脚本可以简化这个过程。 描述中提到的压缩包包含一个名为`...

Global site tag (gtag.js) - Google Analytics