Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 163818 Details for
Bug 36436
[Merge] CVS substituted keywords treated as conflicts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Avoid conflicts in Sync Preview
PreviewMerge_36436_patch.txt (text/plain), 11.92 KB, created by
Axel Mueller
on 2010-04-05 13:36:48 EDT
(
hide
)
Description:
Avoid conflicts in Sync Preview
Filename:
MIME Type:
Creator:
Axel Mueller
Created:
2010-04-05 13:36:48 EDT
Size:
11.92 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.team.cvs.core >Index: src/org/eclipse/team/internal/ccvs/core/CVSContentComparator.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ccvs/core/CVSContentComparator.java >diff -N src/org/eclipse/team/internal/ccvs/core/CVSContentComparator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ccvs/core/CVSContentComparator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,201 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Axel Mueller and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Axel Mueller - initial implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ccvs.core; >+ >+import java.io.*; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.team.core.TeamException; >+import org.eclipse.team.core.history.IFileRevision; >+import org.eclipse.team.core.variants.IResourceVariant; >+import org.eclipse.team.internal.core.Policy; >+import org.eclipse.team.internal.core.TeamPlugin; >+ >+/** >+ * This is an internal class that is used by the <code>CVSContentComparisonSyncInfoFilter</code> >+ * to compare the contents of the local and remote resources >+ */ >+public class CVSContentComparator { >+ >+ private final static String[] CVSKeywords = new String[] { >+ "Id:", //$NON-NLS-1$ >+ "Revision:", //$NON-NLS-1$ >+ "Date:", //$NON-NLS-1$ >+ "Author:", //$NON-NLS-1$ >+ "Log:", //$NON-NLS-1$ >+ "Header:", //$NON-NLS-1$ >+ "Name:" }; //$NON-NLS-1$ >+ >+ private final static int MaxKeywordLen = 9; >+ >+ public CVSContentComparator() { >+ } >+ >+ public boolean compare(Object e1, Object e2, IProgressMonitor monitor) { >+ InputStream is1 = null; >+ InputStream is2 = null; >+ try { >+ monitor.beginTask(null, 100); >+ is1 = getContents(e1, Policy.subMonitorFor(monitor, 50)); >+ is2 = getContents(e2, Policy.subMonitorFor(monitor, 50)); >+ return contentsEqual(is1, is2); >+ } catch(TeamException e) { >+ TeamPlugin.log(e); >+ return false; >+ } finally { >+ try { >+ try { >+ if (is1 != null) { >+ is1.close(); >+ } >+ } finally { >+ if (is2 != null) { >+ is2.close(); >+ } >+ } >+ } catch (IOException e) { >+ // Ignore >+ } >+ monitor.done(); >+ } >+ } >+ >+ /** >+ * Returns <code>true</code> if both input streams byte contents is >+ * identical. >+ * >+ * @param input1 >+ * first input to contents compare >+ * @param input2 >+ * second input to contents compare >+ * @return <code>true</code> if content is equal >+ */ >+ private boolean contentsEqual(InputStream is1, InputStream is2) { >+ try { >+ if (is1 == is2) >+ return true; >+ >+ if (is1 == null && is2 == null) // no byte contents >+ return true; >+ >+ if (is1 == null || is2 == null) // only one has contents >+ return false; >+ >+ boolean StartFound = false; >+ boolean KeywordFound = false; >+ char[] Buffer = new char[MaxKeywordLen]; >+ int Idx = 0; >+ >+ while (true) { >+ int c1 = is1.read(); >+ // if keyword was found ignore everything until the next '$' that marks the end >+ while (KeywordFound && !isDollar(c1)) >+ c1 = is1.read(); >+ int c2 = is2.read(); >+ // if keyword was found ignore everything until the next '$' that marks the end >+ while (KeywordFound && !isDollar(c2)) >+ c2 = is2.read(); >+ // keywords starts and ends with a '$' >+ if (isDollar(c1)){ >+ if (StartFound){ // restart search when we get the second '$' >+ StartFound = false; >+ KeywordFound = false; >+ Idx = 0; >+ } >+ else >+ StartFound = true; >+ } >+ if (c1 == -1 && c2 == -1) >+ return true; >+ if (c1 != c2) >+ break; >+ // we have a possible start but no keyword identified yet >+ if (StartFound && !KeywordFound){ >+ if (!isDollar(c1)){ >+ Buffer[Idx] = (char)c1; // save to temporary buffer (w/o starting '$') >+ ++Idx; >+ } >+ if (isColon(c1)) // colon marks the end of a possible keyword >+ { >+ // check for keyword >+ String key = new String(Buffer,0,Idx); >+ for (int i = 0; i < CVSKeywords.length; i++) { >+ if (CVSKeywords[i].equals(key)){ >+ KeywordFound = true; >+ break; >+ } >+ } >+ if (!KeywordFound) >+ { >+ StartFound = false; >+ Idx = 0; >+ } >+ >+ } else if (Idx >= MaxKeywordLen) >+ { // still no colon then stop search >+ StartFound = false; >+ KeywordFound = false; >+ Idx = 0; >+ } >+ } >+ } >+ } catch (IOException ex) { >+ } finally { >+ try { >+ try { >+ if (is1 != null) { >+ is1.close(); >+ } >+ } finally { >+ if (is2 != null) { >+ is2.close(); >+ } >+ } >+ } catch (IOException e) { >+ // Ignore >+ } >+ } >+ return false; >+ } >+ >+ private boolean isDollar(int c) { >+ if (c == -1) >+ return false; >+ return (((char)c) == '$'); >+ } >+ >+ private boolean isColon(int c) { >+ if (c == -1) >+ return false; >+ return (((char)c) == ':'); >+ } >+ >+ private InputStream getContents(Object resource, IProgressMonitor monitor) throws TeamException { >+ try { >+ if (resource instanceof IFile) { >+ return new BufferedInputStream(((IFile) resource).getContents()); >+ } else if(resource instanceof IResourceVariant) { >+ IResourceVariant remote = (IResourceVariant)resource; >+ if (!remote.isContainer()) { >+ return new BufferedInputStream(remote.getStorage(monitor).getContents()); >+ } >+ } else if(resource instanceof IFileRevision) { >+ IFileRevision remote = (IFileRevision)resource; >+ return new BufferedInputStream(remote.getStorage(monitor).getContents()); >+ } >+ return null; >+ } catch (CoreException e) { >+ throw TeamException.asTeamException(e); >+ } >+ } >+} >Index: src/org/eclipse/team/internal/ccvs/core/CVSContentComparisonSyncInfoFilter.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ccvs/core/CVSContentComparisonSyncInfoFilter.java >diff -N src/org/eclipse/team/internal/ccvs/core/CVSContentComparisonSyncInfoFilter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ccvs/core/CVSContentComparisonSyncInfoFilter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,69 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Axel Mueller and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Axel Mueller - initial implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ccvs.core; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.team.core.synchronize.SyncInfo; >+import org.eclipse.team.core.synchronize.SyncInfoFilter; >+import org.eclipse.team.core.variants.IResourceVariant; >+ >+ >+/** >+ * Selects <code>SyncInfo</code> whose local and remote contents match. >+ * This filter makes use of the <code>IStorage</code> provided by >+ * an <code>IResourceVariant</code> to obtain the remote contents. >+ * This means that the comparison may contact the server unless the contents >+ * were cached locally by a previous operation. The caching of remote >+ * contents is subscriber specific. >+ * Differences in CVS keywords are ignored, e.g. different revisions that cause >+ * pseudo conflicts during merging. >+ * <p> >+ * For folders, the comparison always returns <code>true</code>. >+ */ >+public class CVSContentComparisonSyncInfoFilter extends SyncInfoFilter { >+ CVSContentComparator criteria = new CVSContentComparator(); >+ >+ public CVSContentComparisonSyncInfoFilter() { >+ criteria = new CVSContentComparator(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.team.core.synchronize.SyncInfoFilter#select(org.eclipse.team.core.synchronize.SyncInfo, org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public boolean select(SyncInfo info, IProgressMonitor monitor) { >+ IResourceVariant remote = info.getRemote(); >+ IResource local = info.getLocal(); >+ if (local.getType() != IResource.FILE) return true; >+ if (remote == null) return !local.exists(); >+ if (!local.exists()) return false; >+ return compareContents((IFile)local, remote, monitor); >+ } >+ >+ /** >+ * Compare the contents of the local file and its variant. >+ * This is used by the <code>select</code> method to compare the >+ * contents of two non-null files. >+ * @param local a local file >+ * @param remote a resource variant of the file >+ * @param monitor a progress monitor >+ * @return whether the contents of the two files are equal >+ */ >+ public boolean compareContents(IFile local, IResourceVariant remote, IProgressMonitor monitor) { >+ Assert.isNotNull(local); >+ Assert.isNotNull(remote); >+ return criteria.compare(local, remote, monitor); >+ } >+} >+ >+ >Index: src/org/eclipse/team/internal/ccvs/core/CVSMergeSubscriber.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSMergeSubscriber.java,v >retrieving revision 1.39 >diff -u -r1.39 CVSMergeSubscriber.java >--- src/org/eclipse/team/internal/ccvs/core/CVSMergeSubscriber.java 10 Apr 2006 14:27:17 -0000 1.39 >+++ src/org/eclipse/team/internal/ccvs/core/CVSMergeSubscriber.java 5 Apr 2010 17:23:48 -0000 >@@ -23,6 +23,8 @@ > import org.eclipse.team.core.synchronize.SyncInfo; > import org.eclipse.team.core.synchronize.SyncInfoFilter; > import org.eclipse.team.core.variants.*; >+import org.eclipse.team.internal.ccvs.core.client.Command; >+import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption; > import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; > import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; > import org.eclipse.team.internal.ccvs.core.syncinfo.CVSResourceVariantTree; >@@ -317,6 +319,8 @@ > if (refreshed.length == 0) return; > SyncInfoFilter.ContentComparisonSyncInfoFilter contentFilter = > new SyncInfoFilter.ContentComparisonSyncInfoFilter(); >+ CVSContentComparisonSyncInfoFilter CVSKeywordscontentFilter = >+ new CVSContentComparisonSyncInfoFilter(); > monitor.beginTask(null, refreshed.length * 100); > for (int i = 0; i < refreshed.length; i++) { > IResource resource = refreshed[i]; >@@ -327,10 +331,18 @@ > if (remoteBytes != null > && localBytes != null > && local.exists() >- && !ResourceSyncInfo.getRevision(remoteBytes).equals(ResourceSyncInfo.getRevision(localBytes)) >- && contentFilter.select(getSyncInfo(resource), Policy.subMonitorFor(monitor, 100))) { >- // The contents are equals so mark the file as merged >- internalMerged(resource); >+ && !ResourceSyncInfo.getRevision(remoteBytes).equals(ResourceSyncInfo.getRevision(localBytes)) ){ >+ boolean isContentDifferent; >+ KSubstOption localKSubst = ResourceSyncInfo.getKeywordMode(localBytes); >+ if ( localKSubst.equals(Command.KSUBST_BINARY) || localKSubst.equals(Command.KSUBST_TEXT) ){//TODO: check keywordMode of remote file, too? >+ isContentDifferent = contentFilter.select(getSyncInfo(resource), Policy.subMonitorFor(monitor, 100)); >+ } else { >+ isContentDifferent = CVSKeywordscontentFilter.select(getSyncInfo(resource), Policy.subMonitorFor(monitor, 100)); >+ } >+ if (isContentDifferent) { >+ // The contents are equals so mark the file as merged >+ internalMerged(resource); >+ } > } > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 36436
:
163174
| 163818