Skip to content

Commit a8c2792

Browse files
shaehnVladimir Kotal
authored andcommitted
Incorporated suggested changes
Removed 1st for-loop which was not doing much of anything. Only directories are considered to be looked at as being repositories, or holders of repository info.
1 parent c9be3c3 commit a8c2792

File tree

1 file changed

+38
-63
lines changed

1 file changed

+38
-63
lines changed

src/org/opensolaris/opengrok/history/HistoryGuru.java

Lines changed: 38 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public final class HistoryGuru {
7272
private Map<String, Repository> repositories = new ConcurrentHashMap<>();
7373

7474
private final int scanningDepth;
75-
76-
private String ignoreRepositoryName = ".opengrok_skip_history";
7775

7876
/**
7977
* Creates a new instance of HistoryGuru, and try to set the default source
@@ -344,65 +342,43 @@ private void addRepositories(File[] files, Collection<RepositoryInfo> repos,
344342
private void addRepositories(File[] files, Collection<RepositoryInfo> repos,
345343
IgnoredNames ignoredNames, boolean recursiveSearch, int depth) {
346344

347-
// This check for ignoring a repository only works for embedded
348-
// source code control directories used by SCCS and the like.
349345
for (File file : files) {
350-
if (file.getName().equals(ignoreRepositoryName)) {
351-
LOGGER.log(Level.INFO,
352-
"Skipping history cache creation for {0} and its subdirectories",
353-
file.getParentFile().getAbsolutePath());
354-
return;
355-
}
356-
}
357-
for (File file : files) {
358-
Boolean ignoreRepository = false;
359-
try {
360-
// This check for ignoring a repository is for the
361-
// kind of repository, such as AccuRev, where the
362-
// entire project folder layout (workspace) is
363-
// considered as the repository. Here we need to
364-
// look inside the folder for the magic file.
365-
if( file.isDirectory() ) {
366-
String path = file.getCanonicalPath();
367-
File skipRepository = new File(path, ignoreRepositoryName);
368-
ignoreRepository = skipRepository.exists();
369-
}
370-
} catch( IOException exp ) {
371-
LOGGER.log(Level.WARNING,
372-
"Failed to get canonical path for {0}: {1}",
373-
new Object[]{file.getAbsolutePath(), exp.getMessage()});
374-
}
375-
376-
if( ignoreRepository ) {
377-
LOGGER.log(Level.INFO,
378-
"Skipping history cache creation for {0} and its subdirectories",
379-
file.getAbsolutePath());
380-
} else {
381-
Repository repository = null;
346+
if (file.isDirectory()) {
347+
String path;
382348
try {
383-
repository = RepositoryFactory.getRepository(file);
384-
} catch (InstantiationException ie) {
385-
LOGGER.log(Level.WARNING, "Could not create repository for '"
386-
+ file + "', could not instantiate the repository.", ie);
387-
} catch (IllegalAccessException iae) {
388-
LOGGER.log(Level.WARNING, "Could not create repository for '"
389-
+ file + "', missing access rights.", iae);
390-
}
391-
if (repository == null) {
392-
// Not a repository, search its sub-dirs
393-
if (file.isDirectory() && !ignoredNames.ignore(file)) {
394-
File subFiles[] = file.listFiles();
395-
if (subFiles == null) {
396-
LOGGER.log(Level.WARNING,
397-
"Failed to get sub directories for ''{0}'', check access permissions.",
398-
file.getAbsolutePath());
399-
} else if (depth <= scanningDepth) {
400-
addRepositories(subFiles, repos, ignoredNames, depth + 1);
401-
}
349+
path = file.getCanonicalPath();
350+
File skipRepository = new File(path, ".opengrok_skip_history");
351+
// Should potential repository be ignored?
352+
if (skipRepository.exists()) {
353+
LOGGER.log(Level.INFO,
354+
"Skipping history cache creation for {0} and its subdirectories",
355+
file.getAbsolutePath());
356+
continue;
402357
}
403-
} else {
358+
359+
Repository repository = null;
404360
try {
405-
String path = file.getCanonicalPath();
361+
repository = RepositoryFactory.getRepository(file);
362+
} catch (InstantiationException ie) {
363+
LOGGER.log(Level.WARNING, "Could not create repository for '"
364+
+ file + "', could not instantiate the repository.", ie);
365+
} catch (IllegalAccessException iae) {
366+
LOGGER.log(Level.WARNING, "Could not create repository for '"
367+
+ file + "', missing access rights.", iae);
368+
}
369+
if (repository == null) {
370+
// Not a repository, search its sub-dirs
371+
if (!ignoredNames.ignore(file)) {
372+
File subFiles[] = file.listFiles();
373+
if (subFiles == null) {
374+
LOGGER.log(Level.WARNING,
375+
"Failed to get sub directories for ''{0}'', check access permissions.",
376+
file.getAbsolutePath());
377+
} else if (depth <= scanningDepth) {
378+
addRepositories(subFiles, repos, ignoredNames, depth + 1);
379+
}
380+
}
381+
} else {
406382
repository.setDirectoryName(path);
407383
if (RuntimeEnvironment.getInstance().isVerbose()) {
408384
LOGGER.log(Level.CONFIG, "Adding <{0}> repository: <{1}>",
@@ -425,13 +401,12 @@ private void addRepositories(File[] files, Collection<RepositoryInfo> repos,
425401
false, depth + 1);
426402
}
427403
}
428-
429-
} catch (IOException exp) {
430-
LOGGER.log(Level.WARNING,
431-
"Failed to get canonical path for {0}: {1}",
432-
new Object[]{file.getAbsolutePath(), exp.getMessage()});
433-
LOGGER.log(Level.WARNING, "Repository will be ignored...", exp);
434404
}
405+
} catch (IOException exp) {
406+
LOGGER.log(Level.WARNING,
407+
"Failed to get canonical path for {0}: {1}",
408+
new Object[]{file.getAbsolutePath(), exp.getMessage()});
409+
LOGGER.log(Level.WARNING, "Repository will be ignored...", exp);
435410
}
436411
}
437412
}

0 commit comments

Comments
 (0)