Esempio n. 1
0
  public static SVNAdminArea open(File path, Level logLevel) throws SVNException {
    SVNErrorMessage error = null;
    int wcFormatVersion = -1;
    Collection enabledFactories = getSelector().getEnabledFactories(path, ourFactories, false);
    File adminDir = new Resource(path, SVNFileUtil.getAdminDirectoryName());
    File entriesFile = new Resource(adminDir, "entries");
    if (adminDir.isDirectory() && entriesFile.isFile()) {
      for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) {
        SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next();
        try {
          wcFormatVersion = factory.getVersion(path);
          if (wcFormatVersion > factory.getSupportedVersion()) {
            SVNErrorMessage err =
                SVNErrorMessage.create(
                    SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                    "The path ''{0}'' appears to be part of a Subversion 1.7 or greater\n"
                        + "working copy.  Please upgrade your Subversion client to use this\n"
                        + "working copy.",
                    path);
            SVNErrorManager.error(err, SVNLogType.WC);
          } else if (wcFormatVersion < factory.getSupportedVersion()) {
            SVNErrorMessage err =
                SVNErrorMessage.create(
                    SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                    "Working copy format of {0} is too old ({1}); please check out your working copy again",
                    new Object[] {path, new Integer(wcFormatVersion)});
            SVNErrorManager.error(err, SVNLogType.WC);
          }
        } catch (SVNException e) {
          if (error != null) {
            error.setChildErrorMessage(e.getErrorMessage());
          } else {
            error = e.getErrorMessage();
          }
          continue;
        }

        SVNAdminArea adminArea = factory.doOpen(path, wcFormatVersion);
        if (adminArea != null) {
          adminArea.setWorkingCopyFormatVersion(wcFormatVersion);
          return adminArea;
        }
      }
    }
    if (error == null) {
      if (path != null) {
        checkWCNG(path.getAbsoluteFile(), path);
      }
      error =
          SVNErrorMessage.create(
              SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", path);
    }
    if (error.getErrorCode() == SVNErrorCode.WC_UNSUPPORTED_FORMAT) {
      error.setChildErrorMessage(null);
    }
    SVNErrorManager.error(error, logLevel, SVNLogType.WC);
    return null;
  }
Esempio n. 2
0
  public static int checkWC(File path, boolean useSelector, Level logLevel) throws SVNException {
    Collection enabledFactories = ourFactories;
    if (useSelector) {
      enabledFactories = getSelector().getEnabledFactories(path, enabledFactories, false);
    }
    SVNErrorMessage error = null;
    int version = -1;
    for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) {
      SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next();
      try {
        version = factory.doCheckWC(path, logLevel);
        if (version == 0) {
          return version;
        }

        if (version > factory.getSupportedVersion()) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                  "The path ''{0}'' appears to be part of a Subversion 1.7 or greater\n"
                      + "working copy.  Please upgrade your Subversion client to use this\n"
                      + "working copy.",
                  path);
          SVNErrorManager.error(err, SVNLogType.WC);
        } else if (version < factory.getSupportedVersion()) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                  "Working copy format of {0} is too old ({1}); please check out your working copy again",
                  new Object[] {path, new Integer(version)});
          SVNErrorManager.error(err, SVNLogType.WC);
        }
      } catch (SVNException e) {
        if (error != null) {
          error.setChildErrorMessage(e.getErrorMessage());
        } else {
          error = e.getErrorMessage();
        }
        continue;
      }
      return version;
    }
    if (error == null) {
      if (path != null) {
        checkWCNG(path.getAbsoluteFile(), path);
      }
      error =
          SVNErrorMessage.create(
              SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", path);
    }
    if (error.getErrorCode() == SVNErrorCode.WC_UNSUPPORTED_FORMAT) {
      error.setChildErrorMessage(null);
    }
    SVNErrorManager.error(error, logLevel, SVNLogType.WC);
    return 0;
  }
Esempio n. 3
0
  public long commitTxn(
      boolean runPreCommitHook,
      boolean runPostCommitHook,
      SVNErrorMessage[] postCommitHookError,
      StringBuffer conflictPath)
      throws SVNException {
    if (myFSFS.isHooksEnabled() && runPreCommitHook) {
      FSHooks.runPreCommitHook(myFSFS.getRepositoryRoot(), myTxn.getTxnId());
    }

    long newRevision = SVNRepository.INVALID_REVISION;

    while (true) {
      long youngishRev = myFSFS.getYoungestRevision();
      FSRevisionRoot youngishRoot = myFSFS.createRevisionRoot(youngishRev);

      FSRevisionNode youngishRootNode = youngishRoot.getRevisionNode("/");

      mergeChanges(myFSFS, getTxnRoot(), youngishRootNode, conflictPath);
      myTxn.setBaseRevision(youngishRev);

      FSWriteLock writeLock = FSWriteLock.getWriteLockForDB(myFSFS);
      synchronized (writeLock) {
        try {
          writeLock.lock();
          newRevision = commit();
        } catch (SVNException svne) {
          if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.FS_TXN_OUT_OF_DATE) {
            long youngestRev = myFSFS.getYoungestRevision();
            if (youngishRev == youngestRev) {
              throw svne;
            }
            continue;
          }
          throw svne;
        } finally {
          writeLock.unlock();
          FSWriteLock.release(writeLock);
        }
      }
      break;
    }

    if (myFSFS.isHooksEnabled() && runPostCommitHook) {
      try {
        FSHooks.runPostCommitHook(myFSFS.getRepositoryRoot(), newRevision);
      } catch (SVNException svne) {
        SVNErrorMessage errorMessage =
            SVNErrorMessage.create(
                SVNErrorCode.REPOS_POST_COMMIT_HOOK_FAILED,
                "Commit succeeded, but post-commit hook failed",
                SVNErrorMessage.TYPE_WARNING);
        errorMessage.initCause(svne);
        SVNErrorMessage childErr = svne.getErrorMessage();
        childErr.setDontShowErrorCode(true);
        errorMessage.setChildErrorMessage(childErr);

        if (postCommitHookError != null && postCommitHookError.length > 0) {
          postCommitHookError[0] = errorMessage;
        } else {
          SVNErrorManager.error(errorMessage, SVNLogType.FSFS);
        }
      }
    }
    return newRevision;
  }