Search in sources :

Example 6 with ISVNLogMessage

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

the class Cache method refresh.

public void refresh(List refreshedMessages, IProgressMonitor monitor, int unitWorked) {
    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 = refreshedMessages.iterator();
    while (iter.hasNext()) {
        ISVNLogMessage message = (ISVNLogMessage) iter.next();
        revisions.add(message.getRevision().toString());
    }
    startTempUpdate();
    RandomAccessFile file = null;
    try {
        file = new RandomAccessFile(logMessagesFile, "r");
        int revInt = new Long(getLatestRevision()).intValue();
        while (file.getFilePointer() < file.length()) {
            ISVNLogMessage lm = readNext(file, true);
            level = 0;
            ISVNLogMessage updateRevision = null;
            int index = revisions.indexOf(lm.getRevision().toString());
            if (index == -1) {
                updateRevision = lm;
                monitor.worked(unitWorked / revInt);
            } else {
                updateRevision = (ISVNLogMessage) refreshedMessages.get(index);
                monitor.worked(unitWorked);
            // System.out.println("Update: " + updateRevision.getRevision() + " (level =" + level
            // + ")");
            }
            update(updateRevision, true);
            if (updateRevision.hasChildren() && updateRevision.getChildMessages() != null) {
                updateChildren(updateRevision, true);
            }
            if (monitor.isCanceled()) {
                break;
            }
        }
    } catch (Exception e) {
    } finally {
        closeFile(file);
    }
    finishTempUpdate();
    if (monitor.isCanceled()) {
        revisionsTempFile.delete();
        logMessagesTempFile.delete();
        return;
    }
    revisionsFile.delete();
    logMessagesFile.delete();
    revisionsTempFile.renameTo(revisionsFile);
    logMessagesTempFile.renameTo(logMessagesFile);
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) IOException(java.io.IOException)

Example 7 with ISVNLogMessage

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

the class Cache method findRootNode.

/**
 * This method finds the revision number and path where the file was first created.
 *
 * @param path The path of the selected file
 * @param revision The revision number of the selected file
 * @param listener A listener to implement a progress bar for example
 * @return a Node object just containing the path and revision properties setted
 */
public Node findRootNode(String path, long revision, WorkListener listener) {
    // r means "current revision"
    long r = revision;
    // pr means "previous revision"
    long pr = r;
    RandomAccessFile logMessages = null;
    try {
        /*
       * We need to read the logMessagesFiles backwards, from the selected revision
       * to the root revision.
       * It is done by jumping backwards and reading a
       * maximmun of MAX_LOG_MESSAGES number of messages inside an array
       * that acts as a buffer.
       */
        logMessages = new RandomAccessFile(logMessagesFile, "r");
        ISVNLogMessage[] buffer = new ISVNLogMessage[MAX_LOG_MESSAGES];
        do {
            // We are going to jump to a previous revision.
            // Exactly MAX_LOG_MESSAGES revisions before
            r -= (MAX_LOG_MESSAGES) - 1;
            if (r < 1) {
                // Well, we cannot jump to a revision lower than 1
                r = 1;
            }
            // It moves the file pointer to the revision. Here is where it jumps backwards
            logMessages.seek(getSeek(r));
            // It calculates how many log messages should be read
            // this won't be higher than MAX_LOG_MESSAGES
            int size = (int) (pr - r + 1);
            if (size == 0)
                break;
            // It reads the log messages to the buffer
            readNext(logMessages, buffer, size);
            // It iterates over all log messages
            for (int k = 0; k < size; k++) {
                ISVNLogMessage lm = buffer[k];
                // System.out.println("revision: "+lm.getRevision().getNumber());
                // It iterates over all changed paths
                ISVNLogMessageChangePath[] changedPaths = lm.getChangedPaths();
                for (int n = 0; n < changedPaths.length; n++) {
                    ISVNLogMessageChangePath cp = changedPaths[n];
                    /*
             * It is only interested on 'A' actions.
             * If copySrcPath is not null it compares the paths to know
             * if the changedPath is equals or parent to the current path.
             * For example if it is finding the root node for /branches/a/foo.txt
             * "A /branches/a from /trunk"
             * In this case /branches/a is parent of /branches/a/foo.txt
             * so now we know that /branches/a/foo.txt was copied from /trunk/foo.txt
             * If copySrcPath is null and the changed path is equal to the path
             * we are looking for then we have found the root node.
             */
                    if (lm.getRevision().getNumber() <= revision && cp.getAction() == 'A') {
                        if (cp.getCopySrcPath() != null) {
                            if (isEqualsOrParent(cp.getPath(), Util.unescape(path))) {
                                revision = lm.getRevision().getNumber();
                                path = cp.getCopySrcPath() + Util.unescape(path).substring(cp.getPath().length());
                            // TODO: here I could seek to 'revision'
                            // because all other revisions in between will be ignored
                            }
                        } else {
                            if (cp.getPath().equals(Util.unescape(path))) {
                                revision = lm.getRevision().getNumber();
                                Node node = new Node();
                                node.setPath(Util.unescape(path));
                                node.setRevision(revision);
                                return node;
                            }
                        }
                    }
                }
                if (listener != null)
                    listener.worked();
            }
            // previous revision is the current revision
            pr = r;
        } while (true);
    } catch (IOException e) {
        throw new CacheException("Error while finding root node", e);
    } finally {
        closeFile(logMessages);
    }
    Node n = new Node();
    n.setPath(Util.unescape(path));
    n.setRevision(revision);
    return n;
}
Also used : ISVNLogMessageChangePath(org.tigris.subversion.svnclientadapter.ISVNLogMessageChangePath) RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage)

Example 8 with ISVNLogMessage

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

the class Cache method getNonWrittenChildren.

private List getNonWrittenChildren() {
    List nonWrittenChildren = new ArrayList();
    for (Iterator it = children.iterator(); it.hasNext(); ) {
        ISVNLogMessage logMessage = (ISVNLogMessage) it.next();
        if (!writtenChildren.contains(logMessage.getRevision().toString())) {
            nonWrittenChildren.add(logMessage);
            writtenChildren.add(logMessage.getRevision().toString());
        }
    }
    return nonWrittenChildren;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage)

Example 9 with ISVNLogMessage

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

the class LogEntry method getPathsOnDemand.

private ISVNLogMessageChangePath[] getPathsOnDemand(SVNUrl url) {
    ISVNLogMessage[] tmpMessage;
    ISVNClientAdapter client = null;
    try {
        // errors will not log to console
        client = SVNProviderPlugin.getPlugin().getSVNClient();
        SVNProviderPlugin.disableConsoleLogging();
        tmpMessage = client.getLogMessages(url, getRevision(), getRevision(), true);
        SVNProviderPlugin.enableConsoleLogging();
        if (tmpMessage != null && tmpMessage.length > 0)
            return tmpMessage[0].getChangedPaths();
        else
            return null;
    } catch (Exception e) {
        SVNProviderPlugin.enableConsoleLogging();
        return null;
    } finally {
        SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
    }
}
Also used : ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 10 with ISVNLogMessage

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

the class LogEntry method createLogEntriesFrom.

/**
 * create the LogEntry for the logMessages
 *
 * @param logMessages
 * @return
 */
public static ILogEntry[] createLogEntriesFrom(ISVNRemoteFile remoteFile, ISVNLogMessage[] logMessages, Tags[] tags, SVNUrl[] urls) {
    ILogEntry[] result = new ILogEntry[logMessages.length];
    for (int i = 0; i < logMessages.length; i++) {
        ISVNLogMessage logMessage = logMessages[i];
        ISVNRemoteResource correspondingResource;
        correspondingResource = new RemoteFile(null, remoteFile.getRepository(), urls[i], logMessage.getRevision(), logMessage.getRevision(), logMessage.getDate(), logMessage.getAuthor());
        result[i] = new LogEntry(logMessage, remoteFile, correspondingResource, (tags[i] != null) ? tags[i].getTags() : null);
    }
    return result;
}
Also used : ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

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