diff options
Diffstat (limited to 'bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/RemoteLogOperation.java')
-rw-r--r-- | bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/RemoteLogOperation.java | 296 |
1 files changed, 148 insertions, 148 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/RemoteLogOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/RemoteLogOperation.java index b9f01201a..8eeb0d664 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/RemoteLogOperation.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/RemoteLogOperation.java @@ -46,41 +46,41 @@ public class RemoteLogOperation extends RepositoryLocationOperation { * remote log operation. */ public static class LogEntryCache implements ILogEntryListener { - - /* - * Cache of all log entries - */ + + /* + * Cache of all log entries + */ private Map<String, Map<String, ILogEntry>> entries = new HashMap<>(); /* * Map String:remoteFilePath->Map * (String:revision -> ILogEntry) */ private Map<String, ILogEntry> internalGetLogEntries(String path) { - return entries.get(path); - } - - /** - * Return all the log entries at the given path - * @param path the file path - * @return the log entries for the file - */ - public ILogEntry[] getLogEntries(String path) { + return entries.get(path); + } + + /** + * Return all the log entries at the given path + * @param path the file path + * @return the log entries for the file + */ + public ILogEntry[] getLogEntries(String path) { Map<String, ILogEntry> map = internalGetLogEntries(path); - return map.values().toArray(new ILogEntry[map.values().size()]); - } - - private ILogEntry internalGetLogEntry(String path, String revision) { - Map fileEntries = internalGetLogEntries(path); - if (fileEntries != null) { - return (ILogEntry)fileEntries.get(revision); - } - return null; - } - - public String[] getCachedFilePaths() { - return entries.keySet().toArray(new String[entries.size()]); - } - + return map.values().toArray(new ILogEntry[map.values().size()]); + } + + private ILogEntry internalGetLogEntry(String path, String revision) { + Map fileEntries = internalGetLogEntries(path); + if (fileEntries != null) { + return (ILogEntry)fileEntries.get(revision); + } + return null; + } + + public String[] getCachedFilePaths() { + return entries.keySet().toArray(new String[entries.size()]); + } + /** * Return the log entry that for the given resource * or <code>null</code> if no entry was fetched or the @@ -89,20 +89,20 @@ public class RemoteLogOperation extends RepositoryLocationOperation { * @return the log entry or <code>null</code> */ public synchronized ILogEntry getLogEntry(ICVSRemoteResource resource) { - if (resource instanceof ICVSRemoteFile) { - try { - String path = getFullPath(resource); - String revision = ((ICVSRemoteFile)resource).getRevision(); - return internalGetLogEntry(path, revision); - } catch (TeamException e) { - // Log and return null - CVSUIPlugin.log(e); - } - } - return null; + if (resource instanceof ICVSRemoteFile) { + try { + String path = getFullPath(resource); + String revision = ((ICVSRemoteFile)resource).getRevision(); + return internalGetLogEntry(path, revision); + } catch (TeamException e) { + // Log and return null + CVSUIPlugin.log(e); + } + } + return null; } - /** + /** * Return the log entries that were fetched for the given resource * or an empty list if no entry was fetched. * @param getFullPath(resource) the resource @@ -110,125 +110,125 @@ public class RemoteLogOperation extends RepositoryLocationOperation { */ public synchronized ILogEntry[] getLogEntries(ICVSRemoteResource resource) { Map<String, ILogEntry> fileEntries = internalGetLogEntries(getFullPath(resource)); - if (fileEntries != null) { - return fileEntries.values().toArray(new ILogEntry[fileEntries.size()]); - } - return new ILogEntry[0]; + if (fileEntries != null) { + return fileEntries.values().toArray(new ILogEntry[fileEntries.size()]); + } + return new ILogEntry[0]; } /* - * Return the full path that uniquely identifies the resource - * accross repositories. This path include the repository and - * resource path but does not include the revision so that - * all log entries for a file can be retrieved. - */ - private String getFullPath(ICVSRemoteResource resource) { - return Util.appendPath(resource.getRepository().getLocation(false), resource.getRepositoryRelativePath()); - } + * Return the full path that uniquely identifies the resource + * accross repositories. This path include the repository and + * resource path but does not include the revision so that + * all log entries for a file can be retrieved. + */ + private String getFullPath(ICVSRemoteResource resource) { + return Util.appendPath(resource.getRepository().getLocation(false), resource.getRepositoryRelativePath()); + } public synchronized void clearEntries() { entries.clear(); } - - public synchronized ICVSRemoteFile getImmediatePredecessor(ICVSRemoteFile file) throws TeamException { - ILogEntry[] allLogs = getLogEntries(file); - String revision = file.getRevision(); - // First decrement the last digit and see if that revision exists - String predecessorRevision = getPredecessorRevision(revision); - ICVSRemoteFile predecessor = findRevison(allLogs, predecessorRevision); - // If nothing was found, try to fond the base of a branch - if (predecessor == null && isBrancheRevision(revision)) { - predecessorRevision = getBaseRevision(revision); - predecessor = findRevison(allLogs, predecessorRevision); - } - // If that fails, it is still possible that there is a revision. - // This can happen if the revision has been manually set. - if (predecessor == null) { - // We don't search in this case since this is costly and would be done - // for any file that is new as well. - } - return predecessor; - } - - /* - * Find the given revision in the list of log entries. - * Return null if the revision wasn't found. - */ - private ICVSRemoteFile findRevison(ILogEntry[] allLogs, String predecessorRevision) throws TeamException { - for (int i = 0; i < allLogs.length; i++) { - ILogEntry entry = allLogs[i]; - ICVSRemoteFile file = entry.getRemoteFile(); - if (file.getRevision().equals(predecessorRevision)) { - return file; - } - } - return null; - } - /* - * Decrement the trailing digit by one. - */ - private String getPredecessorRevision(String revision) { - int digits[] = Util.convertToDigits(revision); - digits[digits.length -1]--; - StringBuffer buffer = new StringBuffer(revision.length()); - for (int i = 0; i < digits.length; i++) { - buffer.append(Integer.toString(digits[i])); - if (i < digits.length - 1) { - buffer.append('.'); - } - } - return buffer.toString(); - } - - /* - * Return true if there are more than 2 digits in the revision number - * (i.e. the revision is on a branch) - */ - private boolean isBrancheRevision(String revision) { - return Util.convertToDigits(revision).length > 2; - } - - /* - * Remove the trailing revision digits such that the - * returned revision is shorter than the given revision - * and is an even number of digits long - */ - private String getBaseRevision(String revision) { - int digits[] = Util.convertToDigits(revision); - int length = digits.length - 1; - if (length % 2 == 1) { - length--; - } - StringBuffer buffer = new StringBuffer(revision.length()); - for (int i = 0; i < length; i++) { - buffer.append(Integer.toString(digits[i])); - if (i < length - 1) { - buffer.append('.'); - } - } - return buffer.toString(); - } - /** - * Remove any entries for the remote resources - * @param resource the remote resource - */ - public synchronized void clearEntries(ICVSRemoteResource resource) { - String remotePath = getFullPath(resource); - entries.remove(remotePath); - } + + public synchronized ICVSRemoteFile getImmediatePredecessor(ICVSRemoteFile file) throws TeamException { + ILogEntry[] allLogs = getLogEntries(file); + String revision = file.getRevision(); + // First decrement the last digit and see if that revision exists + String predecessorRevision = getPredecessorRevision(revision); + ICVSRemoteFile predecessor = findRevison(allLogs, predecessorRevision); + // If nothing was found, try to fond the base of a branch + if (predecessor == null && isBrancheRevision(revision)) { + predecessorRevision = getBaseRevision(revision); + predecessor = findRevison(allLogs, predecessorRevision); + } + // If that fails, it is still possible that there is a revision. + // This can happen if the revision has been manually set. + if (predecessor == null) { + // We don't search in this case since this is costly and would be done + // for any file that is new as well. + } + return predecessor; + } + + /* + * Find the given revision in the list of log entries. + * Return null if the revision wasn't found. + */ + private ICVSRemoteFile findRevison(ILogEntry[] allLogs, String predecessorRevision) throws TeamException { + for (int i = 0; i < allLogs.length; i++) { + ILogEntry entry = allLogs[i]; + ICVSRemoteFile file = entry.getRemoteFile(); + if (file.getRevision().equals(predecessorRevision)) { + return file; + } + } + return null; + } + /* + * Decrement the trailing digit by one. + */ + private String getPredecessorRevision(String revision) { + int digits[] = Util.convertToDigits(revision); + digits[digits.length -1]--; + StringBuffer buffer = new StringBuffer(revision.length()); + for (int i = 0; i < digits.length; i++) { + buffer.append(Integer.toString(digits[i])); + if (i < digits.length - 1) { + buffer.append('.'); + } + } + return buffer.toString(); + } + + /* + * Return true if there are more than 2 digits in the revision number + * (i.e. the revision is on a branch) + */ + private boolean isBrancheRevision(String revision) { + return Util.convertToDigits(revision).length > 2; + } + + /* + * Remove the trailing revision digits such that the + * returned revision is shorter than the given revision + * and is an even number of digits long + */ + private String getBaseRevision(String revision) { + int digits[] = Util.convertToDigits(revision); + int length = digits.length - 1; + if (length % 2 == 1) { + length--; + } + StringBuffer buffer = new StringBuffer(revision.length()); + for (int i = 0; i < length; i++) { + buffer.append(Integer.toString(digits[i])); + if (i < length - 1) { + buffer.append('.'); + } + } + return buffer.toString(); + } + /** + * Remove any entries for the remote resources + * @param resource the remote resource + */ + public synchronized void clearEntries(ICVSRemoteResource resource) { + String remotePath = getFullPath(resource); + entries.remove(remotePath); + } - @Override + @Override public void handleLogEntryReceived(ILogEntry entry) { - ICVSRemoteFile file = entry.getRemoteFile(); - String fullPath = getFullPath(file); - String revision = entry.getRevision(); + ICVSRemoteFile file = entry.getRemoteFile(); + String fullPath = getFullPath(file); + String revision = entry.getRevision(); Map<String, ILogEntry> fileEntries = internalGetLogEntries(fullPath); - if (fileEntries == null) { + if (fileEntries == null) { fileEntries = new HashMap<>(); - entries.put(fullPath, fileEntries); - } - fileEntries.put(revision, entry); - } + entries.put(fullPath, fileEntries); + } + fileEntries.put(revision, entry); + } } public RemoteLogOperation(IWorkbenchPart part, ICVSRemoteResource[] remoteResources, CVSTag tag1, CVSTag tag2, LogEntryCache cache) { |