public static void replay(
      FSFS fsfs,
      FSRoot root,
      String basePath,
      long lowRevision,
      boolean sendDeltas,
      ISVNEditor editor)
      throws SVNException {
    Map fsChanges = root.getChangedPaths();
    basePath = basePath.startsWith("/") ? basePath.substring(1) : basePath;
    Collection interestingPaths = new LinkedList();
    Map changedPaths = new HashMap();
    for (Iterator paths = fsChanges.keySet().iterator(); paths.hasNext(); ) {
      String path = (String) paths.next();
      FSPathChange change = (FSPathChange) fsChanges.get(path);

      path = path.startsWith("/") ? path.substring(1) : path;
      if ("".equals(basePath)
          || (path.startsWith(basePath)
              && (path.charAt(basePath.length()) == '/' || path.length() == basePath.length()))) {
        path = path.startsWith("/") ? path.substring(1) : path;
        interestingPaths.add(path);
        changedPaths.put(path, change);
      }
    }
    if (FSRepository.isInvalidRevision(lowRevision)) {
      lowRevision = 0;
    }

    FSRoot compareRoot = null;
    if (sendDeltas && root instanceof FSRevisionRoot) {
      FSRevisionRoot revRoot = (FSRevisionRoot) root;
      compareRoot = fsfs.createRevisionRoot(revRoot.getRevision() - 1);
    }

    if (root instanceof FSRevisionRoot) {
      FSRevisionRoot revRoot = (FSRevisionRoot) root;
      editor.targetRevision(revRoot.getRevision());
    }

    ISVNCommitPathHandler handler =
        new FSReplayPathHandler(fsfs, root, compareRoot, changedPaths, basePath, lowRevision);
    SVNCommitUtil.driveCommitEditor(handler, interestingPaths, editor, -1);
  }
예제 #2
0
  public void makePathMutable(FSParentPath parentPath, String errorPath) throws SVNException {
    FSTransactionRoot txnRoot = getTxnRoot();
    String txnId = txnRoot.getTxnID();

    if (parentPath.getRevNode().getId().isTxn()) {
      return;
    }
    FSRevisionNode clone = null;

    if (parentPath.getParent() != null) {
      makePathMutable(parentPath.getParent(), errorPath);
      FSID parentId = null;
      String copyId = null;

      switch (parentPath.getCopyStyle()) {
        case FSCopyInheritance.COPY_ID_INHERIT_PARENT:
          parentId = parentPath.getParent().getRevNode().getId();
          copyId = parentId.getCopyID();
          break;
        case FSCopyInheritance.COPY_ID_INHERIT_NEW:
          copyId = reserveCopyId(txnId);
          break;
        case FSCopyInheritance.COPY_ID_INHERIT_SELF:
          copyId = null;
          break;
        case FSCopyInheritance.COPY_ID_INHERIT_UNKNOWN:
        default:
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.UNKNOWN,
                  "FATAL error: can not make path ''{0}'' mutable",
                  errorPath);
          SVNErrorManager.error(err, SVNLogType.FSFS);
      }

      String copyRootPath = parentPath.getRevNode().getCopyRootPath();
      long copyRootRevision = parentPath.getRevNode().getCopyRootRevision();

      FSRoot copyrootRoot = myFSFS.createRevisionRoot(copyRootRevision);
      FSRevisionNode copyRootNode = copyrootRoot.getRevisionNode(copyRootPath);
      FSID childId = parentPath.getRevNode().getId();
      FSID copyRootId = copyRootNode.getId();
      boolean isParentCopyRoot = false;
      if (!childId.getNodeID().equals(copyRootId.getNodeID())) {
        isParentCopyRoot = true;
      }

      String clonePath = parentPath.getParent().getAbsPath();
      clone =
          txnRoot.cloneChild(
              parentPath.getParent().getRevNode(),
              clonePath,
              parentPath.getEntryName(),
              copyId,
              isParentCopyRoot);

      txnRoot.putRevNodeToCache(parentPath.getAbsPath(), clone);
    } else {
      FSTransactionInfo txn = txnRoot.getTxn();

      if (txn.getRootID().equals(txn.getBaseID())) {
        SVNErrorMessage err =
            SVNErrorMessage.create(
                SVNErrorCode.UNKNOWN,
                "FATAL error: txn ''{0}'' root id ''{1}'' matches base id ''{2}''",
                new Object[] {txnId, txn.getRootID(), txn.getBaseID()});
        SVNErrorManager.error(err, SVNLogType.FSFS);
      }
      clone = myFSFS.getRevisionNode(txn.getRootID());
    }

    parentPath.setRevNode(clone);
  }
예제 #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;
  }