Search in sources :

Example 1 with ISVNLogMessage

use of org.tigris.subversion.svnclientadapter.ISVNLogMessage in project subclipse by subclipse.

the class Cache method createGraph.

public Graph createGraph(String rootPath, long revision, WorkListener listener) {
    // System.out.println("create graph");
    Graph graph = new Graph(rootPath);
    // root path is the first opened branch
    graph.addBranch(rootPath);
    long seek = getSeek(revision);
    RandomAccessFile file = null;
    try {
        file = new RandomAccessFile(logMessagesFile, "r");
        file.seek(seek);
        while (file.getFilePointer() < file.length()) {
            ISVNLogMessage lm = readNext(file, true);
            ISVNLogMessageChangePath[] changedPaths = lm.getChangedPaths();
            String[] pa = graph.getPathsAsArray();
            Node node = null;
            for (int n = 0; n < changedPaths.length; n++) {
                ISVNLogMessageChangePath cp = changedPaths[n];
                String nodePath = cp.getPath();
                String copySrcPath = cp.getCopySrcPath();
                for (int i = 0; i < pa.length; i++) {
                    String branchPath = pa[i];
                    if (copySrcPath == null) {
                        if ((cp.getAction() == 'A' && nodePath.equals(branchPath)) || (cp.getAction() == 'D' && isEqualsOrParent(nodePath, branchPath)) || (cp.getAction() == 'M' && nodePath.equals(branchPath))) {
                            Branch branch = graph.getBranch(branchPath);
                            if (branch.isEnded()) {
                                // the branch was ended with a D action
                                continue;
                            }
                            node = toNode(lm, cp);
                            node.setParent(branch.getLastNode());
                            branch.addNode(node);
                            if (node.getAction() == 'D') {
                                branch.end();
                            }
                        }
                    } else if (copySrcPath != null && isEqualsOrParent(copySrcPath, branchPath)) {
                        Branch branch = graph.getBranch(branchPath);
                        Node source = branch.getSource(cp.getCopySrcRevision().getNumber());
                        if (source == null)
                            continue;
                        node = toNode(lm, cp);
                        node.setSource(source);
                        String path = nodePath + branchPath.substring(copySrcPath.length());
                        Branch newBranch = graph.getBranch(path);
                        if (newBranch == null) {
                            newBranch = graph.addBranch(path);
                        }
                        newBranch.addNode(node);
                    }
                }
            }
            if (node != null && lm.hasChildren()) {
                ISVNLogMessage[] cm = lm.getChildMessages();
                for (int i = 0; i < cm.length; i++) {
                    ISVNLogMessage child = cm[i];
                    ISVNLogMessageChangePath[] cp = child.getChangedPaths();
                    for (int j = 0; j < cp.length; j++) {
                        ISVNLogMessageChangePath changePath = cp[j];
                        for (int k = 0; k < pa.length; k++) {
                            String path = pa[k];
                            if (path.equals(changePath.getPath())) {
                                Branch branch = graph.getBranch(path);
                                Node source = branch.getSource(child.getRevision().getNumber());
                                if (source == null)
                                    continue;
                                // add connection between "node" and "source"
                                node.addMergedRevision(source);
                            }
                        }
                    }
                }
            }
            if (listener != null)
                listener.worked();
        }
    } catch (IOException e) {
        throw new CacheException("Error while calculating graph", e);
    } finally {
        closeFile(file);
    }
    // Tags
    List paths = graph.getPaths();
    Iterator iter = paths.iterator();
    while (iter.hasNext()) {
        String path = (String) iter.next();
        Branch branch = graph.getBranch(path);
        if (branch.getNodes().size() == 1) {
            Node firstNode = (Node) branch.getNodes().iterator().next();
            if (firstNode.getSource() != null && firstNode.getChildCount() == 0) {
                // therefore is a tag
                if (firstNode.getSource() != null) {
                    firstNode.getSource().addTag(firstNode);
                }
            }
        }
    }
    return graph;
}
Also used : ISVNLogMessageChangePath(org.tigris.subversion.svnclientadapter.ISVNLogMessageChangePath) IOException(java.io.IOException) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) RandomAccessFile(java.io.RandomAccessFile) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ISVNLogMessage

use of org.tigris.subversion.svnclientadapter.ISVNLogMessage in project subclipse by subclipse.

the class GetLogsCommand method run.

/**
 * execute the command
 *
 * @param aMonitor
 * @throws SVNException
 */
public void run(IProgressMonitor aMonitor) throws SVNException {
    ISVNRepositoryLocation repository = null;
    ISVNClientAdapter svnClient = null;
    logEntries = null;
    IProgressMonitor monitor = Policy.monitorFor(aMonitor);
    // $NON-NLS-1$
    monitor.beginTask(Policy.bind("RemoteFile.getLogEntries"), 100);
    ISVNLogMessage[] logMessages;
    try {
        if (callback == null) {
            logMessages = remoteResource.getLogMessages(pegRevision, revisionStart, revisionEnd, stopOnCopy, !SVNProviderPlugin.getPlugin().getSVNClientManager().isFetchChangePathOnDemand(), limit, includeMergedRevisions);
        } else {
            repository = remoteResource.getRepository();
            svnClient = repository.getSVNClient();
            if (remoteResource instanceof BaseResource) {
                boolean logMessagesRetrieved = false;
                ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(remoteResource.getResource());
                if (svnResource != null) {
                    LocalResourceStatus status = svnResource.getStatus();
                    if (status != null && status.isCopied()) {
                        ISVNInfo info = svnClient.getInfoFromWorkingCopy(svnResource.getFile());
                        SVNUrl copiedFromUrl = info.getCopyUrl();
                        if (copiedFromUrl != null) {
                            svnClient.getLogMessages(copiedFromUrl, SVNRevision.HEAD, revisionStart, revisionEnd, stopOnCopy, !SVNProviderPlugin.getPlugin().getSVNClientManager().isFetchChangePathOnDemand(), limit, includeMergedRevisions, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callback);
                            logMessagesRetrieved = true;
                            GetRemoteResourceCommand getRemoteResourceCommand = new GetRemoteResourceCommand(remoteResource.getRepository(), copiedFromUrl, SVNRevision.HEAD);
                            getRemoteResourceCommand.run(null);
                            remoteResource = getRemoteResourceCommand.getRemoteResource();
                        }
                    }
                }
                if (!logMessagesRetrieved)
                    svnClient.getLogMessages(((BaseResource) remoteResource).getFile(), pegRevision, revisionStart, revisionEnd, stopOnCopy, !SVNProviderPlugin.getPlugin().getSVNClientManager().isFetchChangePathOnDemand(), limit, includeMergedRevisions, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callback);
            } else {
                svnClient.getLogMessages(remoteResource.getUrl(), pegRevision, revisionStart, revisionEnd, stopOnCopy, !SVNProviderPlugin.getPlugin().getSVNClientManager().isFetchChangePathOnDemand(), limit, includeMergedRevisions, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callback);
            }
            logMessages = callback.getLogMessages();
        }
        if (remoteResource.isFolder()) {
            logEntries = LogEntry.createLogEntriesFrom((ISVNRemoteFolder) remoteResource, logMessages, getTags(logMessages));
        } else {
            logEntries = LogEntry.createLogEntriesFrom((ISVNRemoteFile) remoteResource, logMessages, getTags(logMessages), getUrls(logMessages));
        }
    } catch (Exception e) {
        throw SVNException.wrapException(e);
    } finally {
        if (repository != null) {
            repository.returnSVNClient(svnClient);
        }
        monitor.done();
    }
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) BaseResource(org.tigris.subversion.subclipse.core.resources.BaseResource) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 3 with ISVNLogMessage

use of org.tigris.subversion.svnclientadapter.ISVNLogMessage in project subclipse by subclipse.

the class ShowAnnotationOperation method getSingleEntry.

private String getSingleEntry(ISVNRemoteFile file, Long revLong) {
    ISVNClientAdapter client = null;
    try {
        client = file.getRepository().getSVNClient();
        SVNRevision revision = SVNRevision.getRevision(revLong.toString());
        ISVNLogMessage[] messages = client.getLogMessages(file.getRepository().getRepositoryRoot(), revision, revision, false);
        if (messages.length == 1)
            return messages[0].getMessage();
        else
            return null;
    } catch (Exception e) {
        return null;
    } finally {
        file.getRepository().returnSVNClient(client);
    }
}
Also used : SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) WorkbenchException(org.eclipse.ui.WorkbenchException) SVNException(org.tigris.subversion.subclipse.core.SVNException) PartInitException(org.eclipse.ui.PartInitException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 4 with ISVNLogMessage

use of org.tigris.subversion.svnclientadapter.ISVNLogMessage in project subclipse by subclipse.

the class Cache method writeChildren.

private void writeChildren(int level, boolean writingTempFile) throws IOException {
    List nonWrittenChildren = getNonWrittenChildren();
    // System.out.println("B. Children: " + nonWrittenChildren.size());
    if (writingTempFile)
        logMessagesTempRaf.writeInt(nonWrittenChildren.size());
    else
        logMessagesRaf.writeInt(nonWrittenChildren.size());
    // for (Iterator it = children.iterator(); it.hasNext();) {
    for (Iterator it = nonWrittenChildren.iterator(); it.hasNext(); ) {
        ISVNLogMessage logMessage = (ISVNLogMessage) it.next();
        writeLogMessage(logMessage, level, writingTempFile);
    }
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage)

Example 5 with ISVNLogMessage

use of org.tigris.subversion.svnclientadapter.ISVNLogMessage in project subclipse by subclipse.

the class Cache method refresh.

public void refresh(List refreshedNodes, ISVNInfo info, IProgressMonitor monitor, int unitWorked) {
    ISVNLogMessageCallback callback = new ISVNLogMessageCallback() {

        public void singleMessage(ISVNLogMessage message) {
            update(message, true);
        }
    };
    revisionsTempFile = new File(root, "revisionsTemp");
    logMessagesTempFile = new File(root, "logMessagesTemp");
    revisionsTempFile.delete();
    logMessagesTempFile.delete();
    try {
        revisionsTempFile.createNewFile();
        logMessagesTempFile.createNewFile();
    } catch (IOException e) {
        Activator.handleError(e);
    }
    List revisions = new ArrayList();
    Iterator iter = refreshedNodes.iterator();
    while (iter.hasNext()) {
        Node node = (Node) iter.next();
        revisions.add(Long.toString(node.getRevision()));
    }
    startTempUpdate();
    RandomAccessFile file = null;
    ISVNClientAdapter client = null;
    try {
        client = SVNProviderPlugin.getPlugin().getSVNClient();
        file = new RandomAccessFile(logMessagesFile, "r");
        int revInt = new Long(getLatestRevision()).intValue();
        while (file.getFilePointer() < file.length()) {
            ISVNLogMessage lm = readNext(file, true);
            level = 0;
            int index = revisions.indexOf(lm.getRevision().toString());
            if (index == -1) {
                update(lm, true);
                if (lm.hasChildren() && lm.getChildMessages() != null) {
                    updateChildren(lm, true);
                }
                monitor.worked(unitWorked / revInt);
            } else {
                Node updateNode = (Node) refreshedNodes.get(index);
                SVNRevision updateRevision = new SVNRevision.Number(updateNode.getRevision());
                client.getLogMessages(new SVNUrl(info.getRepository() + updateNode.getPath()), updateRevision, updateRevision, updateRevision, false, true, 0, true, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callback);
                monitor.worked(unitWorked);
            // updateRevision = (ISVNLogMessage)refreshedMessages.get(index);
            // monitor.worked(unitWorked);
            }
            if (monitor.isCanceled()) {
                break;
            }
        }
    } catch (Exception e) {
    } finally {
        closeFile(file);
        SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
    }
    finishTempUpdate();
    if (monitor.isCanceled()) {
        revisionsTempFile.delete();
        logMessagesTempFile.delete();
        return;
    }
    revisionsFile.delete();
    logMessagesFile.delete();
    revisionsTempFile.renameTo(revisionsFile);
    logMessagesTempFile.renameTo(logMessagesFile);
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) IOException(java.io.IOException) ISVNLogMessageCallback(org.tigris.subversion.svnclientadapter.ISVNLogMessageCallback) RandomAccessFile(java.io.RandomAccessFile) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Aggregations

ISVNLogMessage (org.tigris.subversion.svnclientadapter.ISVNLogMessage)11 ArrayList (java.util.ArrayList)5 Iterator (java.util.Iterator)5 List (java.util.List)5 IOException (java.io.IOException)4 RandomAccessFile (java.io.RandomAccessFile)4 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)4 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)3 File (java.io.File)2 ISVNRemoteFile (org.tigris.subversion.subclipse.core.ISVNRemoteFile)2 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)2 SVNException (org.tigris.subversion.subclipse.core.SVNException)2 ISVNLogMessageChangePath (org.tigris.subversion.svnclientadapter.ISVNLogMessageChangePath)2 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 TeamException (org.eclipse.team.core.TeamException)1 SyncInfoTree (org.eclipse.team.core.synchronize.SyncInfoTree)1 PartInitException (org.eclipse.ui.PartInitException)1 WorkbenchException (org.eclipse.ui.WorkbenchException)1 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)1