public static long[] getRangeEndPoints(Map mergeInfo) { // long[] { youngestRange, oldestRange } long[] rangePoints = {SVNRepository.INVALID_REVISION, SVNRepository.INVALID_REVISION}; if (mergeInfo != null) { for (Iterator mergeInfoIter = mergeInfo.keySet().iterator(); mergeInfoIter.hasNext(); ) { String path = (String) mergeInfoIter.next(); SVNMergeRangeList rangeList = (SVNMergeRangeList) mergeInfo.get(path); if (!rangeList.isEmpty()) { SVNMergeRange[] ranges = rangeList.getRanges(); SVNMergeRange range = ranges[ranges.length - 1]; if (!SVNRevision.isValidRevisionNumber(rangePoints[0]) || range.getEndRevision() > rangePoints[0]) { rangePoints[0] = range.getEndRevision(); } range = ranges[0]; if (!SVNRevision.isValidRevisionNumber(rangePoints[1]) || rangePoints[1] > range.getStartRevision()) { rangePoints[1] = range.getStartRevision(); } } } } return rangePoints; }
/** * Parses an input string and be it a representation of either a revision number, or a timestamp, * or a revision keyword, constructs an <b>SVNRevision</b> representation of the revision. * * @param value a string to be parsed * @return an <b>SVNRevision</b> object that holds the revision information parsed from <code> * value</code>; however if an input string is not a valid one which can be successfully * transformed to an <b>SVNRevision</b> the return value is {@link SVNRevision#UNDEFINED} */ public static SVNRevision parse(String value) { if (value == null) { return SVNRevision.UNDEFINED; } if (value.startsWith("-r")) { value = value.substring("-r".length()); } value = value.trim(); if (value.startsWith("{") && value.endsWith("}")) { value = value.substring(1); value = value.substring(0, value.length() - 1); try { Date date = DateFormat.getDateInstance().parse(value); return SVNRevision.create(date); } catch (ParseException e) { return SVNRevision.UNDEFINED; } } try { long number = Long.parseLong(value); return SVNRevision.create(number); } catch (NumberFormatException nfe) { } SVNRevision revision = (SVNRevision) ourValidRevisions.get(value.toUpperCase()); if (revision == null) { return UNDEFINED; } return revision; }
@Nullable private String getLastMergedRevision(final SVNRevision rev2, final SVNURL svnURL2) { if (!rev2.isValid() || rev2.isLocal()) { return null; } else { final long number = rev2.getNumber(); if (number > 0) { return String.valueOf(number); } else { SVNRepository repos = null; try { repos = myVcs.createRepository(svnURL2.toString()); final long latestRev = repos.getLatestRevision(); return String.valueOf(latestRev); } catch (SVNException e) { return null; } finally { if (repos != null) { repos.closeSession(); } } } } }
@Override public void execute(final SmtpMessage message) throws IOException { final SVNWCClient svnWCClient = svnClientManager.getWCClient(); try { final SVNPropertyData svnPropData = svnWCClient.doGetProperty( svnRepositoryURL, propName, SVNRevision.create(revision), SVNRevision.create(revision)); LOG.info( "PROPCHANGE: getName()=" + svnPropData.getName() + " getValue()=" + svnPropData.getValue()); System.out.println(svnPropData.getName() + ":" + svnPropData.getValue()); // TODO write the prop change to the OutputStream // TODO dont forget old prop value } catch (final SVNException se) { throw new IOException("SVN communication error: " + se.getMessage(), se); } }
static { ourValidRevisions.put(HEAD.getName(), HEAD); ourValidRevisions.put(WORKING.getName(), WORKING); ourValidRevisions.put(PREVIOUS.getName(), PREVIOUS); ourValidRevisions.put(BASE.getName(), BASE); ourValidRevisions.put(COMMITTED.getName(), COMMITTED); }
@Nullable @Override public VcsRevisionNumber parseRevisionNumber(final String revisionNumberString) { final SVNRevision revision = SVNRevision.parse(revisionNumberString); if (revision.equals(SVNRevision.UNDEFINED)) { return null; } return new SvnRevisionNumber(revision); }
/** Cuts off any optional '@revisionnr' from the end of the url string. */ public static String getUrlWithoutRevision(String remoteUrlPossiblyWithRevision) { int idx = remoteUrlPossiblyWithRevision.lastIndexOf('@'); int slashIdx = remoteUrlPossiblyWithRevision.lastIndexOf('/'); if (idx > 0 && idx > slashIdx) { String n = remoteUrlPossiblyWithRevision.substring(idx + 1); SVNRevision r = SVNRevision.parse(n); if ((r != null) && (r.isValid())) { return remoteUrlPossiblyWithRevision.substring(0, idx); } } return remoteUrlPossiblyWithRevision; }
@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(); }
/** * Compares this object with another <b>SVNRevision</b> object. * * @param o an object to be compared with; if it's not an <b>SVNRevision</b> then this method * certainly returns <span class="javakeyword">false</span> * @return <span class="javakeyword">true</span> if equal, otherwise <span * class="javakeyword">false</span> */ public boolean equals(Object o) { if (o == null || o.getClass() != SVNRevision.class) { return false; } SVNRevision r = (SVNRevision) o; if (myRevision >= 0) { return myRevision == r.getNumber(); } else if (myDate != null) { return myDate.equals(r.getDate()); } else if (myName != null) { return myName.equals(r.getName()); } return !r.isValid(); }
public byte[] loadContent() throws IOException, VcsException { ContentLoader loader = new ContentLoader(myURL, myRevision, myPegRevision); if (ApplicationManager.getApplication().isDispatchThread() && !myRevision.isLocal()) { ProgressManager.getInstance() .runProcessWithProgressSynchronously( loader, SvnBundle.message("progress.title.loading.file.content"), false, myVCS.getProject()); } else { loader.run(); } VcsException exception = loader.getException(); if (exception == null) { final byte[] contents = loader.getContents(); ContentRevisionCache.checkContentsSize(myURL, contents.length); return contents; } else { LOG.info( "Failed to load file '" + myURL + "' content at revision: " + myRevision + "\n" + exception.getMessage(), exception); throw exception; } }
private boolean buildModule(String url, SVNLogClient svnlc, SVNXMLLogHandler logHandler) throws IOException2 { PrintStream logger = listener.getLogger(); Long prevRev = previousRevisions.get(url); if (prevRev == null) { logger.println("no revision recorded for " + url + " in the previous build"); return false; } Long thisRev = thisRevisions.get(url); if (thisRev == null) { listener.error( "No revision found for URL: " + url + " in " + SubversionSCM.getRevisionFile(build) + ". Revision file contains: " + thisRevisions.keySet()); return false; } if (thisRev.equals(prevRev)) { logger.println("no change for " + url + " since the previous build"); return false; } try { if (debug) listener .getLogger() .printf( "Computing changelog of %1s from %2s to %3s\n", SVNURL.parseURIEncoded(url), prevRev + 1, thisRev); svnlc.doLog( SVNURL.parseURIEncoded(url), null, SVNRevision.UNDEFINED, SVNRevision.create(prevRev + 1), SVNRevision.create(thisRev), false, // Don't stop on copy. true, // Report paths. 0, // Retrieve log entries for unlimited number of revisions. debug ? new DebugSVNLogHandler(logHandler) : logHandler); if (debug) listener.getLogger().println("done"); } catch (SVNException e) { throw new IOException2("revision check failed on " + url, e); } return true; }
@Override protected void updateStatus(Attributes attributes, PortableStatus status, Lock.Builder lock) throws SAXException { final String revision = attributes.getValue("revision"); if (!StringUtil.isEmpty(revision)) { status.setCommittedRevision(SVNRevision.create(Long.valueOf(revision))); } }
/** * Method getSelectedRevisions * * @return */ public List<SVNRevisionRange> getSelectedRevisions() { List<SVNRevisionRange> revisions = new LinkedList<SVNRevisionRange>(); if ((jTable1.getSelectedRowCount() == 0) || (jTable1.getSelectedRowCount() == jTable1.getRowCount())) { revisions.add( new SVNRevisionRange(SVNRevision.create(minRevision), SVNRevision.create(maxRevision))); } else { for (int i : jTable1.getSelectedRows()) { int selected = jTable1.getRowSorter().convertRowIndexToModel(i); long r = data.get(selected).getRevision(); revisions.add(new SVNRevisionRange(SVNRevision.create(r - 1), SVNRevision.create(r))); } } return revisions; }
/** * Gets the revision from a remote URL - i.e. the part after '@' if any * * @return the revision or null */ private static SVNRevision getRevisionFromRemoteUrl(String remoteUrlPossiblyWithRevision) { int idx = remoteUrlPossiblyWithRevision.lastIndexOf('@'); int slashIdx = remoteUrlPossiblyWithRevision.lastIndexOf('/'); if (idx > 0 && idx > slashIdx) { String n = remoteUrlPossiblyWithRevision.substring(idx + 1); return SVNRevision.parse(n); } return null; }
protected SvnFileRevision createRevision(final SVNLogEntry logEntry, final String copyPath) throws SVNException { Date date = logEntry.getDate(); String author = logEntry.getAuthor(); String message = logEntry.getMessage(); SVNRevision rev = SVNRevision.create(logEntry.getRevision()); final SVNURL url = myRepositoryRoot.appendPath(myLastPath, true); return new SvnFileRevision( myVcs, myPegRevision, rev, url.toString(), author, date, message, copyPath, myCharset); }
private int compareRevisions( @NonNls final SVNRevision revision1, @NonNls final SVNRevision revision2) { if (revision1.equals(revision2)) { return 0; } // working(local) ahead of head if (SVNRevision.WORKING.equals(revision1)) { return 1; } if (SVNRevision.WORKING.equals(revision2)) { return -1; } if (SVNRevision.HEAD.equals(revision1)) { return 1; } if (SVNRevision.HEAD.equals(revision2)) { return -1; } return revision1.getNumber() > revision2.getNumber() ? 1 : -1; }
private File dump(SVNURL url) throws SVNException { final File repositoryRoot = new File(url.getPath()); final SVNAdminClient adminClient = SVNClientManager.newInstance().getAdminClient(); adminClient.doDump( repositoryRoot, SVNDebugLog.getDefaultLog().createOutputLogStream(), SVNRevision.create(0), SVNRevision.HEAD, false, false); return repositoryRoot; }
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())); }
private String getPatch(long revA, long revB) throws SVNException, UnsupportedEncodingException { // Prepare required arguments. SVNURL svnURL = SVNURL.fromFile(getDirectory()); // Get diffClient. SVNClientManager clientManager = SVNClientManager.newInstance(); SVNDiffClient diffClient = clientManager.getDiffClient(); // Using diffClient, write the changes by commitId into // byteArrayOutputStream, as unified format. ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); diffClient.doDiff( svnURL, null, SVNRevision.create(revA), SVNRevision.create(revB), SVNDepth.INFINITY, true, byteArrayOutputStream); return byteArrayOutputStream.toString(Config.getCharset().name()); }
public SvnFileRevision( SvnVcs vcs, SVNRevision pegRevision, LogEntry logEntry, String url, String copyFromPath) { final SVNRevision revision = SVNRevision.create(logEntry.getRevision()); myRevisionNumber = new SvnRevisionNumber(revision); myPegRevision = pegRevision; myRevision = revision; myAuthor = logEntry.getAuthor(); myDate = logEntry.getDate(); myCommitMessage = logEntry.getMessage(); myCopyFromPath = copyFromPath; myVCS = vcs; myURL = url; myMergeSources = new ArrayList<>(); }
public void mergeNext() throws SVNException, VcsException { myAtStart = false; File destination = new File(myTargetPath); MergeClient client = myVcs.getFactory(destination).createMergeClient(); if (myReintegrate) { client.merge( SvnTarget.fromURL(mySourceUrl), destination, false, createDiffOptions(), myHandler); } else { client.merge( SvnTarget.fromURL(mySourceUrl, SVNRevision.create(mySourceCopyRevision)), SvnTarget.fromURL(mySourceUrl, SVNRevision.create(mySourceLatestRevision)), destination, SVNDepth.INFINITY, true, false, false, true, createDiffOptions(), myHandler); } }
@Override public String getPatch(String commitId) throws SVNException { // Prepare required arguments. SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName)); long rev = Integer.parseInt(commitId); // Get diffClient. SVNClientManager clientManager = SVNClientManager.newInstance(); SVNDiffClient diffClient = clientManager.getDiffClient(); // Using diffClient, write the changes by commitId into // byteArrayOutputStream, as unified format. ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); diffClient.doDiff( svnURL, null, SVNRevision.create(rev - 1), SVNRevision.create(rev), SVNDepth.INFINITY, true, byteArrayOutputStream); return byteArrayOutputStream.toString(); }
private static Pair<SVNRevision, SVNURL> createRemoteFolder( final SvnVcs17 vcs, final SVNURL parent, final String folderName) throws SVNException { SVNURL url = parent.appendPath(folderName, false); final String urlText = url.toString(); final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null) { indicator.checkCanceled(); indicator.setText(SvnBundle.message("share.directory.create.dir.progress.text", urlText)); } final SVNCommitInfo info = vcs.createCommitClient() .doMkDir( new SVNURL[] {url}, SvnBundle.message( "share.directory.commit.message", folderName, ApplicationNamesInfo.getInstance().getFullProductName())); return new Pair<SVNRevision, SVNURL>(SVNRevision.create(info.getNewRevision()), url); }
@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(); final SvnTarget target = SvnTarget.fromFile(myFile.getIOFile(), myPeg); try { myVcs .getFactory(target) .createHistoryClient() .doLog( target, myFrom == null ? SVNRevision.HEAD : myFrom, myTo == null ? SVNRevision.create(1) : myTo, false, true, myShowMergeSources && mySupport15, myLimit + 1, null, new MyLogEntryHandler( myVcs, myUrl, pegRevision, relativeUrl, createConsumerAdapter(myConsumer), repoRootURL, myFile.getCharset())); } catch (SVNCancelException e) { // } catch (SVNException e) { myException = new VcsException(e); } catch (VcsException e) { myException = e; } }
private void loadBackwards(SVNURL svnurl) throws SVNException, VcsException { // this method is called when svnurl does not exist in latest repository revision - thus // concrete old revision is used for "info" // command to get repository url Info info = myVcs.getInfo(svnurl, myPeg, myPeg); final SVNURL rootURL = info != null ? info.getRepositoryRootURL() : null; final String root = rootURL != null ? rootURL.toString() : ""; String relativeUrl = myUrl; if (myUrl.startsWith(root)) { relativeUrl = myUrl.substring(root.length()); } final RepositoryLogEntryHandler repositoryLogEntryHandler = new RepositoryLogEntryHandler( myVcs, myUrl, SVNRevision.UNDEFINED, relativeUrl, new ThrowableConsumer<VcsFileRevision, SVNException>() { @Override public void consume(VcsFileRevision revision) throws SVNException { myConsumer.consume(revision); } }, rootURL); repositoryLogEntryHandler.setThrowCancelOnMeetPathCreation(true); SvnTarget target = SvnTarget.fromURL(rootURL, myFrom); myVcs .getFactory(target) .createHistoryClient() .doLog( target, myFrom, myTo == null ? SVNRevision.create(1) : myTo, false, true, myShowMergeSources && mySupport15, 1, null, repositoryLogEntryHandler); }
@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 updateStatus(Attributes attributes, PortableStatus status, Lock.Builder lock) throws SAXException { final StatusType propertiesStatus = parsePropertiesStatus(attributes); status.setPropertiesStatus(propertiesStatus); final StatusType contentsStatus = parseContentsStatus(attributes); status.setContentsStatus(contentsStatus); if (StatusType.STATUS_CONFLICTED.equals(propertiesStatus) || StatusType.STATUS_CONFLICTED.equals(contentsStatus)) { status.setIsConflicted(true); } // optional final String locked = attributes.getValue("wc-locked"); if (locked != null && Boolean.parseBoolean(locked)) { status.setIsLocked(true); } final String copied = attributes.getValue("copied"); if (copied != null && Boolean.parseBoolean(copied)) { status.setIsCopied(true); } final String treeConflicted = attributes.getValue("tree-conflicted"); if (treeConflicted != null && Boolean.parseBoolean(treeConflicted)) { status.setIsConflicted(true); } final String switched = attributes.getValue("switched"); if (switched != null && Boolean.parseBoolean(switched)) { status.setIsSwitched(true); } final String revision = attributes.getValue("revision"); if (!StringUtil.isEmptyOrSpaces(revision)) { try { final long number = Long.parseLong(revision); status.setRevision(SVNRevision.create(number)); } catch (NumberFormatException e) { throw new SAXException(e); } } }
/** * 将svn上removePath路径下的内容导出到本地的localPath路径下 支持文件下载及目录导出 * * @param svnClientManager svn客户端操作对象 * @param remotePath svn远程目录 * @param revision 目标版本 * @param localPath 本地保存目录 */ public static void export( SVNClientManager svnClientManager, String remotePath, long revision, String localPath) throws Exception { File localF = new File(localPath); if (!localF.exists()) { localF.mkdirs(); } else { FileUtils.cleanDirectory(localF); } SVNUpdateClient svnUpdateClient = svnClientManager.getUpdateClient(); svnUpdateClient.doExport( SVNURL.parseURIEncoded(Constants.CRS_REPOS + remotePath), new File(localPath), SVNRevision.HEAD, SVNRevision.create(revision), null, true, SVNDepth.INFINITY); }
@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; } }
@Override public void run(ContinuationContext context) { final SvnContentRevision base = SvnContentRevision.createBaseRevision( myVcs, myNewFilePath, myCommittedRevision.getRevision()); final SvnContentRevision remote = SvnContentRevision.createRemote( myVcs, myOldFilePath, SVNRevision.create(myDescription.getSourceRightVersion().getPegRevision())); try { final ContentRevision newBase = new SimpleContentRevision( base.getContent(), myNewFilePath, base.getRevisionNumber().asString()); final ContentRevision newRemote = new SimpleContentRevision( remote.getContent(), myNewFilePath, remote.getRevisionNumber().asString()); myTheirsChanges.add(new Change(newBase, newRemote)); } catch (VcsException e) { context.handleException(e, true); } }