Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 366016 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/RemoteFolderElement.java (-3 / +34 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 57-63 Link Here
57
    public Object[] fetchChildren(Object o, IProgressMonitor monitor) throws TeamException {
57
    public Object[] fetchChildren(Object o, IProgressMonitor monitor) throws TeamException {
58
        if (!(o instanceof ICVSRemoteFolder))
58
        if (!(o instanceof ICVSRemoteFolder))
59
            return new Object[0];
59
            return new Object[0];
60
        return ((ICVSRemoteFolder) o).members(monitor);
60
		try {
61
			monitor = Policy.monitorFor(monitor);
62
			monitor.beginTask(NLS.bind(
63
					CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
64
					new String[] { getLabel(o) }), 150);
65
			ICVSRemoteFolder folder = (ICVSRemoteFolder) o;
66
			ICVSRemoteResource[] cachedChildren = CVSUIPlugin
67
					.getPlugin()
68
					.getRepositoryManager()
69
					.getCachedChildrenForTag(folder.getRepository(), folder,
70
							folder.getTag(), Policy.subMonitorFor(monitor, 50));
71
			if (cachedChildren.length > 0) {
72
				return cachedChildren;
73
			}
74
			return folder.members(Policy.subMonitorFor(monitor, 100));
75
		} finally {
76
			monitor.done();
77
		}
61
    }
78
    }
62
79
63
    public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
80
    public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
Lines 67-79 Link Here
67
		}
84
		}
68
        try {
85
        try {
69
            monitor = Policy.monitorFor(monitor);
86
            monitor = Policy.monitorFor(monitor);
70
            monitor.beginTask(NLS.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren, new String[] { getLabel(o) }), 100); 
87
			monitor.beginTask(NLS.bind(
88
					CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
89
					new String[] { getLabel(o) }), 150);
90
			ICVSRemoteFolder folder = (ICVSRemoteFolder) o;
91
			ICVSRemoteResource[] cachedChildren = CVSUIPlugin
92
					.getPlugin()
93
					.getRepositoryManager()
94
					.getCachedChildrenForTag(folder.getRepository(), folder,
95
							folder.getTag(), Policy.subMonitorFor(monitor, 50));
96
			if (cachedChildren.length > 0) {
97
				collector.add(cachedChildren, monitor);
98
				return;
99
			}
71
			FetchMembersOperation operation = new FetchMembersOperation(null, (ICVSRemoteFolder)o, collector);
100
			FetchMembersOperation operation = new FetchMembersOperation(null, (ICVSRemoteFolder)o, collector);
72
			operation.run(Policy.subMonitorFor(monitor, 100));
101
			operation.run(Policy.subMonitorFor(monitor, 100));
73
        } catch (InvocationTargetException e) {
102
        } catch (InvocationTargetException e) {
74
            handle(collector, e);
103
            handle(collector, e);
75
		} catch (InterruptedException e) {
104
		} catch (InterruptedException e) {
76
			// Cancelled by the user;
105
			// Cancelled by the user;
106
		} catch (CVSException e) {
107
			 handle(collector, e);
77
		} finally {
108
		} finally {
78
            monitor.done();
109
            monitor.done();
79
        }
110
        }
(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java (-16 / +61 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 142-156 Link Here
142
		Set result = new HashSet();
142
		Set result = new HashSet();
143
		RepositoryRoot root = (RepositoryRoot)repositoryRoots.get(location.getLocation(false));
143
		RepositoryRoot root = (RepositoryRoot)repositoryRoots.get(location.getLocation(false));
144
		if (root != null) {
144
		if (root != null) {
145
			String[] paths = root.getKnownRemotePaths();
145
			CVSTag[] tags = root.getAllKnownTags();
146
			for (int i = 0; i < paths.length; i++) {
146
			for (int i = 0; i < tags.length; i++) {
147
				String path = paths[i];
147
				CVSTag tag = tags[i];
148
				CVSTag[] tags = root.getAllKnownTags(path);
148
				if (tag.getType() == tagType)
149
				for (int j = 0; j < tags.length; j++) {
149
					result.add(tag);
150
					CVSTag tag = tags[j];
151
					if (tag.getType() == tagType)
152
						result.add(tag);
153
				}
154
			}
150
			}
155
		}
151
		}
156
		return (CVSTag[])result.toArray(new CVSTag[0]);
152
		return (CVSTag[])result.toArray(new CVSTag[0]);
Lines 225-244 Link Here
225
			Set result = new HashSet();
221
			Set result = new HashSet();
226
			// Get the tags for the location
222
			// Get the tags for the location
227
			RepositoryRoot root = getRepositoryRootFor(location);
223
			RepositoryRoot root = getRepositoryRootFor(location);
228
			String[] paths = root.getKnownRemotePaths();
224
			String[] paths = root.getRemoteChildrenForTag(null, tag);
229
			for (int i = 0; i < paths.length; i++) {
225
			for (int i = 0; i < paths.length; i++) {
230
				String path = paths[i];
226
				String path = paths[i];
231
				List tags = Arrays.asList(root.getAllKnownTags(path));
227
				ICVSRemoteFolder remote = root.getRemoteFolder(path, tag,
232
				if (tags.contains(tag)) {
228
						Policy.subMonitorFor(monitor, 100));
233
					ICVSRemoteFolder remote = root.getRemoteFolder(path, tag, Policy.subMonitorFor(monitor, 100));
229
				result.add(remote);
234
					result.add(remote);
235
				}
236
			}
230
			}
237
			return (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[result.size()]);
231
			return (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[result.size()]);
238
		} finally {
232
		} finally {
239
			monitor.done();
233
			monitor.done();
240
		}
234
		}
241
	}
235
	}
236
237
	/**
238
	 * Returns a list of child resources for given folder that are known to
239
	 * contain given tag. If the return list is empty than given tag exists
240
	 * directly in given folder and its children should be retrieved directly
241
	 * from the repository.
242
	 * 
243
	 * @param location
244
	 *            CVS repository location
245
	 * @param parentFolder
246
	 *            folder to check tags for
247
	 * @param tag
248
	 * @param monitor
249
	 * @return a list of remote resources that are known to contain given tag or
250
	 *         empty list if resources should be retrieved from the repository
251
	 * @throws CVSException
252
	 */
253
	public ICVSRemoteResource[] getCachedChildrenForTag(
254
			ICVSRepositoryLocation location, ICVSRemoteFolder parentFolder,
255
			CVSTag tag, IProgressMonitor monitor) throws CVSException {
256
		if (tag == null || tag.getType() == CVSTag.HEAD
257
				|| tag.getType() == CVSTag.DATE) {
258
			// folders are kept in cache only for tags and versions
259
			return new ICVSRemoteResource[0];
260
		}
261
		monitor = Policy.monitorFor(monitor);
262
		Set result = new HashSet();
263
		RepositoryRoot root = getRepositoryRootFor(location);
264
		// if remote folder is null return the subfolders of repository root
265
		String[] paths = root.getRemoteChildrenForTag(
266
				parentFolder == null ? null : RepositoryRoot
267
						.getRemotePathFor(parentFolder), tag);
268
		monitor.beginTask(NLS
269
				.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
270
						new String[] { NLS.bind(
271
								CVSUIMessages.RemoteFolderElement_nameAndTag,
272
								new String[] { parentFolder.getName(),
273
										tag.getName() }) }), 10 * paths.length);
274
		try {
275
			for (int i = 0; i < paths.length; i++) {
276
				String path = paths[i];
277
				ICVSRemoteFolder remote = root.getRemoteFolder(path, tag,
278
						Policy.subMonitorFor(monitor, 10));
279
				result.add(remote);
280
			}
281
			return (ICVSRemoteResource[]) result
282
					.toArray(new ICVSRemoteResource[result.size()]);
283
		} finally {
284
			monitor.done();
285
		}
286
	}
242
		
287
		
243
	/*
288
	/*
244
	 * Fetches tags from auto-refresh files if they exist. Then fetches tags from the user defined auto-refresh file
289
	 * Fetches tags from auto-refresh files if they exist. Then fetches tags from the user defined auto-refresh file
(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryRoot.java (-87 / +243 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 25-31 Link Here
25
import org.eclipse.team.internal.ccvs.ui.Policy;
25
import org.eclipse.team.internal.ccvs.ui.Policy;
26
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation;
26
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation;
27
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation.LogEntryCache;
27
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation.LogEntryCache;
28
import org.eclipse.team.internal.ccvs.ui.tags.TagSource;
29
28
30
public class RepositoryRoot extends PlatformObject {
29
public class RepositoryRoot extends PlatformObject {
31
30
Lines 34-41 Link Here
34
	
33
	
35
	ICVSRepositoryLocation root;
34
	ICVSRepositoryLocation root;
36
	String name;
35
	String name;
37
	// Map of String (remote folder path) -> TagCacheEntry
36
	TagCacheEntry rootTagCacheEntry = new TagCacheEntry(Path.ROOT.toString(),
38
	Map versionAndBranchTags = new HashMap();
37
			null);
39
	// Map of String (remote folder path) -> Set (file paths that are project relative)
38
	// Map of String (remote folder path) -> Set (file paths that are project relative)
40
	Map autoRefreshFiles = new HashMap();
39
	Map autoRefreshFiles = new HashMap();
41
	// Map of String (module name) -> ICVSRemoteFolder (that is a defined module)
40
	// Map of String (module name) -> ICVSRemoteFolder (that is a defined module)
Lines 45-56 Link Here
45
	List dateTags = new ArrayList();
44
	List dateTags = new ArrayList();
46
	
45
	
47
	public static class TagCacheEntry {
46
	public static class TagCacheEntry {
47
		String path;
48
		// Set of tags found for this path
48
	    Set tags = new HashSet();
49
	    Set tags = new HashSet();
50
		// String(last path segment) -> TagCacheEntry for child paths
51
		Map children = new HashMap();
52
		TagCacheEntry parent;
49
	    long lastAccessTime;
53
	    long lastAccessTime;
50
        private static final int CACHE_LIFESPAN_IN_DAYS = 7;
54
        private static final int CACHE_LIFESPAN_IN_DAYS = 7;
51
        public TagCacheEntry() {
55
52
            accessed();
56
		public TagCacheEntry(String path, TagCacheEntry parent) {
53
        }
57
			this.path = path;
58
			this.parent = parent;
59
			accessed();
60
		}
61
54
        public boolean isExpired() {
62
        public boolean isExpired() {
55
            long currentTime = System.currentTimeMillis();
63
            long currentTime = System.currentTimeMillis();
56
            long ms = currentTime - lastAccessTime;
64
            long ms = currentTime - lastAccessTime;
Lines 190-196 Link Here
190
	 * 
198
	 * 
191
	 * It is the responsibility of the caller to ensure that the given remote path is valid.
199
	 * It is the responsibility of the caller to ensure that the given remote path is valid.
192
	 */
200
	 */
193
	public void addTags(String remotePath, CVSTag[] tags) {	
201
	public void addTags(String remotePath, CVSTag[] tags) {
202
		if (tags.length == 0) {
203
			return;
204
		}
194
		addDateTags(tags);
205
		addDateTags(tags);
195
		addVersionAndBranchTags(remotePath, tags);
206
		addVersionAndBranchTags(remotePath, tags);
196
	}
207
	}
Lines 203-224 Link Here
203
		}
214
		}
204
	}
215
	}
205
	private void addVersionAndBranchTags(String remotePath, CVSTag[] tags) {
216
	private void addVersionAndBranchTags(String remotePath, CVSTag[] tags) {
206
		// Get the name to cache the version tags with
217
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, true);
207
		String name = getCachePathFor(remotePath);
218
		entry.accessed();
208
		
219
209
		// Make sure there is a table for the ancestor that holds the tags
210
		TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(name);
211
		if (entry == null) {
212
		    entry = new TagCacheEntry();
213
			versionAndBranchTags.put(name, entry);
214
		} else {
215
		    entry.accessed();
216
		}
217
		
218
		// Store the tag with the appropriate ancestor
220
		// Store the tag with the appropriate ancestor
219
		for (int i = 0; i < tags.length; i++) {
221
		for (int i = 0; i < tags.length; i++) {
220
			if(tags[i].getType() != CVSTag.DATE){
222
			if (tags[i].getType() != CVSTag.DATE) {
221
				entry.tags.add(tags[i]);
223
				if (!getAllKnownTagsForParents(entry, true).contains(tags[i])) {
224
					removeTagFromChildrenChacheEntries(entry, tags[i], false);
225
					entry.tags.add(tags[i]);
226
				}
222
			}
227
			}
223
		}
228
		}
224
	}
229
	}
Lines 264-283 Link Here
264
	}
269
	}
265
270
266
	private void removeVersionAndBranchTags(String remotePath, CVSTag[] tags) {
271
	private void removeVersionAndBranchTags(String remotePath, CVSTag[] tags) {
267
		// Get the name to cache the version tags with
272
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
268
		String name = getCachePathFor(remotePath);
273
		// remove tags from this path and its children
269
		
274
		if (entry != null) {
270
		// Make sure there is a table for the ancestor that holds the tags
275
			removeTagsFromChildrenChacheEntries(entry, tags, true);
271
		TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(name);
276
		}
272
		if (entry == null) {
277
278
		// remove tags from all parents of this path
279
		entry = getKnownParentTagCacheEntryFor(remotePath);
280
		for (int i = 0; i < tags.length; i++) {
281
			TagCacheEntry currentEntry = entry;
282
			while (currentEntry != null) {
283
				if (currentEntry.tags.contains(tags[i])) {
284
					currentEntry.tags.remove(tags[i]);
285
					currentEntry.accessed();
286
					break;
287
				} else {
288
					currentEntry = currentEntry.parent;
289
				}
290
			}
291
		}
292
		cleanEmptyParents(entry);
293
	}
294
295
	private void cleanEmptyParents(TagCacheEntry entry) {
296
		if (entry.parent == null) {
297
			// we don't remove the root cache entry
273
			return;
298
			return;
274
		}
299
		}
275
		
300
		if (entry.tags.isEmpty() && entry.children.isEmpty()) {
276
		// Store the tag with the appropriate ancestor
301
			entry.parent.children.remove(new Path(entry.path).lastSegment());
277
		for (int i = 0; i < tags.length; i++) {
302
			entry.parent.accessed();
278
			entry.tags.remove(tags[i]);
279
		}
303
		}
280
		entry.accessed();
304
		cleanEmptyParents(entry.parent);
281
	}
305
	}
282
306
283
	/**
307
	/**
Lines 334-367 Link Here
334
	/**
358
	/**
335
	 * Fetches tags from auto-refresh files.
359
	 * Fetches tags from auto-refresh files.
336
	 */
360
	 */
337
	public CVSTag[] refreshDefinedTags(ICVSFolder folder, boolean recurse, IProgressMonitor monitor) throws TeamException {
361
	public CVSTag[] refreshDefinedTags(ICVSFolder folder, boolean recurse,
362
			IProgressMonitor monitor) throws TeamException {
338
		monitor = Policy.monitorFor(monitor);
363
		monitor = Policy.monitorFor(monitor);
339
	    monitor.beginTask(null, 100);
364
		monitor.beginTask(null, recurse ? 210 : 100);
340
	    CVSTag[] tags = null;
365
		try {
341
	    if (!recurse && !folder.getFolderSyncInfo().isVirtualDirectory()) {
366
			CVSTag[] tags = null;
342
	        // Only try the auto-refresh file(s) if we are not recursing into sub-folders
367
			if (!folder.getFolderSyncInfo().isVirtualDirectory()) {
343
	        tags = fetchTagsUsingAutoRefreshFiles(folder, Policy.subMonitorFor(monitor, 50));
368
				// Only try the auto-refresh file(s) if we are not recursing
344
	    }
369
				// into sub-folders
345
        if (tags == null || tags.length == 0) {
370
				tags = fetchTagsUsingAutoRefreshFiles(folder,
346
            // There we're no tags found on the auto-refresh files or we we're aksed to go deep
371
						Policy.subMonitorFor(monitor, 50));
347
            // Try using the log command
372
			}
348
            tags = fetchTagsUsingLog(folder, recurse, Policy.subMonitorFor(monitor, 50));
373
			if (tags == null || tags.length == 0) {
349
        }
374
				// There we're no tags found on the auto-refresh files or we
350
		if (tags != null && tags.length > 0) {
375
				// we're asked to go deep
351
		    String remotePath = getRemotePathFor(folder);
376
				// Try using the log command
352
			addTags(remotePath, tags);
377
				tags = fetchTagsUsingLog(folder,
378
						Policy.subMonitorFor(monitor, 50));
379
			}
380
			if (tags != null && tags.length > 0) {
381
				String remotePath = getRemotePathFor(folder);
382
				addTags(remotePath, tags);
383
				return tags;
384
			}
385
			if (recurse) {
386
				folder.fetchChildren(Policy.subMonitorFor(monitor, 10));
387
				ICVSResource[] children = folder
388
						.members(ICVSFolder.FOLDER_MEMBERS);
389
				for (int i = 0; i < children.length; i++) {
390
					refreshDefinedTags(
391
							(ICVSFolder) children[i],
392
							recurse,
393
							Policy.subMonitorFor(monitor, 100 / children.length));
394
				}
395
			}
396
			return tags;
397
		} finally {
398
			monitor.done();
353
		}
399
		}
354
		monitor.done();
355
		return tags;
356
	}
400
	}
357
	
401
	
358
    private CVSTag[] fetchTagsUsingLog(ICVSFolder folder, final boolean recurse, IProgressMonitor monitor) throws CVSException {
402
    private CVSTag[] fetchTagsUsingLog(ICVSFolder folder, IProgressMonitor monitor) throws CVSException {
359
        LogEntryCache logEntries = new LogEntryCache();
403
        LogEntryCache logEntries = new LogEntryCache();
360
        RemoteLogOperation operation = new RemoteLogOperation(null, new ICVSRemoteResource[] { asRemoteResource(folder) }, null, null, logEntries) {
404
        RemoteLogOperation operation = new RemoteLogOperation(null, new ICVSRemoteResource[] { asRemoteResource(folder) }, null, null, logEntries) {
361
            protected Command.LocalOption[] getLocalOptions(CVSTag tag1,CVSTag tag2) {
405
            protected Command.LocalOption[] getLocalOptions(CVSTag tag1,CVSTag tag2) {
362
                Command.LocalOption[] options = new Command.LocalOption[] {};
406
                Command.LocalOption[] options = new Command.LocalOption[] {};
363
                if (recurse) 
364
                    return options;
365
                Command.LocalOption[] newOptions = new Command.LocalOption[options.length + 1];
407
                Command.LocalOption[] newOptions = new Command.LocalOption[options.length + 1];
366
                System.arraycopy(options, 0, newOptions, 0, options.length);
408
                System.arraycopy(options, 0, newOptions, 0, options.length);
367
                newOptions[options.length] = Command.DO_NOT_RECURSE;
409
                newOptions[options.length] = Command.DO_NOT_RECURSE;
Lines 444-465 Link Here
444
		return (CVSTag[])tagSet.toArray(new CVSTag[0]);
486
		return (CVSTag[])tagSet.toArray(new CVSTag[0]);
445
	}
487
	}
446
	
488
	
447
	/**
489
	/*
448
	 * Return the cache key (path) for the given folder path. For root projects
490
	 * Return the cache key (path) for the given folder path.
449
	 * it returns the folder the project is mapped to as the tag source. For
491
	 * This has been changed to cache the tags directly 
450
	 * non-root projects it returns only the first segment of the path because
492
	 * with the folder to better support non-root projects.
451
	 * for the time being tag lists are kept for the remote ancestors of the
493
	 * However, resources in the local workspace use the folder
452
	 * resource that is a direct child of the remote root.
494
	 * the project is mapped to as the tag source (see TagSource)
453
	 *
454
	 * @see TagSource
455
	 * @see #addTags(String, CVSTag[])
456
	 *
457
	 * @param remotePath
458
	 *            the remote folder path
459
	 * @return the cache key (path) for the given folder path
460
	 */
495
	 */
461
	private String getCachePathFor(String remotePath) {
496
	private String getCachePathFor(String remotePath) {
462
		return new Path(null, remotePath).segment(0);
497
		return remotePath;
498
	}
499
500
	private TagCacheEntry getTagCacheEntryFor(String remotePath, boolean create) {
501
		String path = getCachePathFor(remotePath);
502
		String[] segments = new Path(null, path).segments();
503
		TagCacheEntry currentTagCacheEntry = rootTagCacheEntry;
504
		for (int i = 0; i < segments.length; i++) {
505
			String segment = segments[i];
506
			if (currentTagCacheEntry.children.containsKey(segment)) {
507
				currentTagCacheEntry = (TagCacheEntry) currentTagCacheEntry.children
508
						.get(segment);
509
				continue;
510
			}
511
			if (!create) {
512
				return null;
513
			}
514
			TagCacheEntry newTagCacheEntry = new TagCacheEntry(new Path(null,
515
					path).removeLastSegments(segments.length - (i + 1))
516
					.toString(), currentTagCacheEntry);
517
			currentTagCacheEntry.children.put(segment, newTagCacheEntry);
518
			currentTagCacheEntry = newTagCacheEntry;
519
		}
520
		return currentTagCacheEntry;
521
	}
522
523
	private TagCacheEntry getKnownParentTagCacheEntryFor(String remotePath) {
524
		String path = getCachePathFor(remotePath);
525
		String[] segments = new Path(null, path).segments();
526
		TagCacheEntry currentTagCacheEntry = rootTagCacheEntry;
527
		for (int i = 0; i < segments.length; i++) {
528
			String segment = segments[i];
529
			if (currentTagCacheEntry.children.containsKey(segment)) {
530
				currentTagCacheEntry = (TagCacheEntry) currentTagCacheEntry.children
531
						.get(segment);
532
			} else {
533
				break; // we reached the last existing parent
534
			}
535
		}
536
		return currentTagCacheEntry;
537
	}
538
539
	private void removeTagsFromChildrenChacheEntries(TagCacheEntry entry,
540
			CVSTag[] tags, boolean includeThisEntry) {
541
		for (int i = 0; i < tags.length; i++) {
542
			removeTagFromChildrenChacheEntries(entry, tags[i], includeThisEntry);
543
		}
544
	}
545
546
	private void removeTagFromChildrenChacheEntries(TagCacheEntry entry,
547
			CVSTag tag, boolean includeThisEntry) {
548
		Iterator childrenIterator = entry.children.values().iterator();
549
		while (childrenIterator.hasNext()) {
550
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
551
			removeTagFromChildrenChacheEntries(child, tag, true);
552
		}
553
		if (includeThisEntry) {
554
			entry.tags.remove(tag);
555
			entry.accessed();
556
			if (entry.tags.size() == 0 && entry.children.size() == 0
557
					&& entry.parent != null) {
558
				// remove this entry when the last tag was removed
559
				// keep the entry if there are any children that have tags
560
				Map newParentChildren = new HashMap();
561
				newParentChildren.putAll(entry.parent.children);
562
				newParentChildren.remove(new Path(entry.path).lastSegment());
563
				entry.parent.children = newParentChildren;
564
			}
565
		}
463
	}
566
	}
464
	
567
	
465
	/**
568
	/**
Lines 504-510 Link Here
504
				attributes.put(RepositoriesViewContentHandler.TYPE_ATTRIBUTE, RepositoriesViewContentHandler.DEFINED_MODULE_TYPE);
607
				attributes.put(RepositoriesViewContentHandler.TYPE_ATTRIBUTE, RepositoriesViewContentHandler.DEFINED_MODULE_TYPE);
505
			}
608
			}
506
			attributes.put(RepositoriesViewContentHandler.PATH_ATTRIBUTE, name);
609
			attributes.put(RepositoriesViewContentHandler.PATH_ATTRIBUTE, name);
507
			TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(path);
610
			TagCacheEntry entry = (TagCacheEntry) getTagCacheEntryFor(path,
611
					false);
508
			boolean writeOutTags = entry != null && !entry.isExpired();
612
			boolean writeOutTags = entry != null && !entry.isExpired();
509
			if (writeOutTags)
613
			if (writeOutTags)
510
			    attributes.put(RepositoriesViewContentHandler.LAST_ACCESS_TIME_ATTRIBUTE, Long.toString(entry.lastAccessTime));
614
			    attributes.put(RepositoriesViewContentHandler.LAST_ACCESS_TIME_ATTRIBUTE, Long.toString(entry.lastAccessTime));
Lines 538-571 Link Here
538
		writer.startAndEndTag(s, attributes, true);
642
		writer.startAndEndTag(s, attributes, true);
539
	}
643
	}
540
644
645
	private Set getAllKnownTagsForParents(TagCacheEntry entry,
646
			boolean includeThisEntry) {
647
		Set tags = new HashSet();
648
		if (entry.parent != null) {
649
			tags.addAll(getAllKnownTagsForParents(entry.parent, true));
650
		}
651
		if (includeThisEntry) {
652
			tags.addAll(entry.tags);
653
		}
654
		return tags;
655
	}
656
657
	private Set getAllKnownTagsForChildren(TagCacheEntry entry,
658
			boolean includeThisEntry) {
659
		Set tags = new HashSet();
660
		Iterator childrenIterator = entry.children.values().iterator();
661
		while (childrenIterator.hasNext()) {
662
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
663
			tags.addAll(getAllKnownTagsForChildren(child, true));
664
		}
665
		if (includeThisEntry) {
666
			tags.addAll(entry.tags);
667
		}
668
		return tags;
669
	}
670
541
	/**
671
	/**
542
	 * Method getKnownTags.
672
	 * Method getKnownTags.
543
	 * @param remotePath
673
	 * @param remotePath
544
	 * @return CVSTag[]
674
	 * @return CVSTag[]
545
	 */
675
	 */
546
	public CVSTag[] getAllKnownTags(String remotePath) {
676
	public CVSTag[] getAllKnownTags(String remotePath) {
547
	    TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(getCachePathFor(remotePath));
677
		Set tags = getAllKnownTagsForParents(
548
		if(entry != null){
678
				getKnownParentTagCacheEntryFor(remotePath), true);
549
		    entry.accessed();
679
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
550
			CVSTag [] tags1 = (CVSTag[]) entry.tags.toArray(new CVSTag[entry.tags.size()]);
680
		if (entry != null) {
551
			CVSTag[] tags2 = getDateTags();
681
			tags.addAll(getAllKnownTagsForChildren(entry, true));
552
			int len = tags1.length + tags2.length;
553
			CVSTag[] tags = new CVSTag[len];
554
			for(int i = 0; i < len; i++){
555
				if(i < tags1.length){
556
					tags[i] = tags1[i];
557
				}else{
558
					tags[i] = tags2[i-tags1.length];
559
				}
560
			}
561
			return tags;
562
		}
682
		}
563
		return getDateTags();
683
		return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
564
	}
684
	}
565
685
566
	public String[] getKnownRemotePaths() {
686
	public CVSTag[] getAllKnownTags() {
687
		Set tags = getAllKnownTagsForChildren(rootTagCacheEntry, true);
688
		return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
689
	}
690
691
	public String[] getRemoteChildrenForTag(String remotePath, CVSTag tag) {
692
		TagCacheEntry entry;
693
		if (remotePath == null) {
694
			entry = rootTagCacheEntry;
695
		} else {
696
			entry = getTagCacheEntryFor(remotePath, false);
697
		}
698
		if (entry == null) {
699
			return new String[0];
700
		}
701
567
		Set paths = new HashSet();
702
		Set paths = new HashSet();
568
		paths.addAll(versionAndBranchTags.keySet());
703
		Iterator childrenIterator = entry.children.values().iterator();
704
		while (childrenIterator.hasNext()) {
705
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
706
			if (getAllKnownTagsForChildren(child, true).contains(tag)) {
707
				paths.add(child.path);
708
			}
709
		}
710
		return (String[]) paths.toArray(new String[paths.size()]);
711
	}
712
	
713
	private Set getKnownRemotePaths(TagCacheEntry root) {
714
		Set paths = new HashSet();
715
		Iterator childrenIterator = root.children.values().iterator();
716
		while(childrenIterator.hasNext()){
717
			paths.addAll(getKnownRemotePaths((TagCacheEntry) childrenIterator.next()));
718
		}
719
		paths.add(root.path);
720
		return paths;
721
		
722
	}
723
	public String[] getKnownRemotePaths() {
724
		Set paths =  getKnownRemotePaths(rootTagCacheEntry);
569
		paths.addAll(autoRefreshFiles.keySet());
725
		paths.addAll(autoRefreshFiles.keySet());
570
		return (String[]) paths.toArray(new String[paths.size()]);
726
		return (String[]) paths.toArray(new String[paths.size()]);
571
	}
727
	}
Lines 620-626 Link Here
620
     * as it was read from the persistent store.
776
     * as it was read from the persistent store.
621
     */
777
     */
622
    /* package */ void setLastAccessedTime(String remotePath, long lastAccessTime) {
778
    /* package */ void setLastAccessedTime(String remotePath, long lastAccessTime) {
623
	    TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(getCachePathFor(remotePath));
779
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
624
		if(entry != null){
780
		if(entry != null){
625
		    entry.lastAccessTime = lastAccessTime;
781
		    entry.lastAccessTime = lastAccessTime;
626
		}
782
		}
(-)a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/RepositoriesViewTests.java (-14 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
2
 * Copyright (c) 2011, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 82-110 Link Here
82
82
83
		// create project
83
		// create project
84
		IProject project = getUniqueTestProject("TestBranchSubmoduleChildrenProject");
84
		IProject project = getUniqueTestProject("TestBranchSubmoduleChildrenProject");
85
		buildResources(project, new String[] { "file1.txt" }, true);
86
		// share project under module
85
		// share project under module
87
		shareProject(getRepository(), project,
86
		shareProject(getRepository(), project,
88
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
87
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
89
		assertValidCheckout(project);
88
		assertValidCheckout(project);
90
89
91
		// make some changes
90
		// add some files
92
		addResources(project, new String[] { "folder1/c.txt" }, false);
91
		addResources(project, new String[] { "file1.txt" }, true);
93
92
94
		// make branch
93
		// make branch
95
		CVSTag version = new CVSTag(versionName, CVSTag.VERSION);
94
		CVSTag version = new CVSTag(versionName, CVSTag.VERSION);
96
		CVSTag branch = new CVSTag(branchName, CVSTag.BRANCH);
95
		CVSTag branch = new CVSTag(branchName, CVSTag.BRANCH);
97
96
98
		makeBranch(new IResource[] { project }, version, branch, true);
97
		makeBranch(new IResource[] { project }, version, branch, true);
99
		commitProject(project);
100
101
		// refresh branches
102
		CVSUIPlugin
103
				.getPlugin()
104
				.getRepositoryManager()
105
				.refreshDefinedTags(
106
						getRepository().getRemoteFolder(moduleName, null),
107
						true, true, DEFAULT_MONITOR);
108
98
109
		// check if module is the only branch child
99
		// check if module is the only branch child
110
		RemoteContentProvider rcp = new RemoteContentProvider();
100
		RemoteContentProvider rcp = new RemoteContentProvider();
Lines 118-123 Link Here
118
		Object[] modules = rcp.getChildren(branches[0]);
108
		Object[] modules = rcp.getChildren(branches[0]);
119
		assertEquals(1, modules.length);
109
		assertEquals(1, modules.length);
120
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
110
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
111
112
		// refresh branches
113
		CVSUIPlugin
114
				.getPlugin()
115
				.getRepositoryManager()
116
				.refreshDefinedTags(
117
						getRepository().getRemoteFolder(moduleName, null),
118
						true, true, DEFAULT_MONITOR);
119
120
		// check if after refresh module is still the only branch child
121
		branches = rcp.getChildren(categories[1]);
122
		assertEquals(1, branches.length);
123
		assertEquals(branchName, ((CVSTagElement) (branches[0])).getTag()
124
				.getName());
125
		modules = rcp.getChildren(branches[0]);
126
		assertEquals(1, modules.length);
127
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
121
	}
128
	}
122
129
123
	public void testTagSubmoduleChildren() throws TeamException, CoreException {
130
	public void testTagSubmoduleChildren() throws TeamException, CoreException {
Lines 128-144 Link Here
128
135
129
		// create project
136
		// create project
130
		IProject project = getUniqueTestProject("TestTagSubmoduleChildrenProject");
137
		IProject project = getUniqueTestProject("TestTagSubmoduleChildrenProject");
131
		buildResources(project, new String[] { "file1.txt" }, true);
132
		// share project under module
138
		// share project under module
133
		shareProject(getRepository(), project,
139
		shareProject(getRepository(), project,
134
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
140
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
135
		assertValidCheckout(project);
141
		assertValidCheckout(project);
136
142
143
		// add some files
144
		addResources(project, new String[] { "file1.txt" }, true);
145
137
		// tag project
146
		// tag project
138
		CVSTag tag = new CVSTag(versionName, CVSTag.VERSION);
147
		CVSTag tag = new CVSTag(versionName, CVSTag.VERSION);
139
148
140
		tagProject(project, tag, true);
149
		tagProject(project, tag, true);
141
150
151
		// refresh branches
152
		CVSUIPlugin
153
				.getPlugin()
154
				.getRepositoryManager()
155
				.refreshDefinedTags(
156
						getRepository().getRemoteFolder(moduleName, null),
157
						true, true, DEFAULT_MONITOR);
158
142
		RemoteContentProvider rcp = new RemoteContentProvider();
159
		RemoteContentProvider rcp = new RemoteContentProvider();
143
		Object[] categories = rcp.getChildren(getRepositoryRoot());
160
		Object[] categories = rcp.getChildren(getRepositoryRoot());
144
		assertEquals(4, categories.length);
161
		assertEquals(4, categories.length);

Return to bug 366016