public SVNDirEntry info(String path, long revision) throws SVNException {
   try {
     openConnection();
     String fullPath = getFullPath(path);
     SVNURL url = getLocation().setPath(fullPath, false);
     path = getRepositoryPath(path);
     Object[] buffer = new Object[] {"stat", path, getRevisionObject(revision)};
     write("(w(s(n)))", buffer);
     authenticate();
     read("[((?F))]", buffer, true);
     SVNDirEntry entry = (SVNDirEntry) buffer[0];
     if (entry != null) {
       entry =
           new SVNDirEntry(
               url,
               SVNPathUtil.tail(path),
               entry.getKind(),
               entry.getSize(),
               entry.hasProperties(),
               entry.getRevision(),
               entry.getDate(),
               entry.getAuthor());
     }
     return entry;
   } catch (SVNException e) {
     closeSession();
     handleUnsupportedCommand(e, "'stat' not implemented");
   } finally {
     closeConnection();
   }
   return null;
 }
  @Nullable
  public static SvnBranchConfigurationNew loadDefaultConfiguration(
      final Project project, final VirtualFile vcsRoot) {
    try {
      final SvnVcs vcs = SvnVcs.getInstance(project);

      File rootFile = new File(vcsRoot.getPath());
      final Info info = vcs.getInfo(rootFile);
      if (info == null || info.getURL() == null) {
        LOG.info("Directory is not a working copy: " + vcsRoot.getPresentableUrl());
        return null;
      }
      SVNURL baseUrl = info.getURL();

      final SvnBranchConfigurationNew result = new SvnBranchConfigurationNew();
      result.setTrunkUrl(baseUrl.toString());
      while (true) {
        final String s = SVNPathUtil.tail(baseUrl.getPath());
        if (s.equalsIgnoreCase(DEFAULT_TRUNK_NAME)
            || s.equalsIgnoreCase(DEFAULT_BRANCHES_NAME)
            || s.equalsIgnoreCase(DEFAULT_TAGS_NAME)) {
          SVNURL rootPath = baseUrl.removePathTail();
          SvnTarget target = SvnTarget.fromURL(rootPath);

          vcs.getFactory(target)
              .createBrowseClient()
              .list(target, SVNRevision.HEAD, Depth.IMMEDIATES, createHandler(result, rootPath));
          break;
        }
        if (SVNPathUtil.removeTail(baseUrl.getPath()).length() == 0) {
          break;
        }
        baseUrl = baseUrl.removePathTail();
      }
      return result;
    } catch (SVNException e) {
      LOG.info(e);
      return null;
    } catch (VcsException e) {
      LOG.info(e);
      return null;
    }
  }
 static ChangeInfo classifiedChange(final SVNLogEntry entry, String rootPath, final String path) {
   StoreKind kind = StoreKind.OTHER;
   // Be sure the root path ends with a slash because the 'path' will always have the slash.
   if (!rootPath.endsWith("/")) {
     rootPath = rootPath + "/";
   }
   String name = path.length() > rootPath.length() ? path.substring(rootPath.length()) : path;
   String page = null;
   Matcher matcher = PAGE_PATH.matcher(name);
   if (matcher.matches() && !name.endsWith("-attachments")) {
     kind = StoreKind.PAGE;
     page = name;
   } else {
     matcher = ATTACHMENT_PATH.matcher(name);
     if (matcher.matches()) {
       kind = StoreKind.ATTACHMENT;
       page = matcher.group(1);
       name = matcher.group(2);
     }
   }
   String user = entry.getAuthor();
   Date date = entry.getDate();
   SVNLogEntryPath logForPath = (SVNLogEntryPath) entry.getChangedPaths().get(path);
   String copiedFrom = logForPath.getCopyPath();
   long copiedFromRevision = -1;
   if (SVNPathUtil.isAncestor(rootPath, copiedFrom)) {
     copiedFrom = SVNPathUtil.tail(copiedFrom);
     copiedFromRevision = logForPath.getCopyRevision();
   } else {
     copiedFrom = null;
   }
   return new ChangeInfo(
       page,
       name,
       user,
       date,
       entry.getRevision(),
       entry.getMessage(),
       kind,
       ChangeType.forCode(logForPath.getType()),
       copiedFrom,
       copiedFromRevision);
 }
Example #4
0
  private void doList(
      SVNRepository repos,
      long rev,
      final ISVNDirEntryHandler handler,
      boolean fetchLocks,
      SVNDepth depth,
      int entryFields,
      SVNURL externalParentUrl,
      String externalTarget)
      throws SVNException {
    boolean includeExternals = !getOperation().isIgnoreExternals();
    Map<SVNURL, SVNPropertyValue> externals =
        includeExternals ? new HashMap<SVNURL, SVNPropertyValue>() : null;
    SVNURL url = repos.getLocation();
    SVNURL reposRoot = repos.getRepositoryRoot(false);
    SVNDirEntry entry = null;
    SVNException error = null;
    try {
      entry = repos.info("", rev);
    } catch (SVNException svne) {
      if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_IMPLEMENTED) {
        error = svne;
      } else {
        throw svne;
      }
    }
    if (error != null) {
      SVNNodeKind kind = repos.checkPath("", rev);
      if (kind != SVNNodeKind.NONE) {
        if (!url.equals(reposRoot)) {
          String name = SVNPathUtil.tail(repos.getLocation().getPath());
          repos.setLocation(repos.getLocation().removePathTail(), false);
          Collection<SVNDirEntry> dirEntries =
              repos.getDir("", rev, null, entryFields, (Collection) null);
          repos.setLocation(url, false);
          for (Iterator<SVNDirEntry> ents = dirEntries.iterator(); ents.hasNext(); ) {
            SVNDirEntry dirEntry = (SVNDirEntry) ents.next();
            if (name.equals(dirEntry.getName())) {
              entry = dirEntry;
              break;
            }
          }
          if (entry != null) {
            entry.setRelativePath(kind == SVNNodeKind.FILE ? name : "");
          }
        } else {
          SVNProperties props = new SVNProperties();
          repos.getDir("", rev, props, entryFields, (Collection<SVNDirEntry>) null);
          SVNProperties revProps = repos.getRevisionProperties(rev, null);
          String author = revProps.getStringValue(SVNRevisionProperty.AUTHOR);
          String dateStr = revProps.getStringValue(SVNRevisionProperty.DATE);
          Date datestamp = null;
          if (dateStr != null) {
            datestamp = SVNDate.parseDateString(dateStr);
          }
          entry =
              new SVNDirEntry(
                  url, reposRoot, "", kind, 0, !props.isEmpty(), rev, datestamp, author);
          entry.setRelativePath("");
        }
      }
    } else if (entry != null) {
      if (entry.getKind() == SVNNodeKind.DIR) {
        entry.setName("");
      }
      entry.setRelativePath(entry.getKind() == SVNNodeKind.DIR ? "" : entry.getName());
    }
    if (entry == null) {
      SVNErrorMessage err =
          SVNErrorMessage.create(
              SVNErrorCode.FS_NOT_FOUND, "URL ''{0}'' non-existent in that revision", url);
      SVNErrorManager.error(err, SVNLogType.WC);
    }
    final Map locksMap = new SVNHashMap();
    if (fetchLocks) {
      SVNLock[] locks = new SVNLock[0];
      try {
        locks = repos.getLocks("");
      } catch (SVNException e) {
        if (!(e.getErrorMessage() != null
            && e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_IMPLEMENTED)) {
          throw e;
        }
      }
      if (locks != null && locks.length > 0) {
        SVNURL root = repos.getRepositoryRoot(true);
        for (int i = 0; i < locks.length; i++) {
          String repositoryPath = locks[i].getPath();
          locksMap.put(root.appendPath(repositoryPath, false), locks[i]);
        }
      }
    }
    ISVNDirEntryHandler nestedHandler =
        new ISVNDirEntryHandler() {

          public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
            dirEntry.setLock((SVNLock) locksMap.get(dirEntry.getURL()));
            handler.handleDirEntry(dirEntry);
          }
        };
    entry.setExternalParentUrl(externalParentUrl);
    entry.setExternalTarget(externalTarget);
    nestedHandler.handleDirEntry(entry);
    if (entry.getKind() == SVNNodeKind.DIR
        && (depth == SVNDepth.FILES
            || depth == SVNDepth.IMMEDIATES
            || depth == SVNDepth.INFINITY)) {
      list(
          repos,
          "",
          rev,
          depth,
          entryFields,
          externals,
          externalParentUrl,
          externalTarget,
          nestedHandler);
    }

    if (includeExternals && externals != null && externals.size() > 0) {
      listExternals(repos, externals, depth, entryFields, fetchLocks, handler);
    }
  }
Example #5
0
  public void run() throws SVNException {
    List targets = getSVNEnvironment().combineTargets(new ArrayList(), true);
    if (targets.isEmpty()) {
      SVNErrorManager.error(
          SVNErrorMessage.create(SVNErrorCode.CL_INSUFFICIENT_ARGS), SVNLogType.CLIENT);
    }
    String lastTarget = (String) targets.get(targets.size() - 1);
    if (SVNCommandUtil.isURL(lastTarget)) {
      if (targets.size() == 1) {
        SVNPath target = new SVNPath(lastTarget, true);
        lastTarget = target.getURL().getPath();
        lastTarget = SVNPathUtil.tail(lastTarget);
      } else {
        lastTarget = "";
      }
      targets.add(lastTarget);
    } else if (targets.size() == 1) {
      SVNErrorManager.error(
          SVNErrorMessage.create(SVNErrorCode.CL_INSUFFICIENT_ARGS), SVNLogType.CLIENT);
    }
    SVNUpdateClient client = getSVNEnvironment().getClientManager().getUpdateClient();
    if (!getSVNEnvironment().isQuiet()) {
      client.setEventHandler(new SVNNotifyPrinter(getSVNEnvironment(), true, false, false));
    }

    SVNRevision revision = getSVNEnvironment().getStartRevision();
    for (int i = 0; i < targets.size() - 1; i++) {
      String targetName = (String) targets.get(i);
      SVNPath target = new SVNPath(targetName, true);
      if (!target.isURL()) {
        SVNErrorManager.error(
            SVNErrorMessage.create(
                SVNErrorCode.BAD_URL, "''{0}'' doesn not appear to be a URL", targetName),
            SVNLogType.CLIENT);
      }
      String targetDir;
      SVNPath dstTarget;
      if (targets.size() == 2) {
        // url + path
        targetDir = lastTarget;
        dstTarget = new SVNPath(targetDir);
      } else {
        // all urls + base dst.
        targetDir = target.getURL().getPath();
        targetDir = SVNPathUtil.tail(targetDir);
        targetDir = SVNPathUtil.append(lastTarget, targetDir);
        dstTarget = new SVNPath(targetDir);
      }
      SVNRevision pegRevision = target.getPegRevision();
      if (revision == SVNRevision.UNDEFINED) {
        revision = pegRevision != SVNRevision.UNDEFINED ? pegRevision : SVNRevision.HEAD;
      }
      client.doCheckout(
          target.getURL(),
          dstTarget.getFile(),
          pegRevision,
          revision,
          getSVNEnvironment().getDepth(),
          getSVNEnvironment().isForce());
    }
  }