@Nullable
  public SVNURL getUrlForFile(final File file) {
    final RootUrlInfo rootUrlInfo = getWcRootForFilePath(file);
    if (rootUrlInfo == null) {
      return null;
    }

    final String absolutePath = file.getAbsolutePath();
    final String rootAbsPath = rootUrlInfo.getIoFile().getAbsolutePath();
    if (absolutePath.length() < rootAbsPath.length()) {
      // remove last separator from etalon name
      if (absolutePath.equals(rootAbsPath.substring(0, rootAbsPath.length() - 1))) {
        return rootUrlInfo.getAbsoluteUrlAsUrl();
      }
      return null;
    }
    final String relativePath = absolutePath.substring(rootAbsPath.length());
    try {
      return rootUrlInfo
          .getAbsoluteUrlAsUrl()
          .appendPath(FileUtil.toSystemIndependentName(relativePath), true);
    } catch (SVNException e) {
      LOG.info(e);
      return null;
    }
  }
  @Nullable
  public String getLocalPath(final String url) {
    synchronized (myMonitor) {
      final String rootUrl = getUrlRootForUrl(url);
      if (rootUrl == null) {
        return null;
      }
      final RootUrlInfo parentInfo = myMapping.byUrl(rootUrl);
      if (parentInfo == null) {
        return null;
      }

      return fileByUrl(parentInfo.getIoFile().getAbsolutePath(), rootUrl, url).getAbsolutePath();
    }
  }
  @Test
  public void testExternalCopyIsDetected() throws Exception {
    prepareExternal();

    final SvnFileUrlMapping workingCopies = myVcs.getSvnFileUrlMapping();
    final List<RootUrlInfo> infos = workingCopies.getAllWcInfos();
    Assert.assertEquals(2, infos.size());
    final Set<String> expectedUrls = new HashSet<String>();
    expectedUrls.add(StringUtil.toLowerCase(myExternalURL));
    expectedUrls.add(StringUtil.toLowerCase(myMainUrl));

    for (RootUrlInfo info : infos) {
      expectedUrls.remove(StringUtil.toLowerCase(info.getAbsoluteUrl()));
    }
    Assert.assertTrue(expectedUrls.isEmpty());
  }
Exemplo n.º 4
0
  /**
   * Returns real working copies roots - if there is <Project Root> -> Subversion setting, and there
   * is one working copy, will return one root
   */
  public List<WCInfo> getAllWcInfos() {
    final SvnFileUrlMapping urlMapping = getSvnFileUrlMapping();

    final List<RootUrlInfo> infoList = urlMapping.getAllWcInfos();
    final List<WCInfo> infos = new ArrayList<WCInfo>();
    for (RootUrlInfo info : infoList) {
      final File file = info.getIoFile();
      infos.add(
          new WCInfo(
              file.getAbsolutePath(),
              info.getAbsoluteUrlAsUrl(),
              info.getFormat(),
              info.getRepositoryUrl(),
              SvnUtil.isWorkingCopyRoot(file),
              info.getType(),
              SvnUtil.getDepth(this, file)));
    }
    return infos;
  }
  @Override
  public Pair<SvnChangeList, FilePath> getOneList(final VirtualFile file, VcsRevisionNumber number)
      throws VcsException {
    final RootUrlInfo rootUrlInfo =
        myVcs.getSvnFileUrlMapping().getWcRootForFilePath(new File(file.getPath()));
    if (rootUrlInfo == null) return null;
    final VirtualFile root = rootUrlInfo.getVirtualFile();
    if (root == null) return null;
    final SvnRepositoryLocation svnRootLocation =
        (SvnRepositoryLocation) getLocationFor(new FilePathImpl(root));
    if (svnRootLocation == null) return null;
    final String url = svnRootLocation.getURL();
    final long revision;
    try {
      revision = Long.parseLong(number.asString());
    } catch (NumberFormatException e) {
      throw new VcsException(e);
    }

    final SvnChangeList[] result = new SvnChangeList[1];
    final SVNLogClient logger;
    final SVNRevision revisionBefore;
    final SVNURL repositoryUrl;
    final SVNURL svnurl;
    final SVNInfo targetInfo;
    try {
      logger = myVcs.createLogClient();
      revisionBefore = SVNRevision.create(revision);

      svnurl = SVNURL.parseURIEncoded(url);
      final SVNWCClient client = myVcs.createWCClient();
      final SVNInfo info = client.doInfo(svnurl, SVNRevision.UNDEFINED, SVNRevision.HEAD);
      targetInfo = client.doInfo(new File(file.getPath()), SVNRevision.UNDEFINED);
      if (info == null) {
        throw new VcsException("Can not get repository URL");
      }
      repositoryUrl = info.getRepositoryRootURL();
    } catch (SVNException e) {
      LOG.info(e);
      throw new VcsException(e);
    }

    tryExactHit(svnRootLocation, result, logger, revisionBefore, repositoryUrl, svnurl);
    if (result[0] == null) {
      tryByRoot(result, logger, revisionBefore, repositoryUrl);
      if (result[0] == null) {
        FilePath path =
            tryStepByStep(svnRootLocation, result, logger, revisionBefore, targetInfo, svnurl);
        path = path == null ? new FilePathImpl(file) : path;
        // and pass & take rename context there
        return new Pair<SvnChangeList, FilePath>(result[0], path);
      }
    }
    if (result[0].getChanges().size() == 1) {
      final Collection<Change> changes = result[0].getChanges();
      final Change change = changes.iterator().next();
      final ContentRevision afterRevision = change.getAfterRevision();
      if (afterRevision != null) {
        return new Pair<SvnChangeList, FilePath>(result[0], afterRevision.getFile());
      } else {
        return new Pair<SvnChangeList, FilePath>(result[0], new FilePathImpl(file));
      }
    }
    String relativePath =
        SVNPathUtil.getRelativePath(
            targetInfo.getRepositoryRootURL().toString(), targetInfo.getURL().toString());
    relativePath = relativePath.startsWith("/") ? relativePath : "/" + relativePath;
    final Change targetChange = result[0].getByPath(relativePath);
    if (targetChange == null) {
      FilePath path =
          tryStepByStep(svnRootLocation, result, logger, revisionBefore, targetInfo, svnurl);
      path = path == null ? new FilePathImpl(file) : path;
      // and pass & take rename context there
      return new Pair<SvnChangeList, FilePath>(result[0], path);
    }
    return new Pair<SvnChangeList, FilePath>(result[0], new FilePathImpl(file));
  }
 private SvnCopyRootSimple convert(final RootUrlInfo info) {
   final SvnCopyRootSimple copy = new SvnCopyRootSimple();
   copy.myVcsRoot = FileUtil.toSystemDependentName(info.getRoot().getPath());
   copy.myCopyRoot = info.getIoFile().getAbsolutePath();
   return copy;
 }