@@ -73,6 +73,8 @@ public final class HistoryGuru {
73
73
74
74
private final int scanningDepth ;
75
75
76
+ private String ignoreRepositoryName = ".opengrok_skip_history" ;
77
+
76
78
/**
77
79
* Creates a new instance of HistoryGuru, and try to set the default source
78
80
* control system.
@@ -341,69 +343,95 @@ private void addRepositories(File[] files, Collection<RepositoryInfo> repos,
341
343
*/
342
344
private void addRepositories (File [] files , Collection <RepositoryInfo > repos ,
343
345
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.
344
349
for (File file : files ) {
345
- Repository repository = null ;
346
- if (file .getName ().equals (".opengrok_skip_history" )) {
350
+ if (file .getName ().equals (ignoreRepositoryName )) {
347
351
LOGGER .log (Level .INFO ,
348
352
"Skipping history cache creation for {0} and its subdirectories" ,
349
353
file .getParentFile ().getAbsolutePath ());
350
354
return ;
351
355
}
352
356
}
353
357
for (File file : files ) {
354
- Repository repository = null ;
358
+ Boolean ignoreRepository = false ;
355
359
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 ();
375
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 ());
376
380
} else {
381
+ Repository repository = null ;
377
382
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 )) {
389
394
File subFiles [] = file .listFiles ();
390
395
if (subFiles == null ) {
391
396
LOGGER .log (Level .WARNING ,
392
397
"Failed to get sub directories for ''{0}'', check access permissions." ,
393
398
file .getAbsolutePath ());
394
399
} 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 );
399
401
}
400
402
}
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 ));
401
413
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
+ }
407
435
}
408
436
}
409
437
}
0 commit comments