Skip to content

Commit de8268f

Browse files
shaehnVladimir Kotal
authored andcommitted
Have .opengrok_skip_history seen by AccuRev
Changed HistoryGuru::addRepository so that it will recognize .opengrok_skip_history files in folders prior to scanning the folder/directory.
1 parent add3d95 commit de8268f

File tree

1 file changed

+70
-42
lines changed

1 file changed

+70
-42
lines changed

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

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public final class HistoryGuru {
7373

7474
private final int scanningDepth;
7575

76+
private String ignoreRepositoryName = ".opengrok_skip_history";
77+
7678
/**
7779
* Creates a new instance of HistoryGuru, and try to set the default source
7880
* control system.
@@ -341,69 +343,95 @@ private void addRepositories(File[] files, Collection<RepositoryInfo> repos,
341343
*/
342344
private void addRepositories(File[] files, Collection<RepositoryInfo> repos,
343345
IgnoredNames ignoredNames, boolean recursiveSearch, int depth) {
346+
347+
// This check for ignoring a repository only works for embedded
348+
// source code control directories used by SCCS and the like.
344349
for (File file : files) {
345-
Repository repository = null;
346-
if (file.getName().equals(".opengrok_skip_history")) {
350+
if (file.getName().equals(ignoreRepositoryName)) {
347351
LOGGER.log(Level.INFO,
348352
"Skipping history cache creation for {0} and its subdirectories",
349353
file.getParentFile().getAbsolutePath());
350354
return;
351355
}
352356
}
353357
for (File file : files) {
354-
Repository repository = null;
358+
Boolean ignoreRepository = false;
355359
try {
356-
repository = RepositoryFactory.getRepository(file);
357-
} catch (InstantiationException ie) {
358-
LOGGER.log(Level.WARNING, "Could not create repository for '"
359-
+ file + "', could not instantiate the repository.", ie);
360-
} catch (IllegalAccessException iae) {
361-
LOGGER.log(Level.WARNING, "Could not create repository for '"
362-
+ file + "', missing access rights.", iae);
363-
}
364-
if (repository == null) {
365-
// Not a repository, search its sub-dirs
366-
if (file.isDirectory() && !ignoredNames.ignore(file)) {
367-
File subFiles[] = file.listFiles();
368-
if (subFiles == null) {
369-
LOGGER.log(Level.WARNING,
370-
"Failed to get sub directories for ''{0}'', check access permissions.",
371-
file.getAbsolutePath());
372-
} else if (depth <= scanningDepth) {
373-
addRepositories(subFiles, repos, ignoredNames, depth + 1);
374-
}
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();
375369
}
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());
376380
} else {
381+
Repository repository = null;
377382
try {
378-
String path = file.getCanonicalPath();
379-
repository.setDirectoryName(path);
380-
if (RuntimeEnvironment.getInstance().isVerbose()) {
381-
LOGGER.log(Level.CONFIG, "Adding <{0}> repository: <{1}>",
382-
new Object[]{repository.getClass().getName(), path});
383-
}
384-
385-
repos.add(new RepositoryInfo(repository));
386-
387-
// @TODO: Search only for one type of repository - the one found here
388-
if (recursiveSearch && repository.supportsSubRepositories()) {
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)) {
389394
File subFiles[] = file.listFiles();
390395
if (subFiles == null) {
391396
LOGGER.log(Level.WARNING,
392397
"Failed to get sub directories for ''{0}'', check access permissions.",
393398
file.getAbsolutePath());
394399
} else if (depth <= scanningDepth) {
395-
// Search only one level down - if not: too much
396-
// stat'ing for huge Mercurial repositories
397-
addRepositories(subFiles, repos, ignoredNames,
398-
false, depth + 1);
400+
addRepositories(subFiles, repos, ignoredNames, depth + 1);
399401
}
400402
}
403+
} else {
404+
try {
405+
String path = file.getCanonicalPath();
406+
repository.setDirectoryName(path);
407+
if (RuntimeEnvironment.getInstance().isVerbose()) {
408+
LOGGER.log(Level.CONFIG, "Adding <{0}> repository: <{1}>",
409+
new Object[]{repository.getClass().getName(), path});
410+
}
411+
412+
repos.add(new RepositoryInfo(repository));
401413

402-
} catch (IOException exp) {
403-
LOGGER.log(Level.WARNING,
404-
"Failed to get canonical path for {0}: {1}",
405-
new Object[]{file.getAbsolutePath(), exp.getMessage()});
406-
LOGGER.log(Level.WARNING, "Repository will be ignored...", exp);
414+
// @TODO: Search only for one type of repository - the one found here
415+
if (recursiveSearch && repository.supportsSubRepositories()) {
416+
File subFiles[] = file.listFiles();
417+
if (subFiles == null) {
418+
LOGGER.log(Level.WARNING,
419+
"Failed to get sub directories for ''{0}'', check access permissions.",
420+
file.getAbsolutePath());
421+
} else if (depth <= scanningDepth) {
422+
// Search only one level down - if not: too much
423+
// stat'ing for huge Mercurial repositories
424+
addRepositories(subFiles, repos, ignoredNames,
425+
false, depth + 1);
426+
}
427+
}
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);
434+
}
407435
}
408436
}
409437
}

0 commit comments

Comments
 (0)