@Override
    protected void preliminary() throws SVNException {
      SVNWCClient wcClient = myVcs.createWCClient();
      myInfo =
          wcClient.doInfo(new File(myFile.getIOFile().getAbsolutePath()), SVNRevision.UNDEFINED);
      wcClient.setEventHandler(
          new ISVNEventHandler() {
            public void handleEvent(SVNEvent event, double progress) throws SVNException {}

            public void checkCancelled() throws SVNCancelException {
              myPI.checkCanceled();
            }
          });
      if (myInfo == null || myInfo.getRepositoryRootURL() == null) {
        myException =
            new VcsException("File ''{0}'' is not under version control" + myFile.getIOFile());
        return;
      }
      if (myInfo.getURL() == null) {
        myException =
            new VcsException("File " + myFile.getPath() + " is not under Subversion control");
        return;
      }
      myUrl = myInfo.getURL().toString();
    }
 /** passed dir must be under VC control (it is assumed) */
 @Nullable
 public String getRepositoryUUID(final Project project, final VirtualFile dir) {
   try {
     final SVNInfo info1 =
         new RepeatSvnActionThroughBusy() {
           @Override
           protected void executeImpl() throws SVNException {
             myT = myVcs.getInfo(new File(dir.getPath()));
           }
         }.compute();
     if (info1 == null || info1.getRepositoryUUID() == null) {
       // go deeper if current parent was added (if parent was added, it theoretically could NOT
       // know its repo UUID)
       final VirtualFile parent = dir.getParent();
       if (parent == null) {
         return null;
       }
       if (isPendingAdd(project, parent)) {
         return getRepositoryUUID(project, parent);
       }
     } else {
       return info1.getRepositoryUUID();
     }
   } catch (SVNException e) {
     // go to return default
   }
   return null;
 }
 @Override
 public SVNNodeKind getKind() {
   if (myFileExists) return super.getKind();
   final SVNInfo info = initInfo();
   if (info != null) {
     return info.getKind();
   }
   return super.getKind();
 }
  @Override
  public File getFile() {
    File file = super.getFile();

    if (file == null) {
      SVNInfo info = initInfo();
      file = info != null ? info.getFile() : file;
    }

    return file;
  }
  @Override
  public SVNURL getURL() {
    SVNURL url = super.getURL();

    if (url == null) {
      SVNInfo info = initInfo();
      url = info != null ? info.getURL() : url;
    }

    return url;
  }
 public SVNInfo getInfo(File ioFile) {
   try {
     SVNWCClient wcClient = createWCClient();
     SVNInfo info = wcClient.doInfo(ioFile, SVNRevision.UNDEFINED);
     if (info == null || info.getRepositoryRootURL() == null) {
       info = wcClient.doInfo(ioFile, SVNRevision.HEAD);
     }
     return info;
   } catch (SVNException e) {
     return null;
   }
 }
  @Override
  public SVNRevision getRevision() {
    final SVNRevision revision = super.getRevision();
    if (revision != null && revision.isValid()) return revision;

    final SVNStatusType status = getContentsStatus();
    if (SVNStatusType.STATUS_NONE.equals(status)
        || SVNStatusType.STATUS_UNVERSIONED.equals(status)
        || SVNStatusType.STATUS_ADDED.equals(status)) return revision;

    final SVNInfo info = initInfo();
    return info == null ? revision : info.getRevision();
  }
    public String invoke(File p, VirtualChannel channel) throws IOException {
      final SVNClientManager manager = SubversionSCM.createSvnClientManager(authProvider);
      try {
        final SVNWCClient svnwc = manager.getWCClient();

        SVNInfo info;
        try {
          info = svnwc.doInfo(p, SVNRevision.WORKING);
          return info.getURL().toDecodedString();
        } catch (SVNException e) {
          e.printStackTrace();
          return null;
        }
      } finally {
        manager.dispose();
      }
    }
 @Override
 protected void load() {
   if (myPI != null) {
     myPI.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", myUrl));
   }
   SVNWCClient wcClient = myVcs.createWCClient();
   try {
     final SVNURL svnurl = SVNURL.parseURIEncoded(myUrl);
     SVNInfo info = null;
     info = wcClient.doInfo(svnurl, SVNRevision.UNDEFINED, SVNRevision.HEAD);
     final String root = info.getRepositoryRootURL().toString();
     String relativeUrl = myUrl;
     if (myUrl.startsWith(root)) {
       relativeUrl = myUrl.substring(root.length());
     }
     SVNLogClient client = myVcs.createLogClient();
     client.doLog(
         svnurl,
         new String[] {},
         SVNRevision.UNDEFINED,
         SVNRevision.HEAD,
         SVNRevision.create(1),
         false,
         true,
         mySupport15,
         0,
         null,
         new RepositoryLogEntryHandler(
             myVcs,
             myUrl,
             SVNRevision.UNDEFINED,
             relativeUrl,
             myConsumer,
             info.getRepositoryRootURL()));
   } catch (SVNCancelException e) {
     //
   } catch (SVNException e) {
     myException = new VcsException(e);
   } catch (VcsException e) {
     myException = e;
   }
 }
    @Override
    protected void load() {
      String relativeUrl = myUrl;
      final SVNURL repoRootURL = myInfo.getRepositoryRootURL();

      final String root = repoRootURL.toString();
      if (myUrl != null && myUrl.startsWith(root)) {
        relativeUrl = myUrl.substring(root.length());
      }
      if (myPI != null) {
        myPI.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", myUrl));
      }
      final SVNRevision pegRevision = myInfo.getRevision();
      SVNLogClient client = myVcs.createLogClient();
      try {
        client.doLog(
            new File[] {new File(myFile.getIOFile().getAbsolutePath())},
            SVNRevision.HEAD,
            SVNRevision.create(1),
            SVNRevision.UNDEFINED,
            false,
            true,
            mySupport15,
            0,
            null,
            new MyLogEntryHandler(
                myVcs,
                myUrl,
                pegRevision,
                relativeUrl,
                myConsumer,
                repoRootURL,
                myFile.getCharset()));
      } catch (SVNCancelException e) {
        //
      } catch (SVNException e) {
        myException = new VcsException(e);
      } catch (VcsException e) {
        myException = e;
      }
    }
 @Nullable
 private VcsRevisionNumber getCurrentRevision(FilePath file) {
   if (file.isNonLocal()) {
     // technically, it does not make sense, since there's no "current" revision for non-local
     // history (if look how it's used)
     // but ok, lets keep it for now
     return new SvnRevisionNumber(SVNRevision.HEAD);
   }
   try {
     SVNWCClient wcClient = myVcs.createWCClient();
     SVNInfo info =
         wcClient.doInfo(new File(file.getPath()).getAbsoluteFile(), SVNRevision.UNDEFINED);
     if (info != null) {
       return new SvnRevisionNumber(info.getRevision());
     } else {
       return null;
     }
   } catch (SVNException e) {
     return null;
   }
 }
  private void analyzeFolder(File file) {
    try {
      LOG.debug("File:" + file.getPath());
      SVNInfo svnInfo = svnCln.getInfo(file);

      String lastCommitter = svnInfo.getAuthor();

      Date lastDateCommit = svnInfo.getCommittedDate();
      LOG.debug("lastDateCommit=" + lastDateCommit);

      long lastRev = svnInfo.getRevision().getNumber();
      assertEquals(99, lastRev);

      // Get SVNUrl
      LOG.debug("getChangelistName=" + svnInfo.getChangelistName());
      String svnUrl = svnInfo.getRepositoryRootURL().toDecodedString();

      assertEquals("http://svn.mkss.vn/svnobserver", svnUrl);

      scanFolder(new File(wcPath));
    } catch (SVNException ex) {
      // TODO Auto-generated catch block
      ex.printStackTrace();
    }
  }
  /** Test method for {@link svn.client.SVNClient#doCheckOut(java.util.Date)}. */
  @Test
  public void testGetWCInfo() {

    try {
      SVNWCClient wcCln = svnCln.getSVNWCClient();

      SVNInfo svnInfo = wcCln.doInfo(new File(this.wcPath), SVNRevision.HEAD);
      String lastCommitter = svnInfo.getAuthor();
      assertEquals("thach", lastCommitter);

      Date lastDateCommit = svnInfo.getCommittedDate();
      LOG.debug("lastDateCommit=" + lastDateCommit);
      assertNotNull(lastDateCommit);

      long lastRev = svnInfo.getRevision().getNumber();
      assertEquals(99, lastRev);

      // Get SVNUrl
      LOG.debug("getChangelistName=" + svnInfo.getChangelistName());
      String svnUrl = svnInfo.getRepositoryRootURL().toDecodedString();

      assertEquals("http://svn.mkss.vn/svnobserver", svnUrl);
      analyzeFolder(new File(wcPath));
    } catch (SVNException ex) {
      ex.printStackTrace();
      fail(ex.getMessage());
    }
  }
  @Test
  public void testGetInfo2() {
    DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
    SVNClientManager clientManager = SVNClientManager.newInstance(options, "", "");
    SVNWCClient wcClient = clientManager.getWCClient();

    /*
     * For using over http:// and https://
     */
    DAVRepositoryFactory.setup();

    // Create configuration file in current folder
    File configFile = new File(".rockysvn");
    String username = "******";
    String password = "******";
    ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager(configFile, username, password);
    // String url = "https://open-ones.googlecode.com/svn/trunk/ProjectList/RockySVN";
    String url = "https://hcm-svn.fsoft.fpt.vn/svn/F15-HCAM/trunk";

    SVNRevision revision = SVNRevision.HEAD;
    File path = new File("D:/Project/MyProject/Open-Ones/RockySVN");
    try {
      SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
      repository.setAuthenticationManager(authManager);
      repository.getDatedRevision(new Date());
      long latestRev = repository.getLatestRevision();

      assertEquals(634, latestRev);
      SVNInfo svnInfo = wcClient.doInfo(path, revision);
      assertEquals("ThachLN", svnInfo.getAuthor());
      assertEquals(123, svnInfo.getRevision().getID());
      assertEquals(new Date(), svnInfo.getRevision().getDate());
    } catch (SVNException ex) {
      ex.printStackTrace();
      fail(ex.getMessage());
    }
  }
  private void fillMapping(final SvnMapping mapping, final List<SvnCopyRootSimple> list) {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();

    for (SvnCopyRootSimple simple : list) {
      final VirtualFile copyRoot = lfs.findFileByIoFile(new File(simple.myCopyRoot));
      final VirtualFile vcsRoot = lfs.findFileByIoFile(new File(simple.myVcsRoot));

      if (copyRoot == null || vcsRoot == null) continue;

      final SvnVcs vcs = SvnVcs.getInstance(myProject);
      final SVNInfo svnInfo = vcs.getInfo(copyRoot);
      if ((svnInfo == null) || (svnInfo.getRepositoryRootURL() == null)) continue;

      final RootUrlInfo info =
          new RootUrlInfo(
              svnInfo.getRepositoryRootURL(),
              svnInfo.getURL(),
              SvnFormatSelector.getWorkingCopyFormat(svnInfo.getFile()),
              copyRoot,
              vcsRoot);
      mapping.add(info);
    }
  }
 private void collectLogEntriesForRepository(
     final ProgressIndicator indicator,
     FilePath file,
     final Consumer<VcsFileRevision> result,
     final Ref<Boolean> supports15Ref)
     throws SVNException, VcsException {
   final String url = file.getPath().replace('\\', '/');
   if (indicator != null) {
     indicator.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", url));
   }
   SVNWCClient wcClient = myVcs.createWCClient();
   final SVNURL svnurl = SVNURL.parseURIEncoded(url);
   SVNInfo info = wcClient.doInfo(svnurl, SVNRevision.UNDEFINED, SVNRevision.HEAD);
   final String root = info.getRepositoryRootURL().toString();
   String relativeUrl = url;
   if (url.startsWith(root)) {
     relativeUrl = url.substring(root.length());
   }
   SVNLogClient client = myVcs.createLogClient();
   final boolean supports15 = SvnUtil.checkRepositoryVersion15(myVcs, root);
   supports15Ref.set(supports15);
   // todo log in history provider
   client.doLog(
       svnurl,
       new String[] {},
       SVNRevision.UNDEFINED,
       SVNRevision.HEAD,
       SVNRevision.create(1),
       false,
       true,
       supports15,
       0,
       null,
       new RepositoryLogEntryHandler(
           myVcs, url, SVNRevision.UNDEFINED, relativeUrl, result, info.getRepositoryRootURL()));
 }
  private void collectLogEntries(
      final ProgressIndicator indicator,
      FilePath file,
      VcsException[] exception,
      final Consumer<VcsFileRevision> result,
      final Ref<Boolean> supports15Ref)
      throws SVNException, VcsException {
    SVNWCClient wcClient = myVcs.createWCClient();
    SVNInfo info =
        wcClient.doInfo(new File(file.getIOFile().getAbsolutePath()), SVNRevision.UNDEFINED);
    wcClient.setEventHandler(
        new ISVNEventHandler() {
          public void handleEvent(SVNEvent event, double progress) throws SVNException {}

          public void checkCancelled() throws SVNCancelException {
            indicator.checkCanceled();
          }
        });
    if (info == null || info.getRepositoryRootURL() == null) {
      exception[0] =
          new VcsException("File ''{0}'' is not under version control" + file.getIOFile());
      return;
    }
    final String url = info.getURL() == null ? null : info.getURL().toString();
    String relativeUrl = url;
    final SVNURL repoRootURL = info.getRepositoryRootURL();

    final String root = repoRootURL.toString();
    if (url != null && url.startsWith(root)) {
      relativeUrl = url.substring(root.length());
    }
    if (indicator != null) {
      indicator.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", url));
    }
    final SVNRevision pegRevision = info.getRevision();
    SVNLogClient client = myVcs.createLogClient();

    final boolean supports15 = SvnUtil.checkRepositoryVersion15(myVcs, url);
    supports15Ref.set(supports15);
    client.doLog(
        new File[] {new File(file.getIOFile().getAbsolutePath())},
        SVNRevision.HEAD,
        SVNRevision.create(1),
        SVNRevision.UNDEFINED,
        false,
        true,
        supports15,
        0,
        null,
        new MyLogEntryHandler(
            myVcs, url, pegRevision, relativeUrl, result, repoRootURL, file.getCharset()));
  }
 // return changed path, if any
 private FilePath tryStepByStep(
     final SvnRepositoryLocation svnRepositoryLocation,
     final SvnChangeList[] result,
     SVNLogClient logger,
     final SVNRevision revisionBefore,
     final SVNInfo info,
     SVNURL svnurl)
     throws VcsException {
   final String repositoryRoot = info.getRepositoryRootURL().toString();
   try {
     final RenameContext renameContext = new RenameContext(info);
     logger.doLog(
         svnurl,
         null,
         SVNRevision.UNDEFINED,
         SVNRevision.HEAD,
         revisionBefore,
         false,
         true,
         false,
         0,
         null,
         new ISVNLogEntryHandler() {
           public void handleLogEntry(SVNLogEntry logEntry) {
             if (myProject.isDisposed()) throw new ProcessCanceledException();
             if (logEntry.getDate() == null) {
               // do not add lists without info - this situation is possible for lists where there
               // are paths that user has no rights to observe
               return;
             }
             renameContext.accept(logEntry);
             if (logEntry.getRevision() == revisionBefore.getNumber()) {
               result[0] =
                   new SvnChangeList(myVcs, svnRepositoryLocation, logEntry, repositoryRoot);
             }
           }
         });
     return renameContext.getFilePath(myVcs);
   } catch (SVNException e) {
     LOG.info(e);
     throw new VcsException(e);
   }
 }
Example #19
0
  @Test
  public void testMixedWorkingRevisions() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);

    final File trunk = new File(myTempDirFixture.getTempDirPath(), "trunk");
    trunk.mkdir();
    Thread.sleep(100);
    final File folder = new File(trunk, "folder");
    folder.mkdir();
    Thread.sleep(100);
    final File f1 = new File(folder, "f1.txt");
    f1.createNewFile();
    new File(folder, "f2.txt").createNewFile();
    Thread.sleep(100);

    verify(runSvn("import", "-m", "test", trunk.getAbsolutePath(), myRepoUrl + "/trunk"));
    verify(runSvn("copy", "-m", "test", myRepoUrl + "/trunk", myRepoUrl + "/branch"));

    FileUtil.delete(trunk);
    verify(runSvn("co", myRepoUrl + "/trunk", trunk.getAbsolutePath()));
    verify(runSvn("co", myRepoUrl + "/branch", myBranchVcsRoot.getAbsolutePath()));

    // rev 3
    final VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f1);
    editFileInCommand(myProject, vf, "123\n456\n123");
    Thread.sleep(100);
    verify(runSvn("ci", "-m", "test", trunk.getAbsolutePath()));

    // rev 4: record non inheritable merge
    verify(runSvn("propset", "svn:mergeinfo", "/trunk:3", myBranchVcsRoot.getAbsolutePath()));
    Thread.sleep(100);
    verify(runSvn("ci", "-m", "test", myBranchVcsRoot.getAbsolutePath()));

    Thread.sleep(100);
    // ! no update!

    final SvnVcs vcs = SvnVcs.getInstance(myProject);
    final SVNWCClient wcClient = vcs.createWCClient();
    final SVNPropertyData data =
        wcClient.doGetProperty(
            myBranchVcsRoot, "svn:mergeinfo", SVNRevision.UNDEFINED, SVNRevision.WORKING);
    assert data != null
        && data.getValue() != null
        && "/trunk:3".equals(data.getValue().getString());

    final SVNInfo f1info =
        wcClient.doInfo(new File(myBranchVcsRoot, "folder/f1.txt"), SVNRevision.WORKING);
    assert f1info.getRevision().getNumber() == 2;

    final CommittedChangesProvider<SvnChangeList, ChangeBrowserSettings> committedChangesProvider =
        vcs.getCommittedChangesProvider();
    final List<SvnChangeList> changeListList =
        committedChangesProvider.getCommittedChanges(
            committedChangesProvider.createDefaultSettings(),
            new SvnRepositoryLocation(myRepoUrl + "/trunk"),
            0);

    final SvnChangeList changeList = changeListList.get(0);
    final String encodedRepoUrl = SVNURL.parseURIDecoded(myRepoUrl).toString();
    final BranchInfo branchInfo =
        new BranchInfo(
            vcs,
            encodedRepoUrl,
            encodedRepoUrl + "/branch",
            encodedRepoUrl + "/trunk",
            encodedRepoUrl + "/trunk",
            vcs.createWCClient());
    SvnMergeInfoCache.MergeCheckResult result =
        branchInfo.checkList(changeList, myBranchVcsRoot.getAbsolutePath());
    assert SvnMergeInfoCache.MergeCheckResult.NOT_MERGED.equals(result);

    // and after update
    verify(runSvn("up", myBranchVcsRoot.getAbsolutePath()));
    Thread.sleep(100);

    branchInfo.clear();
    result = branchInfo.checkList(changeList, myBranchVcsRoot.getAbsolutePath());
    assert SvnMergeInfoCache.MergeCheckResult.MERGED.equals(result);
  }
 private RenameContext(final SVNInfo info) {
   myRepositoryRoot = info.getRepositoryRootURL().toString();
   myCurrentPath = SVNPathUtil.getRelativePath(myRepositoryRoot, info.getURL().toString());
   myCurrentPath = myCurrentPath.startsWith("/") ? myCurrentPath : ("/" + myCurrentPath);
 }
  @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));
  }
 /**
  * Gets the <i>'.prej'</i> file containing details on properties conflicts. If the item's
  * properties are in conflict with those that came during an update this file will contain a
  * conflict description.
  *
  * @return the properties conflicts file
  */
 @Override
 public File getPropRejectFile() {
   if (!isConflicted()) return null;
   final SVNInfo info = initInfo();
   return info == null ? null : info.getPropConflictFile();
 }
 /**
  * Gets the revision of the item's ancestor from which the item was copied (the item is added with
  * history).
  *
  * @return the ancestor's revision
  */
 @Override
 public SVNRevision getCopyFromRevision() {
   if (!isCopied()) return null;
   final SVNInfo info = initInfo();
   return info == null ? null : info.getCopyFromRevision();
 }
 /**
  * Returns a tree conflict description.
  *
  * @return tree conflict description; <code>null</code> if no conflict description exists on this
  *     item
  * @since 1.3
  */
 @Override
 public SVNTreeConflictDescription getTreeConflict() {
   if (!isConflicted()) return null;
   final SVNInfo info = initInfo();
   return info == null ? null : info.getTreeConflict();
 }