org.tmatesoft.svn.core.SVNCommitInfo Java Examples

The following examples show how to use org.tmatesoft.svn.core.SVNCommitInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MCRVersioningMetadataStore.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void delete(int id) throws IOException {
    String commitMsg = "Deleted metadata object " + getID() + "_" + id + " in store";
    // Commit to SVN
    SVNCommitInfo info;
    try {
        SVNRepository repository = getRepository();
        ISVNEditor editor = repository.getCommitEditor(commitMsg, null);
        editor.openRoot(-1);
        editor.deleteEntry("/" + getSlotPath(id), -1);
        editor.closeDir();

        info = editor.closeEdit();
        LOGGER.info("SVN commit of delete finished, new revision {}", info.getNewRevision());
    } catch (SVNException e) {
        LOGGER.error("Error while deleting {} in SVN ", id, e);
    } finally {
        super.delete(id);
    }
}
 
Example #2
Source File: ProgressBarReplicationHandler.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
@Override
public void revisionReplicated(SVNRepositoryReplicator source, SVNCommitInfo commitInfo) throws SVNException {
	printer.printProgressBar(commitInfo.getNewRevision());
}
 
Example #3
Source File: MCRVersionedMetadata.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
void commit(String mode) throws IOException {
    // Commit to SVN
    SVNCommitInfo info;
    try {
        SVNRepository repository = getStore().getRepository();

        // Check which paths already exist in SVN
        String[] paths = store.getSlotPaths(id);
        int existing = paths.length - 1;
        for (; existing >= 0; existing--) {
            if (!repository.checkPath(paths[existing], -1).equals(SVNNodeKind.NONE)) {
                break;
            }
        }

        existing += 1;

        // Start commit editor
        String commitMsg = mode + "d metadata object " + store.getID() + "_" + id + " in store";
        ISVNEditor editor = repository.getCommitEditor(commitMsg, null);
        editor.openRoot(-1);

        // Create directories in SVN that do not exist yet
        for (int i = existing; i < paths.length - 1; i++) {
            LOGGER.debug("SVN create directory {}", paths[i]);
            editor.addDir(paths[i], null, -1);
            editor.closeDir();
        }

        // Commit file changes
        String filePath = paths[paths.length - 1];
        if (existing < paths.length) {
            editor.addFile(filePath, null, -1);
        } else {
            editor.openFile(filePath, -1);
        }

        editor.applyTextDelta(filePath, null);
        SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();

        String checksum;
        try (InputStream in = Files.newInputStream(path)) {
            checksum = deltaGenerator.sendDelta(filePath, in, editor, true);
        }

        if (store.shouldForceXML()) {
            editor.changeFileProperty(filePath, SVNProperty.MIME_TYPE, SVNPropertyValue.create("text/xml"));
        }

        editor.closeFile(filePath, checksum);
        editor.closeDir(); // root

        info = editor.closeEdit();
    } catch (SVNException e) {
        throw new IOException(e);
    }
    revision = () -> Optional.of(info.getNewRevision());
    LOGGER.info("SVN commit of {} finished, new revision {}", mode, getRevision());

    if (MCRVersioningMetadataStore.shouldSyncLastModifiedOnSVNCommit()) {
        setLastModified(info.getDate());
    }
}
 
Example #4
Source File: ReportSVNEditor.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public SVNCommitInfo closeEdit() {
  return null;
}
 
Example #5
Source File: SVNEditorWrapper.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public SVNCommitInfo closeEdit() throws SVNException {
  return (editor != null) ? editor.closeEdit() : null;
}
 
Example #6
Source File: SvnProctorUtils.java    From proctor with Apache License 2.0 4 votes vote down vote up
static void doInWorkingDirectory(
    final Logger logger,
    final File userDir,
    final String username,
    final String password,
    final SVNURL svnUrl,
    final FileBasedProctorStore.ProctorUpdater updater,
    final String comment) throws IOException, SVNException, Exception {
    final BasicAuthenticationManager authManager = new BasicAuthenticationManager(username, password);
    final SVNClientManager userClientManager = SVNClientManager.newInstance(null, authManager);
    final SVNWCClient wcClient = userClientManager.getWCClient();

    try {
        // Clean up the UserDir
        SvnProctorUtils.cleanUpWorkingDir(logger, userDir, svnUrl, userClientManager);

        /*
            if (previousVersion != 0) {
                final Collection<?> changesSinceGivenVersion = repo.log(new String[] { "" }, null, previousVersion, -1, false, false);
                if (! changesSinceGivenVersion.isEmpty()) {
                    //  TODO: the baseline version is out of date, so need to go back to the user
                }
            }
            updateClient.doCheckout(checkoutUrl, workingDir, null, SVNRevision.HEAD, SVNDepth.INFINITY, false);
        */

        final FileBasedProctorStore.RcsClient rcsClient = new SvnPersisterCoreImpl.SvnRcsClient(wcClient);
        final boolean thingsChanged = updater.doInWorkingDirectory(rcsClient, userDir);

        if (thingsChanged) {
            final SVNCommitClient commitClient = userClientManager.getCommitClient();
            final SVNCommitPacket commit = commitClient.doCollectCommitItems(new File[]{userDir}, false, false, SVNDepth.INFINITY, new String[0]);
            long elapsed = -System.currentTimeMillis();
            final SVNCommitInfo info = commitClient.doCommit(commit, /* keepLocks */ false, comment);
            elapsed += System.currentTimeMillis();
            if (logger.isDebugEnabled()) {
                final StringBuilder changes = new StringBuilder("Committed " + commit.getCommitItems().length + " changes: ");
                for (final SVNCommitItem item : commit.getCommitItems()) {
                    changes.append(item.getKind() + " - " + item.getPath() + ", ");
                }
                changes.append(String.format(" in %d ms new revision: r%d", elapsed, info.getNewRevision()));
                logger.debug(changes.toString());
            }
        }
    } finally {
        userClientManager.dispose();
    }
}