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);
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations