|
19 | 19 |
|
20 | 20 | /*
|
21 | 21 | * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
|
| 22 | + * Portions Copyright (c) 2017, Chris Fraire <[email protected]>. |
22 | 23 | */
|
23 | 24 | package org.opensolaris.opengrok.history;
|
24 | 25 |
|
|
27 | 28 | import java.io.InputStream;
|
28 | 29 | import java.lang.reflect.InvocationTargetException;
|
29 | 30 | import java.nio.file.Path;
|
| 31 | +import java.nio.file.Paths; |
30 | 32 | import java.util.ArrayList;
|
31 | 33 | import java.util.Collection;
|
32 | 34 | import java.util.Collections;
|
|
39 | 41 | import java.util.concurrent.CountDownLatch;
|
40 | 42 | import java.util.concurrent.ExecutorService;
|
41 | 43 | import java.util.concurrent.Executors;
|
42 |
| -import java.util.concurrent.Semaphore; |
43 | 44 | import java.util.concurrent.ThreadFactory;
|
44 | 45 | import java.util.concurrent.TimeUnit;
|
45 | 46 | import java.util.logging.Level;
|
|
49 | 50 | import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
|
50 | 51 | import org.opensolaris.opengrok.index.IgnoredNames;
|
51 | 52 | import org.opensolaris.opengrok.logger.LoggerFactory;
|
| 53 | +import org.opensolaris.opengrok.util.PathUtils; |
52 | 54 | import org.opensolaris.opengrok.util.Statistics;
|
53 | 55 |
|
54 | 56 | /**
|
@@ -76,6 +78,12 @@ public final class HistoryGuru {
|
76 | 78 | */
|
77 | 79 | private Map<String, Repository> repositories = new ConcurrentHashMap<>();
|
78 | 80 |
|
| 81 | + /** |
| 82 | + * set of repository roots (using ConcurrentHashMap but a throwaway value) |
| 83 | + * with parent of {@code DirectoryName} as key |
| 84 | + */ |
| 85 | + private Map<String, String> repositoryRoots = new ConcurrentHashMap<>(); |
| 86 | + |
79 | 87 | private final int scanningDepth;
|
80 | 88 |
|
81 | 89 | /**
|
@@ -415,7 +423,11 @@ private Collection<RepositoryInfo> addRepositories(File[] files,
|
415 | 423 | }
|
416 | 424 |
|
417 | 425 | repoList.add(new RepositoryInfo(repository));
|
418 |
| - repositories.put(repository.getDirectoryName(), repository); |
| 426 | + String repoDirectoryName = repository.getDirectoryName(); |
| 427 | + File repoDirectoryFile = new File(repoDirectoryName); |
| 428 | + String repoDirParent = repoDirectoryFile.getParent(); |
| 429 | + repositoryRoots.put(repoDirParent, ""); |
| 430 | + repositories.put(repoDirectoryName, repository); |
419 | 431 |
|
420 | 432 | // @TODO: Search only for one type of repository - the one found here
|
421 | 433 | if (recursiveSearch && repository.supportsSubRepositories()) {
|
@@ -829,12 +841,27 @@ public void ensureHistoryCacheExists(File file) throws HistoryException {
|
829 | 841 |
|
830 | 842 | protected Repository getRepository(File path) {
|
831 | 843 | File file = path;
|
| 844 | + Set<String> rootKeys = repositoryRoots.keySet(); |
832 | 845 |
|
833 | 846 | while (file != null) {
|
834 |
| - Repository r = repositories.get(file.getAbsolutePath()); |
835 |
| - if (r != null) { |
836 |
| - return r; |
| 847 | + String nextPath = file.getPath(); |
| 848 | + for (String rootKey : rootKeys) { |
| 849 | + String rel; |
| 850 | + try { |
| 851 | + rel = PathUtils.getRelativeToCanonical(nextPath, rootKey); |
| 852 | + } catch (IOException e) { |
| 853 | + LOGGER.log(Level.WARNING, |
| 854 | + "Failed to get relative to canonical for " + nextPath, |
| 855 | + e); |
| 856 | + return null; |
| 857 | + } |
| 858 | + String inRootPath = Paths.get(rootKey, rel).toString(); |
| 859 | + Repository r = repositories.get(inRootPath); |
| 860 | + if (r != null) { |
| 861 | + return r; |
| 862 | + } |
837 | 863 | }
|
| 864 | + |
838 | 865 | file = file.getParentFile();
|
839 | 866 | }
|
840 | 867 |
|
|
0 commit comments