@Override public List<Commit> getHistory(int page, int limit, String until) throws AmbiguousObjectException, IOException, NoHeadException, GitAPIException, SVNException { // Get the repository SVNURL svnURL = SVNURL.fromFile(new File(repoPrefix + ownerName + "/" + projectName)); org.tmatesoft.svn.core.io.SVNRepository repository = SVNRepositoryFactory.create(svnURL); // path to get log String[] paths = {"/"}; // Determine revisions long startRevision = repository.getLatestRevision() - page * limit; long endRevision = startRevision - limit; if (endRevision < 1) { endRevision = 1; } // No log to return. if (startRevision < endRevision) { return new ArrayList<>(); } // Get the logs List<Commit> result = new ArrayList<>(); for (Object entry : repository.log(paths, null, startRevision, endRevision, false, false)) { result.add(new SvnCommit((SVNLogEntry) entry)); } return result; }
public VCSModule(final String url) { try { this.url = SVNURL.fromFile(new File(url)); this.authManager = SVNWCUtil.createDefaultAuthenticationManager("", ""); this.repository = SVNRepositoryFactory.create(this.url); this.repository.setAuthenticationManager(this.authManager); this.latestRevision = this.repository.getLatestRevision(); } catch (final SVNException e) { e.printStackTrace(); } }
@Override public Commit getCommit(String revNumber) throws IOException, SVNException { long rev = Integer.parseInt(revNumber); String[] paths = {"/"}; SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName)); org.tmatesoft.svn.core.io.SVNRepository repository = SVNRepositoryFactory.create(svnURL); for (Object entry : repository.log(paths, null, rev, rev, false, false)) { return new SvnCommit((SVNLogEntry) entry); } return null; }
@Override public boolean isEmpty() { SVNURL svnURL; org.tmatesoft.svn.core.io.SVNRepository repository = null; try { svnURL = SVNURL.fromFile(getDirectory()); repository = SVNRepositoryFactory.create(svnURL); return repository.getLatestRevision() == 0; } catch (SVNException e) { throw new RuntimeException(e); } finally { if (repository != null) { repository.closeSession(); } } }
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()); }
@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 org.tmatesoft.svn.core.io.SVNRepository getSVNRepository() throws SVNException { SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName)); return SVNRepositoryFactory.create(svnURL); }
private org.tmatesoft.svn.core.io.SVNRepository getSVNRepository() throws SVNException { SVNURL svnURL = SVNURL.fromFile(getDirectory()); return SVNRepositoryFactory.create(svnURL); }
/** * Pass the absolute path of the base directory where all example data will be created in arg[0]. * The sample will create: * * <p>- arg[0]/exampleRepository - repository with some test data - arg[0]/exampleWC - working * copy checked out from exampleRepository */ public static void main(String[] args) { // initialize SVNKit to work through file:/// protocol SamplesUtility.initializeFSFSprotocol(); File baseDirectory = new File(args[0]); File reposRoot = new File(baseDirectory, "exampleRepository"); File wcRoot = new File(baseDirectory, "exampleWC"); try { // first create a repository and fill it with data SamplesUtility.createRepository(reposRoot); SVNCommitInfo info = SamplesUtility.createRepositoryTree(reposRoot); // print out new revision info System.out.println(info); SVNClientManager clientManager = SVNClientManager.newInstance(); clientManager.setEventHandler(new EventHandler()); SVNURL reposURL = SVNURL.fromFile(reposRoot); // copy A to A_copy in repository (url-to-url copy) SVNCopyClient copyClient = clientManager.getCopyClient(); SVNURL A_URL = reposURL.appendPath("A", true); SVNURL copyTargetURL = reposURL.appendPath("A_copy", true); SVNCopySource copySource = new SVNCopySource(SVNRevision.UNDEFINED, SVNRevision.HEAD, A_URL); info = copyClient.doCopy( new SVNCopySource[] {copySource}, copyTargetURL, false, false, true, "copy A to A_copy", null); // print out new revision info System.out.println(info); // checkout the entire repository tree SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot); // now make some changes to the A tree SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true); SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false); SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient(); wcClient.doSetProperty( new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false, SVNDepth.EMPTY, null, null); // commit local changes SVNCommitClient commitClient = clientManager.getCommitClient(); commitClient.doCommit( new File[] {wcRoot}, false, "committing changes", null, null, false, false, SVNDepth.INFINITY); // now diff the base revision of the working copy against the repository SVNDiffClient diffClient = clientManager.getDiffClient(); SVNRevisionRange rangeToMerge = new SVNRevisionRange(SVNRevision.create(1), SVNRevision.HEAD); diffClient.doMerge( A_URL, SVNRevision.HEAD, Collections.singleton(rangeToMerge), new File(wcRoot, "A_copy"), SVNDepth.UNKNOWN, true, false, false, false); // now make some changes to the A tree again // change file contents of iota and A/D/gamma SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text2 appended to 'iota'", true); SamplesUtility.writeToFile(new File(wcRoot, "A/D/gamma"), "New text in 'gamma'", false); // remove A/C from version control wcClient.doDelete(new File(wcRoot, "A/C"), false, true, false); // commit local changes commitClient.doCommit( new File[] {wcRoot}, false, "committing changes again", null, null, false, false, SVNDepth.INFINITY); /* do the same merge call, merge-tracking feature will merge only those revisions * which were not still merged. */ diffClient.doMerge( A_URL, SVNRevision.HEAD, Collections.singleton(rangeToMerge), new File(wcRoot, "A_copy"), SVNDepth.UNKNOWN, true, false, false, false); } catch (SVNException svne) { System.out.println(svne.getErrorMessage()); System.exit(1); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(1); } }