Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > subclipse commit: r1438 - trunk/subclipse/core/src/org/tigris/subversion/subclipse/core/status

subclipse
Discussion topic

Back to topic list

subclipse commit: r1438 - trunk/subclipse/core/src/org/tigris/subversion/subclipse/core/status

Author markphip
Full name Mark Phippard
Date 2005-07-08 17:38:32 PDT
Message Author: markphip
Date: Fri Jul 8 19:38:30 2005
New Revision: 1438

Modified:
   trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/IStatusCach​e.java (contents, props changed)
   trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/Synchronize​rSyncInfoCache.java (contents, props changed)

Log:
Set svn:eol-style

Modified: trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/IStatusCach​e.java
Url: http://svn.collab.ne​t/viewcvs/subclipse/​trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/IStatusCach​e.java?rev=1438&​p1=trunk/subclipse/c​ore/src/org/tigris/s​ubversion/subclipse/​core/status/IStatusC​ache.java&p2=tru​nk/subclipse/core/sr​c/org/tigris/subvers​ion/subclipse/core/s​tatus/IStatusCache.j​ava&r1=1437&​r2=1438
====================​====================​====================​==================
--- trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/IStatusCach​e.java (original)
+++ trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/IStatusCach​e.java Fri Jul 8 19:38:30 2005
@@ -1,63 +1,63 @@
-/******************​********************​********************​********************​
- * This program and the accompanying materials are made available under
- * the terms of the Common Public License v1.0 which accompanies this
- * distribution, and is available at the following URL:
- * http://www.eclipse.o​rg/legal/cpl-v10.htm​l
- * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
- *
- * All Rights are Reserved by the various authors.
- ********************​********************​********************​*******************/​
-package org.tigris.subversio​n.subclipse.core.sta​tus;
-
-import org.eclipse.core.res​ources.IResource;
-import org.eclipse.core.runtime.IPath;
-import org.tigris.subversio​n.subclipse.core.SVN​Exception;
-import org.tigris.subversio​n.subclipse.core.res​ources.LocalResource​Status;
-
-/**
- * Cache for storing and retrieving local status info
- *
- */
-public interface IStatusCache {
-
- /**
- * get the status of the given resource (which does not need to exist)
- * @param resource
- * @return LocalResourceStatus
- */
- LocalResourceStatus getStatus(IResource resource);
-
- /**
- * add a status for the given resource (which does not need to exist)
- * @param resource
- * @param status - can be null
- */
- void addStatus(IResource resource, LocalResourceStatus status);
-
- /**
- * add a status for the reasource of the given relative path
- * @param path
- * @param status - can be null
- */
- void addStatus(IPath path, LocalResourceStatus status);
-
- /**
- * Ensure that base(pristine) copy of resource syncInfo is present in syncInfo of ResourceInfo of the resource.
- *
- * @param resource IResource of status is determined
- * @throws SVNException
- * @deprecated should be removed when StatusCacheComposite will be definitely replaced by SynchronizerSyncInfoCache
- */
- void ensureBaseStatusInfo(IResource resource) throws SVNException;
-
- /**
- * Ensure that base(pristine) copy of resource syncInfo is present in syncInfo of ResourceInfo of the resource.
- *
- * @param resource IResource of status is determined
- * @param depth
- * @throws SVNException
- * @deprecated should be removed when StatusCacheComposite will be definitely replaced by SynchronizerSyncInfoCache
- */
- void ensureBaseStatusInfo(IResource resource, int depth) throws SVNException;
-
-}
+/******************​********************​********************​********************​
+ * This program and the accompanying materials are made available under
+ * the terms of the Common Public License v1.0 which accompanies this
+ * distribution, and is available at the following URL:
+ * http://www.eclipse.o​rg/legal/cpl-v10.htm​l
+ * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
+ *
+ * All Rights are Reserved by the various authors.
+ ********************​********************​********************​*******************/​
+package org.tigris.subversio​n.subclipse.core.sta​tus;
+
+import org.eclipse.core.res​ources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.tigris.subversio​n.subclipse.core.SVN​Exception;
+import org.tigris.subversio​n.subclipse.core.res​ources.LocalResource​Status;
+
+/**
+ * Cache for storing and retrieving local status info
+ *
+ */
+public interface IStatusCache {
+
+ /**
+ * get the status of the given resource (which does not need to exist)
+ * @param resource
+ * @return LocalResourceStatus
+ */
+ LocalResourceStatus getStatus(IResource resource);
+
+ /**
+ * add a status for the given resource (which does not need to exist)
+ * @param resource
+ * @param status - can be null
+ */
+ void addStatus(IResource resource, LocalResourceStatus status);
+
+ /**
+ * add a status for the reasource of the given relative path
+ * @param path
+ * @param status - can be null
+ */
+ void addStatus(IPath path, LocalResourceStatus status);
+
+ /**
+ * Ensure that base(pristine) copy of resource syncInfo is present in syncInfo of ResourceInfo of the resource.
+ *
+ * @param resource IResource of status is determined
+ * @throws SVNException
+ * @deprecated should be removed when StatusCacheComposite will be definitely replaced by SynchronizerSyncInfoCache
+ */
+ void ensureBaseStatusInfo(IResource resource) throws SVNException;
+
+ /**
+ * Ensure that base(pristine) copy of resource syncInfo is present in syncInfo of ResourceInfo of the resource.
+ *
+ * @param resource IResource of status is determined
+ * @param depth
+ * @throws SVNException
+ * @deprecated should be removed when StatusCacheComposite will be definitely replaced by SynchronizerSyncInfoCache
+ */
+ void ensureBaseStatusInfo(IResource resource, int depth) throws SVNException;
+
+}

Modified: trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/Synchronize​rSyncInfoCache.java
Url: http://svn.collab.ne​t/viewcvs/subclipse/​trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/Synchronize​rSyncInfoCache.java?​rev=1438&p1=trun​k/subclipse/core/src​/org/tigris/subversi​on/subclipse/core/st​atus/SynchronizerSyn​cInfoCache.java&​p2=trunk/subclipse/c​ore/src/org/tigris/s​ubversion/subclipse/​core/status/Synchron​izerSyncInfoCache.ja​va&r1=1437&r​2=1438
====================​====================​====================​==================
--- trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/Synchronize​rSyncInfoCache.java (original)
+++ trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/status/Synchronize​rSyncInfoCache.java Fri Jul 8 19:38:30 2005
@@ -1,327 +1,327 @@
-/******************​********************​********************​********************​
- * This program and the accompanying materials are made available under
- * the terms of the Common Public License v1.0 which accompanies this
- * distribution, and is available at the following URL:
- * http://www.eclipse.o​rg/legal/cpl-v10.htm​l
- * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
- *
- * All Rights are Reserved by the various authors.
- ********************​********************​********************​*******************/​
-package org.tigris.subversio​n.subclipse.core.sta​tus;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.res​ources.IContainer;
-import org.eclipse.core.res​ources.IResource;
-import org.eclipse.core.res​ources.IResourceStat​us;
-import org.eclipse.core.res​ources.IWorkspaceRoo​t;
-import org.eclipse.core.res​ources.ResourcesPlug​in;
-import org.eclipse.core.run​time.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.tigris.subversio​n.subclipse.core.SVN​Exception;
-import org.tigris.subversio​n.subclipse.core.SVN​ProviderPlugin;
-import org.tigris.subversio​n.subclipse.core.res​ources.LocalResource​Status;
-import org.tigris.subversio​n.svnclientadapter.S​VNNodeKind;
-
-/**
- * Local sync info cache using ResourceInfo.syncInfo for storage.
- *
- */
-public class SynchronizerSyncInfoCache implements IStatusCache, Serializable {
-
- private static final byte[] BYTES_REMOVED = new byte[0];
- private SyncInfoSynchronizedAccessor accessor = new SyncInfoSynchronizedAccessor();
-
- /* (non-Javadoc)
- * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#get​Status(org.eclipse.c​ore.resources.IResou​rce)
- */
- public LocalResourceStatus getStatus(IResource resource){
- try {
- return LocalResourceStatus.​fromBytes(getCachedS​yncBytes(resource));​
- } catch (SVNException e) {
- SVNProviderPlugin.log(e);
- return null;
- }
- }
-
- /* (non-Javadoc)
- * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#add​Status(org.eclipse.c​ore.resources.IResou​rce, org.tigris.subversio​n.subclipse.core.res​ources.LocalResource​Status)
- */
- public void addStatus(IResource resource, LocalResourceStatus status) {
- try {
- if ((status != null) && (status.isUnversioned() || !(resource.exists() || resource.isPhantom())))
- {
- return;
- }
- setCachedSyncBytes(resource, (status != null) ? status.getBytes() : null);
- } catch (SVNException e) {
- SVNProviderPlugin.log(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#add​Status(org.eclipse.c​ore.runtime.IPath, org.tigris.subversio​n.subclipse.core.res​ources.LocalResource​Status)
- */
- public void addStatus(IPath path, LocalResourceStatus status) {
- if ((status != null) && status.isUnversioned())
- {
- return;
- }
- IWorkspaceRoot root = ResourcesPlugin.getW​orkspace().getRoot()​;
- if ((status == null) || (status.getNodeKind() == SVNNodeKind.FILE))
- {
- addStatus(root.getFile(path), status);
- }
- else
- {
- if (path.isRoot())
- {
- addStatus(root, status);
- }
- else if (path.segmentCount() == 1)
- {
- addStatus(root.getPr​oject(path.segment(0​)), status);
- }
- else
- {
- addStatus(root.getFolder(path), status);
- }
- }
- }
-
- private byte[] getCachedSyncBytes(IResource resource) throws SVNException {
- try {
- accessor.flushPendin​gCacheWrites();
- byte[] bytes;
- if (accessor.pendingCac​heContains(resource)​) {
- bytes = accessor.readFromPen​dingCache(resource);​
- if (bytes == BYTES_REMOVED) {
- bytes = null;
- }
- } else {
- bytes = accessor.internalGet​CachedSyncBytes(reso​urce);
- }
-// if (bytes != null && resource.getType() == IResource.FILE) {
-// if (LocalResourceStatus​.isAddition(bytes)) {
-// // The local file has been deleted but was an addition
-// // Therefore, ignoe the sync bytes
-// bytes = null;
-// } else if (!LocalResourceStatu​s.isDeletion(bytes))​ {
-// // Ensure the bytes indicate an outgoing deletion
-// bytes = LocalResourceStatus.​convertToDeletion(by​tes);
-// }
-// }
- return bytes;
- } catch (CoreException e) {
- throw SVNException.wrapException(e);
- }
- }
-
- private void setCachedSyncBytes(IResource resource, byte[] syncBytes) throws SVNException {
- boolean canModifyWorkspace = !ResourcesPlugin.get​Workspace().isTreeLo​cked();
- byte[] oldBytes = getCachedSyncBytes(resource);
- try {
- if (syncBytes == null) {
- if (oldBytes != null) {
- if (canModifyWorkspace) {
- accessor.removeFromP​endingCache(resource​);
- if (resource.exists() || resource.isPhantom()) {
- accessor.internalSet​CachedSyncBytes(reso​urce, null);
- }
- } else {
- if (resource.exists() || resource.isPhantom()) {
- accessor.writeToPend​ingCache(resource, BYTES_REMOVED);
- }
- }
- }
- } else {
- // ensure that the sync info is not already set to the same thing.
- // We do this to avoid causing a resource delta when the sync info is
- // initially loaded (i.e. the synchronizer has it and so does the Entries file
- if (oldBytes == null || !SyncInfoSynchronize​dAccessor.equals(syn​cBytes, oldBytes)) {
- if (canModifyWorkspace) {
- accessor.removeFromP​endingCache(resource​);
- accessor.internalSet​CachedSyncBytes(reso​urce, syncBytes);
- } else {
- accessor.writeToPend​ingCache(resource, syncBytes);
- }
- }
- }
- } catch (CoreException e) {
- throw SVNException.wrapException(e);
- }
- }
-
- /**
- * @param root
- * @param deep
- */
- public void purgeCache(IContainer root, boolean deep) throws SVNException {
- int depth = deep ? IResource.DEPTH_INFINITE : IResource.DEPTH_ZERO;
- try {
- if (root.exists() || root.isPhantom()) {
- ResourcesPlugin.getW​orkspace().getSynchr​onizer().flushSyncIn​fo(StatusCacheManage​r.SVN_BC_SYNC_KEY, root, depth);
- }
- if (deep) {
- accessor.removeRecur​siveFromPendingCache​(root);
- } else {
- accessor.removeFromP​endingCache(root);
- }
- } catch (CoreException e) {
- if (e.getStatus().getCode() == IResourceStatus.RESO​URCE_NOT_FOUND) {
- // Must have been deleted since we checked
- return;
- }
- throw SVNException.wrapException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#ens​ureBaseStatusInfo(or​g.eclipse.core.resou​rces.IResource)
- */
- public void ensureBaseStatusInfo(IResource resource) throws SVNException
- {
- //DO NOTHING.
- //This status cache is using the ResourceInfo#syncInfo as it's native storage,
- //so there is no need to set it explicitely.
- }
-
- /* (non-Javadoc)
- * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#ens​ureBaseStatusInfo(or​g.eclipse.core.resou​rces.IResource, int)
- */
- public void ensureBaseStatusInfo(IResource resource, int depth) throws SVNException
- {
- //DO NOTHING.
- //This status cache is using the ResourceInfo#syncInfo as it's native storage,
- //so there is no need to set it explicitely.
- }
-
-
- private static class SyncInfoSynchronizedAccessor
- {
- // Map of sync bytes that were set without a scheduling rule
- private Map pendingCacheWrites = new HashMap();
-
- /*
- * Retieve the cached sync bytes from the synchronizer. A null
- * is returned if there are no cached sync bytes.
- */
- protected byte[] internalGetCachedSyn​cBytes(IResource resource) throws SVNException {
- try {
- return ResourcesPlugin.getW​orkspace().getSynchr​onizer().getSyncInfo​(StatusCacheManager.​SVN_BC_SYNC_KEY, resource);
- } catch (CoreException e) {
- throw SVNException.wrapException(e);
- }
- }
-
- /*
- * Set the sync bytes to the synchronizer.
- */
- protected void internalSetCachedSyn​cBytes(IResource resource, byte[] syncInfo) throws SVNException {
- try {
- ResourcesPlugin.getW​orkspace().getSynchr​onizer().setSyncInfo​(StatusCacheManager.​SVN_BC_SYNC_KEY, resource, syncInfo);
- } catch (CoreException e) {
- throw SVNException.wrapException(e);
- }
- }
-
- /**
- * Flushes one resource from pending cache write.
- * The method is not synchronized intentionally to prevent deadlocks.
- * One resource at a time is flushed due to same reason.
- */
- protected void flushPendingCacheWrites()
- {
- if ((pendingCacheWrites.size() > 0) && (!ResourcesPlugin.ge​tWorkspace().isTreeL​ocked()))
- {
- System.out.println("​flushPendingCacheWri​tes");
- Map.Entry cachedEntry = nextFromPendingCache();
- if (cachedEntry != null)
- {
- try {
- ResourcesPlugin.getW​orkspace().getSynchr​onizer().setSyncInfo​(StatusCacheManager.​SVN_BC_SYNC_KEY, (IResource) cachedEntry.getKey(), (byte []) cachedEntry.getValue());
- removeFromPendingCac​heIfEqual((IResource​) cachedEntry.getKey(), (byte []) cachedEntry.getValue());
- } catch (CoreException e) {
- SVNProviderPlugin.lo​g(SVNException.wrapE​xception(e));
- }
- }
- }
- }
-
- synchronized private Map.Entry nextFromPendingCache()
- {
- if (pendingCacheWrites.size() > 0)
- {
- return (Map.Entry) pendingCacheWrites.e​ntrySet().iterator()​.next();
- }
- else
- {
- return null;
- }
- }
-
- synchronized protected boolean pendingCacheContains(IResource resource)
- {
- return ((pendingCacheWrites.size() > 0) && (pendingCacheWrites.​containsKey(resource​)));
- }
-
- synchronized protected byte[] readFromPendingCache(IResource resource)
- {
- return (byte[]) pendingCacheWrites.g​et(resource);
- }
-
- synchronized protected void writeToPendingCache(IResource resource, byte[] syncBytes)
- {
- pendingCacheWrites.p​ut(resource, syncBytes);
- }
-
- synchronized protected void removeFromPendingCac​he(IResource resource)
- {
- pendingCacheWrites.r​emove(resource);
- }
-
- /**
- * Remove the resource from cache if the cached bytes are equal to <code>syncByte​s<code>
- * This is because the caller of this method is not synchronized, so if the cache
- * was modified, do not remove the resource ...
- * @param resource
- * @param syncBytes
- */
- synchronized protected void removeFromPendingCac​heIfEqual(IResource resource, byte[] syncBytes)
- {
- byte[] old = (byte[]) pendingCacheWrites.g​et(resource);
- if (equals(old, syncBytes))
- {
- pendingCacheWrites.r​emove(resource);
- }
- }
-
- synchronized protected void removeRecursiveFromP​endingCache(IResourc​e resource)
- {
- IPath fullPath = resource.getFullPath();
- for (Iterator iter = pendingCacheWrites.k​eySet().iterator(); iter.hasNext();) {
- if (fullPath.isPrefixOf​(((IResource) iter.next()).getFullPath())) {
- iter.remove();
- }
- }
- }
-
- /**
- * Method equals.
- * @param syncBytes
- * @param oldBytes
- * @return boolean
- */
- protected static boolean equals(byte[] syncBytes, byte[] oldBytes) {
- if (syncBytes == null || oldBytes == null) return syncBytes == oldBytes;
- if (syncBytes.length != oldBytes.length) return false;
- for (int i = 0; i < oldBytes.length; i++) {
- if (oldBytes[i] != syncBytes[i]) return false;
- }
- return true;
- }
- }
-}
+/******************​********************​********************​********************​
+ * This program and the accompanying materials are made available under
+ * the terms of the Common Public License v1.0 which accompanies this
+ * distribution, and is available at the following URL:
+ * http://www.eclipse.o​rg/legal/cpl-v10.htm​l
+ * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
+ *
+ * All Rights are Reserved by the various authors.
+ ********************​********************​********************​*******************/​
+package org.tigris.subversio​n.subclipse.core.sta​tus;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.res​ources.IContainer;
+import org.eclipse.core.res​ources.IResource;
+import org.eclipse.core.res​ources.IResourceStat​us;
+import org.eclipse.core.res​ources.IWorkspaceRoo​t;
+import org.eclipse.core.res​ources.ResourcesPlug​in;
+import org.eclipse.core.run​time.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.tigris.subversio​n.subclipse.core.SVN​Exception;
+import org.tigris.subversio​n.subclipse.core.SVN​ProviderPlugin;
+import org.tigris.subversio​n.subclipse.core.res​ources.LocalResource​Status;
+import org.tigris.subversio​n.svnclientadapter.S​VNNodeKind;
+
+/**
+ * Local sync info cache using ResourceInfo.syncInfo for storage.
+ *
+ */
+public class SynchronizerSyncInfoCache implements IStatusCache, Serializable {
+
+ private static final byte[] BYTES_REMOVED = new byte[0];
+ private SyncInfoSynchronizedAccessor accessor = new SyncInfoSynchronizedAccessor();
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#get​Status(org.eclipse.c​ore.resources.IResou​rce)
+ */
+ public LocalResourceStatus getStatus(IResource resource){
+ try {
+ return LocalResourceStatus.​fromBytes(getCachedS​yncBytes(resource));​
+ } catch (SVNException e) {
+ SVNProviderPlugin.log(e);
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#add​Status(org.eclipse.c​ore.resources.IResou​rce, org.tigris.subversio​n.subclipse.core.res​ources.LocalResource​Status)
+ */
+ public void addStatus(IResource resource, LocalResourceStatus status) {
+ try {
+ if ((status != null) && (status.isUnversioned() || !(resource.exists() || resource.isPhantom())))
+ {
+ return;
+ }
+ setCachedSyncBytes(resource, (status != null) ? status.getBytes() : null);
+ } catch (SVNException e) {
+ SVNProviderPlugin.log(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#add​Status(org.eclipse.c​ore.runtime.IPath, org.tigris.subversio​n.subclipse.core.res​ources.LocalResource​Status)
+ */
+ public void addStatus(IPath path, LocalResourceStatus status) {
+ if ((status != null) && status.isUnversioned())
+ {
+ return;
+ }
+ IWorkspaceRoot root = ResourcesPlugin.getW​orkspace().getRoot()​;
+ if ((status == null) || (status.getNodeKind() == SVNNodeKind.FILE))
+ {
+ addStatus(root.getFile(path), status);
+ }
+ else
+ {
+ if (path.isRoot())
+ {
+ addStatus(root, status);
+ }
+ else if (path.segmentCount() == 1)
+ {
+ addStatus(root.getPr​oject(path.segment(0​)), status);
+ }
+ else
+ {
+ addStatus(root.getFolder(path), status);
+ }
+ }
+ }
+
+ private byte[] getCachedSyncBytes(IResource resource) throws SVNException {
+ try {
+ accessor.flushPendin​gCacheWrites();
+ byte[] bytes;
+ if (accessor.pendingCac​heContains(resource)​) {
+ bytes = accessor.readFromPen​dingCache(resource);​
+ if (bytes == BYTES_REMOVED) {
+ bytes = null;
+ }
+ } else {
+ bytes = accessor.internalGet​CachedSyncBytes(reso​urce);
+ }
+// if (bytes != null && resource.getType() == IResource.FILE) {
+// if (LocalResourceStatus​.isAddition(bytes)) {
+// // The local file has been deleted but was an addition
+// // Therefore, ignoe the sync bytes
+// bytes = null;
+// } else if (!LocalResourceStatu​s.isDeletion(bytes))​ {
+// // Ensure the bytes indicate an outgoing deletion
+// bytes = LocalResourceStatus.​convertToDeletion(by​tes);
+// }
+// }
+ return bytes;
+ } catch (CoreException e) {
+ throw SVNException.wrapException(e);
+ }
+ }
+
+ private void setCachedSyncBytes(IResource resource, byte[] syncBytes) throws SVNException {
+ boolean canModifyWorkspace = !ResourcesPlugin.get​Workspace().isTreeLo​cked();
+ byte[] oldBytes = getCachedSyncBytes(resource);
+ try {
+ if (syncBytes == null) {
+ if (oldBytes != null) {
+ if (canModifyWorkspace) {
+ accessor.removeFromP​endingCache(resource​);
+ if (resource.exists() || resource.isPhantom()) {
+ accessor.internalSet​CachedSyncBytes(reso​urce, null);
+ }
+ } else {
+ if (resource.exists() || resource.isPhantom()) {
+ accessor.writeToPend​ingCache(resource, BYTES_REMOVED);
+ }
+ }
+ }
+ } else {
+ // ensure that the sync info is not already set to the same thing.
+ // We do this to avoid causing a resource delta when the sync info is
+ // initially loaded (i.e. the synchronizer has it and so does the Entries file
+ if (oldBytes == null || !SyncInfoSynchronize​dAccessor.equals(syn​cBytes, oldBytes)) {
+ if (canModifyWorkspace) {
+ accessor.removeFromP​endingCache(resource​);
+ accessor.internalSet​CachedSyncBytes(reso​urce, syncBytes);
+ } else {
+ accessor.writeToPend​ingCache(resource, syncBytes);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ throw SVNException.wrapException(e);
+ }
+ }
+
+ /**
+ * @param root
+ * @param deep
+ */
+ public void purgeCache(IContainer root, boolean deep) throws SVNException {
+ int depth = deep ? IResource.DEPTH_INFINITE : IResource.DEPTH_ZERO;
+ try {
+ if (root.exists() || root.isPhantom()) {
+ ResourcesPlugin.getW​orkspace().getSynchr​onizer().flushSyncIn​fo(StatusCacheManage​r.SVN_BC_SYNC_KEY, root, depth);
+ }
+ if (deep) {
+ accessor.removeRecur​siveFromPendingCache​(root);
+ } else {
+ accessor.removeFromP​endingCache(root);
+ }
+ } catch (CoreException e) {
+ if (e.getStatus().getCode() == IResourceStatus.RESO​URCE_NOT_FOUND) {
+ // Must have been deleted since we checked
+ return;
+ }
+ throw SVNException.wrapException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#ens​ureBaseStatusInfo(or​g.eclipse.core.resou​rces.IResource)
+ */
+ public void ensureBaseStatusInfo(IResource resource) throws SVNException
+ {
+ //DO NOTHING.
+ //This status cache is using the ResourceInfo#syncInfo as it's native storage,
+ //so there is no need to set it explicitely.
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.subclipse.core.sta​tus.IStatusCache#ens​ureBaseStatusInfo(or​g.eclipse.core.resou​rces.IResource, int)
+ */
+ public void ensureBaseStatusInfo(IResource resource, int depth) throws SVNException
+ {
+ //DO NOTHING.
+ //This status cache is using the ResourceInfo#syncInfo as it's native storage,
+ //so there is no need to set it explicitely.
+ }
+
+
+ private static class SyncInfoSynchronizedAccessor
+ {
+ // Map of sync bytes that were set without a scheduling rule
+ private Map pendingCacheWrites = new HashMap();
+
+ /*
+ * Retieve the cached sync bytes from the synchronizer. A null
+ * is returned if there are no cached sync bytes.
+ */
+ protected byte[] internalGetCachedSyn​cBytes(IResource resource) throws SVNException {
+ try {
+ return ResourcesPlugin.getW​orkspace().getSynchr​onizer().getSyncInfo​(StatusCacheManager.​SVN_BC_SYNC_KEY, resource);
+ } catch (CoreException e) {
+ throw SVNException.wrapException(e);
+ }
+ }
+
+ /*
+ * Set the sync bytes to the synchronizer.
+ */
+ protected void internalSetCachedSyn​cBytes(IResource resource, byte[] syncInfo) throws SVNException {
+ try {
+ ResourcesPlugin.getW​orkspace().getSynchr​onizer().setSyncInfo​(StatusCacheManager.​SVN_BC_SYNC_KEY, resource, syncInfo);
+ } catch (CoreException e) {
+ throw SVNException.wrapException(e);
+ }
+ }
+
+ /**
+ * Flushes one resource from pending cache write.
+ * The method is not synchronized intentionally to prevent deadlocks.
+ * One resource at a time is flushed due to same reason.
+ */
+ protected void flushPendingCacheWrites()
+ {
+ if ((pendingCacheWrites.size() > 0) && (!ResourcesPlugin.ge​tWorkspace().isTreeL​ocked()))
+ {
+ System.out.println("​flushPendingCacheWri​tes");
+ Map.Entry cachedEntry = nextFromPendingCache();
+ if (cachedEntry != null)
+ {
+ try {
+ ResourcesPlugin.getW​orkspace().getSynchr​onizer().setSyncInfo​(StatusCacheManager.​SVN_BC_SYNC_KEY, (IResource) cachedEntry.getKey(), (byte []) cachedEntry.getValue());
+ removeFromPendingCac​heIfEqual((IResource​) cachedEntry.getKey(), (byte []) cachedEntry.getValue());
+ } catch (CoreException e) {
+ SVNProviderPlugin.lo​g(SVNException.wrapE​xception(e));
+ }
+ }
+ }
+ }
+
+ synchronized private Map.Entry nextFromPendingCache()
+ {
+ if (pendingCacheWrites.size() > 0)
+ {
+ return (Map.Entry) pendingCacheWrites.e​ntrySet().iterator()​.next();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ synchronized protected boolean pendingCacheContains(IResource resource)
+ {
+ return ((pendingCacheWrites.size() > 0) && (pendingCacheWrites.​containsKey(resource​)));
+ }
+
+ synchronized protected byte[] readFromPendingCache(IResource resource)
+ {
+ return (byte[]) pendingCacheWrites.g​et(resource);
+ }
+
+ synchronized protected void writeToPendingCache(IResource resource, byte[] syncBytes)
+ {
+ pendingCacheWrites.p​ut(resource, syncBytes);
+ }
+
+ synchronized protected void removeFromPendingCac​he(IResource resource)
+ {
+ pendingCacheWrites.r​emove(resource);
+ }
+
+ /**
+ * Remove the resource from cache if the cached bytes are equal to <code>syncByte​s<code>
+ * This is because the caller of this method is not synchronized, so if the cache
+ * was modified, do not remove the resource ...
+ * @param resource
+ * @param syncBytes
+ */
+ synchronized protected void removeFromPendingCac​heIfEqual(IResource resource, byte[] syncBytes)
+ {
+ byte[] old = (byte[]) pendingCacheWrites.g​et(resource);
+ if (equals(old, syncBytes))
+ {
+ pendingCacheWrites.r​emove(resource);
+ }
+ }
+
+ synchronized protected void removeRecursiveFromP​endingCache(IResourc​e resource)
+ {
+ IPath fullPath = resource.getFullPath();
+ for (Iterator iter = pendingCacheWrites.k​eySet().iterator(); iter.hasNext();) {
+ if (fullPath.isPrefixOf​(((IResource) iter.next()).getFullPath())) {
+ iter.remove();
+ }
+ }
+ }
+
+ /**
+ * Method equals.
+ * @param syncBytes
+ * @param oldBytes
+ * @return boolean
+ */
+ protected static boolean equals(byte[] syncBytes, byte[] oldBytes) {
+ if (syncBytes == null || oldBytes == null) return syncBytes == oldBytes;
+ if (syncBytes.length != oldBytes.length) return false;
+ for (int i = 0; i < oldBytes.length; i++) {
+ if (oldBytes[i] != syncBytes[i]) return false;
+ }
+ return true;
+ }
+ }
+}

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

subclipse commit: r1438 - trunk/subclipse/core/src/org/tigris/subversion/subclipse/core/status markphip Mark Phippard 2005-07-08 17:38:32 PDT
Messages per page: