public long getFile(String path, long revision, Map properties, OutputStream contents) throws SVNException { Long rev = revision > 0 ? new Long(revision) : null; try { openConnection(); Object[] buffer = new Object[] { "get-file", getRepositoryPath(path), rev, Boolean.valueOf(properties != null), Boolean.valueOf(contents != null) }; write("(w(s(n)ww))", buffer); authenticate(); buffer[2] = properties; buffer = read("[((?S)N(*P))]", buffer, true); if (properties != null) { properties.put(SVNProperty.REVISION, buffer[1].toString()); properties.put(SVNProperty.CHECKSUM, buffer[0].toString()); } if (contents != null) { Object[] buffer2 = new Object[] {contents}; read("*I", buffer2, true); read("[()]", buffer2, true); } return SVNReader.getLong(buffer, 1); } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } }
public long getDir(String path, long revision, Map properties, final ISVNDirEntryHandler handler) throws SVNException { Long rev = getRevisionObject(revision); try { openConnection(); String fullPath = getFullPath(path); final SVNURL url = getLocation().setPath(fullPath, false); path = getRepositoryPath(path); Object[] buffer = new Object[] { "get-dir", path, rev, Boolean.valueOf(properties != null), Boolean.valueOf(handler != null) }; write("(w(s(n)ww))", buffer); authenticate(); buffer[1] = properties; buffer = read("[(N(*P)", buffer, true); revision = buffer[0] != null ? SVNReader.getLong(buffer, 0) : revision; ISVNDirEntryHandler nestedHandler = new ISVNDirEntryHandler() { public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException { handler.handleDirEntry( new SVNDirEntry( url.appendPath(dirEntry.getName(), false), dirEntry.getName(), dirEntry.getKind(), dirEntry.getSize(), dirEntry.hasProperties(), dirEntry.getRevision(), dirEntry.getDate(), dirEntry.getAuthor())); } }; if (handler != null) { buffer[0] = nestedHandler; read("(*D)))", buffer, true); } else { read("()))", null, true); } } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } return revision; }
public int getLocations( String path, long pegRevision, long[] revisions, ISVNLocationEntryHandler handler) throws SVNException { assertValidRevision(pegRevision); for (int i = 0; i < revisions.length; i++) { assertValidRevision(revisions[i]); } int count = 0; try { openConnection(); path = getRepositoryPath(path); Object[] buffer = new Object[] {"get-locations", path, getRevisionObject(pegRevision), revisions}; write("(w(sn(*n)))", buffer); authenticate(); while (true) { try { read("(NS)", buffer, false); } catch (SVNException e) { break; } count++; if (handler != null) { long revision = SVNReader.getLong(buffer, 0); String location = SVNReader.getString(buffer, 1); if (location != null) { handler.handleLocationEntry(new SVNLocationEntry(revision, location)); } } } read("x", buffer, true); read("[()]", buffer, true); } catch (SVNException e) { closeSession(); handleUnsupportedCommand(e, "'get-locations' not implemented"); } finally { closeConnection(); } return count; }
public long getLatestRevision() throws SVNException { Object[] buffer = new Object[] {"get-latest-rev"}; try { openConnection(); write("(w())", buffer); authenticate(); buffer = read("[(N)]", buffer, true); } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } return SVNReader.getLong(buffer, 0); }
public long getDatedRevision(Date date) throws SVNException { if (date == null) { date = new Date(System.currentTimeMillis()); } Object[] buffer = new Object[] {"get-dated-rev", date}; try { openConnection(); write("(w(s))", buffer); authenticate(); buffer = read("[(N)]", buffer, true); } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } return SVNReader.getLong(buffer, 0); }
public long log( String[] targetPaths, long startRevision, long endRevision, boolean changedPaths, boolean strictNode, long limit, ISVNLogEntryHandler handler) throws SVNException { long count = 0; long latestRev = -1; if (isInvalidRevision(startRevision)) { startRevision = latestRev = getLatestRevision(); } if (isInvalidRevision(endRevision)) { endRevision = latestRev != -1 ? latestRev : getLatestRevision(); } try { openConnection(); String[] repositoryPaths = getRepositoryPaths(targetPaths); if (repositoryPaths == null || repositoryPaths.length == 0) { repositoryPaths = new String[] {""}; } Object[] buffer = new Object[] { "log", repositoryPaths, getRevisionObject(startRevision), getRevisionObject(endRevision), Boolean.valueOf(changedPaths), Boolean.valueOf(strictNode), limit > 0 ? new Long(limit) : null }; write("(w((*s)(n)(n)wwn))", buffer); authenticate(); while (true) { try { read("((", buffer, false); Map changedPathsMap = null; if (changedPaths) { changedPathsMap = handler != null ? new HashMap() : null; while (true) { try { read("(SW(?S?N))", buffer, false); if (changedPathsMap != null) { String path = SVNReader.getString(buffer, 0); if (path != null && !"".equals(path.trim())) { String type = SVNReader.getString(buffer, 1); String copyPath = SVNReader.getString(buffer, 2); long copyRev = SVNReader.getLong(buffer, 3); changedPathsMap.put( path, new SVNLogEntryPath(path, type.charAt(0), copyPath, copyRev)); } } } catch (SVNException e) { break; } } } read(")N(?S)(?S)(?S))", buffer, false); count++; if (handler != null && (limit <= 0 || count <= limit)) { long revision = SVNReader.getLong(buffer, 0); String author = SVNReader.getString(buffer, 1); Date date = SVNReader.getDate(buffer, 2); String message = SVNReader.getString(buffer, 3); // remove all handler.handleLogEntry( new SVNLogEntry(changedPathsMap, revision, author, date, message)); } } catch (SVNException e) { if (e instanceof SVNCancelException || e instanceof SVNAuthenticationException) { throw e; } read("x", buffer, true); if (limit <= 0 || (limit > 0 && count <= limit)) { read("[()]", buffer, true); } return count; } } } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } }
public int getFileRevisions( String path, long sRevision, long eRevision, ISVNFileRevisionHandler handler) throws SVNException { Long srev = getRevisionObject(sRevision); Long erev = getRevisionObject(eRevision); int count = 0; SVNDeltaReader deltaReader = new SVNDeltaReader(); try { openConnection(); Object[] buffer = new Object[] {"get-file-revs", getRepositoryPath(path), srev, erev}; write("(w(s(n)(n)))", buffer); authenticate(); buffer = new Object[5]; while (true) { SVNFileRevision fileRevision = null; boolean skipDelta = false; try { buffer = read("(SN(*P)(*Z)?S", buffer, false); if (buffer[4] != null && ((String) buffer[4]).length() == 0) { buffer[4] = null; skipDelta = true; } else { read(")", null, false); } count++; } catch (SVNException e) { read("x", buffer, true); read("[()]", buffer, true); return count; } String name = null; if (handler != null) { name = (String) buffer[0]; long revision = SVNReader.getLong(buffer, 1); Map properties = SVNReader.getMap(buffer, 2); Map propertiesDelta = SVNReader.getMap(buffer, 3); if (name != null) { fileRevision = new SVNFileRevision(name, revision, properties, propertiesDelta); } buffer[2] = null; buffer[3] = null; } if (handler != null && fileRevision != null) { handler.openRevision(fileRevision); } if (skipDelta) { if (handler != null) { handler.closeRevision(name == null ? path : name); } continue; } boolean windowRead = false; while (true) { byte[] line = (byte[]) read("?W?B", buffer, true)[1]; if (line == null) { // may be failure read("[]", buffer, true); break; } else if (line.length == 0) { // empty line, delta end. break; } // apply delta here. if (!windowRead) { if (handler != null) { handler.applyTextDelta(name == null ? path : name, null); windowRead = true; } } deltaReader.nextWindow(line, 0, line.length, name == null ? path : name, handler); } deltaReader.reset(name == null ? path : name, handler); if (windowRead) { handler.textDeltaEnd(name == null ? path : name); } if (handler != null) { handler.closeRevision(name == null ? path : name); } } } catch (SVNException e) { closeSession(); handleUnsupportedCommand(e, "'get-file-revs' not implemented"); } finally { closeConnection(); } return -1; }
public SVNDirEntry getDir( String path, long revision, boolean includeComment, final Collection entries) throws SVNException { Long rev = getRevisionObject(revision); // convert path to path relative to repos root. SVNDirEntry parentEntry = null; try { openConnection(); final SVNURL url = getLocation().setPath(getFullPath(path), false); ISVNDirEntryHandler handler = new ISVNDirEntryHandler() { public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException { dirEntry = new SVNDirEntry( url.appendPath(dirEntry.getName(), false), dirEntry.getName(), dirEntry.getKind(), dirEntry.getSize(), dirEntry.hasProperties(), dirEntry.getRevision(), dirEntry.getDate(), dirEntry.getAuthor()); entries.add(dirEntry); } }; path = getRepositoryPath(path); // get parent Object[] buffer = new Object[] {"stat", path, getRevisionObject(revision)}; write("(w(s(n)))", buffer); authenticate(); read("[((?F))]", buffer, true); parentEntry = (SVNDirEntry) buffer[0]; parentEntry = new SVNDirEntry( url, "", parentEntry.getKind(), parentEntry.getSize(), parentEntry.hasProperties(), parentEntry.getRevision(), parentEntry.getDate(), parentEntry.getAuthor()); // get entries. buffer = new Object[] {"get-dir", path, rev, Boolean.FALSE, Boolean.TRUE}; write("(w(s(n)ww))", buffer); authenticate(); buffer = read("[(N(*P)", buffer, true); revision = buffer[0] != null ? SVNReader.getLong(buffer, 0) : revision; if (handler != null) { buffer[0] = handler; read("(*D)))", buffer, true); } else { read("()))", null, true); } // get comments. if (includeComment) { Map messages = new HashMap(); for (Iterator ents = entries.iterator(); ents.hasNext(); ) { SVNDirEntry entry = (SVNDirEntry) ents.next(); Long key = getRevisionObject(entry.getRevision()); if (messages.containsKey(key)) { entry.setCommitMessage((String) messages.get(key)); continue; } buffer = new Object[] {"rev-prop", key, SVNRevisionProperty.LOG}; write("(w(ns))", buffer); authenticate(); buffer = read("[((?S))]", buffer, true); messages.put(key, buffer[0]); entry.setCommitMessage((String) buffer[0]); } } } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } return parentEntry; }