Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8b3be7c1ffb4824f717ade1060e8d4f074b7ffbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. 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
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.core;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.core.variants.IResourceVariantComparator;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;

/**
 * CVSRevisionNumberCompareCriteria
 */
 public class CVSRevisionNumberCompareCriteria implements IResourceVariantComparator {
 	
	private boolean isThreeWay;

	public CVSRevisionNumberCompareCriteria(boolean isThreeWay) {
		this.isThreeWay = isThreeWay;
	}

	/* (non-Javadoc)
	 * @see ComparisonCriteria#compare(Object, Object, IProgressMonitor)
	 */
	public boolean compare(Object e1, Object e2) {
		if(e1 instanceof IResource && e2 instanceof ICVSRemoteResource) {
			return compare((IResource)e1, (ICVSRemoteResource)e2);
		} else if(e1 instanceof ICVSRemoteResource && e2 instanceof ICVSRemoteResource) {
			return compare((ICVSRemoteResource)e1, (ICVSRemoteResource)e2);
		}
		return false;
	}
	
	/**
	 * @see RemoteSyncElement#timestampEquals(IResourceVariant, IResourceVariant)
	 */
	protected boolean compare(ICVSRemoteResource e1, ICVSRemoteResource e2) {
		if(e1.isContainer()) {
			if(e2.isContainer()) {
				return true;
			}
			return false;
		}
		return e1.equals(e2);
	}

	/**
	 * @see RemoteSyncElement#timestampEquals(IResource, IResourceVariant)
	 */
	protected boolean compare(IResource e1, ICVSRemoteResource e2) {
		if(e1.getType() != IResource.FILE) {
			if(e2.isContainer()) {
				return true;
			}
			return false;
		}
		ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor((IFile)e1);
		try {
			byte[] syncBytes1 = cvsFile.getSyncBytes();
			byte[] syncBytes2 = ((ICVSRemoteFile)e2).getSyncBytes();
		
			if(syncBytes1 != null) {
				if(ResourceSyncInfo.isDeletion(syncBytes1) || ResourceSyncInfo.isMerge(syncBytes1) || cvsFile.isModified(null)) {
					return false;
				}
				return ResourceSyncInfo.getRevision(syncBytes1).equals(ResourceSyncInfo.getRevision(syncBytes2));
			}
			return false;
		} catch(CVSException e) {
			CVSProviderPlugin.log(e);
			return false;
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.core.subscribers.IComparisonCriteria#compare(org.eclipse.core.resources.IResource, org.eclipse.team.core.subscribers.ISubscriberResource)
	 */
	public boolean compare(IResource local, IResourceVariant remote) {
		return compare(local, (ICVSRemoteResource)remote);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.core.subscribers.IComparisonCriteria#compare(org.eclipse.team.core.subscribers.ISubscriberResource, org.eclipse.team.core.subscribers.ISubscriberResource)
	 */
	public boolean compare(IResourceVariant base, IResourceVariant remote) {
		return compare((ICVSRemoteResource)base, (ICVSRemoteResource)remote);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.core.subscribers.ISubscriberResourceComparator#isThreeWay()
	 */
	public boolean isThreeWay() {
		return isThreeWay;
	}
}

Back to the top