Skip to content

Commit 8d26e0b

Browse files
committed
filter repositories based on list of directories before invalidating when doing partial reindex
fixes #880
1 parent ad4ef47 commit 8d26e0b

File tree

3 files changed

+74
-24
lines changed

3 files changed

+74
-24
lines changed

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,15 @@ protected void writeConfiguration() throws IOException {
938938
public void setConfiguration(Configuration configuration) {
939939
this.configuration = configuration;
940940
register();
941-
HistoryGuru.getInstance().invalidateRepositories(configuration.getRepositories());
941+
HistoryGuru.getInstance().invalidateRepositories(
942+
configuration.getRepositories());
943+
}
944+
945+
public void setConfiguration(Configuration configuration, List<String> subFileList) {
946+
this.configuration = configuration;
947+
register();
948+
HistoryGuru.getInstance().invalidateRepositories(
949+
configuration.getRepositories(), subFileList);
942950
}
943951

944952
public Configuration getConfiguration() {

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.File;
2626
import java.io.IOException;
2727
import java.io.InputStream;
28+
import java.nio.file.Path;
2829
import java.util.ArrayList;
2930
import java.util.Collection;
3031
import java.util.Collections;
@@ -714,7 +715,32 @@ protected Repository getRepository(File path) {
714715
}
715716

716717
/**
717-
* Invalidate the current list of known repositories!
718+
* Invalidate list of known repositories which match the list of directories.
719+
*
720+
* @param repos the new repositories
721+
* @param dirs only process repositories which match the directories
722+
*/
723+
public void invalidateRepositories(Collection<? extends RepositoryInfo> repos, List<String> dirs)
724+
{
725+
if (repos != null && !repos.isEmpty() && dirs != null && !dirs.isEmpty()) {
726+
List<RepositoryInfo> newrepos = new ArrayList<> ();
727+
for (RepositoryInfo i : repos) {
728+
for (String dir : dirs) {
729+
Path dirPath = new File(dir).toPath();
730+
Path iPath = new File(i.getDirectoryName()).toPath();
731+
if (iPath.startsWith(dirPath)) {
732+
newrepos.add(i);
733+
}
734+
}
735+
}
736+
repos = newrepos;
737+
}
738+
739+
invalidateRepositories(repos);
740+
}
741+
742+
/**
743+
* Invalidate list of known repositories.
718744
*
719745
* @param repos The new repositories
720746
*/
@@ -723,8 +749,13 @@ public void invalidateRepositories(Collection<? extends RepositoryInfo> repos)
723749
if (repos == null || repos.isEmpty()) {
724750
repositories.clear();
725751
} else {
726-
Map<String, Repository> nrep =
752+
Map<String, Repository> newrepos =
727753
new HashMap<String, Repository>(repos.size());
754+
Statistics elapsed = new Statistics();
755+
boolean verbose = RuntimeEnvironment.getInstance().isVerbose();
756+
if (verbose) {
757+
log.log(Level.FINE, "invalidating repositories");
758+
}
728759
for (RepositoryInfo i : repos) {
729760
try {
730761
Repository r = RepositoryFactory.getRepository(i);
@@ -733,7 +764,7 @@ public void invalidateRepositories(Collection<? extends RepositoryInfo> repos)
733764
"Failed to instanciate internal repository data for "
734765
+ i.getType() + " in " + i.getDirectoryName());
735766
} else {
736-
nrep.put(r.getDirectoryName(), r);
767+
newrepos.put(r.getDirectoryName(), r);
737768
}
738769
} catch (InstantiationException ex) {
739770
log.log(Level.WARNING, "Could not create " + i.getType()
@@ -745,7 +776,10 @@ public void invalidateRepositories(Collection<? extends RepositoryInfo> repos)
745776
+ "', missing access rights.", iae);
746777
}
747778
}
748-
repositories = nrep;
779+
repositories = newrepos;
780+
if (verbose) {
781+
elapsed.report(log, "done invalidating repositories");
782+
}
749783
}
750784
}
751785
}

src/org/opensolaris/opengrok/index/Indexer.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public static void main(String argv[]) {
114114
Executor.registerErrorHandler();
115115
boolean searchRepositories = false;
116116
ArrayList<String> subFiles = new ArrayList<>();
117+
ArrayList<String> subFilesList = new ArrayList<>();
117118
ArrayList<String> repositories = new ArrayList<>();
118119
HashSet<String> allowedSymlinks = new HashSet<>();
119120
String configFilename = null;
@@ -530,9 +531,20 @@ public static void main(String argv[]) {
530531
allowedSymlinks.addAll(cfg.getAllowedSymlinks());
531532
cfg.setAllowedSymlinks(allowedSymlinks);
532533

534+
// Assemble the unprocessed command line arguments (possibly
535+
// a list of paths). This will be used to perform more fine
536+
// grained checking in invalidateRepositories().
537+
int optind = getopt.getOptind();
538+
int orig_optind = optind;
539+
if (optind != -1) {
540+
while (optind < argv.length) {
541+
subFilesList.add(cfg.getSourceRoot() + argv[optind++]);
542+
}
543+
}
544+
533545
// Set updated configuration in RuntimeEnvironment.
534546
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
535-
env.setConfiguration(cfg);
547+
env.setConfiguration(cfg, subFilesList);
536548

537549
/*
538550
* Add paths to directories under source root. If projects
@@ -542,28 +554,24 @@ public static void main(String argv[]) {
542554
* directory and not per project data root directory).
543555
* For the check we need to have 'env' already set.
544556
*/
545-
int optind = getopt.getOptind();
546-
int orig_optind = optind;
547-
if (optind != -1) {
548-
while (optind < argv.length) {
549-
if (env.hasProjects()) {
550-
// The paths need to correspond to a project.
551-
if (Project.getProject(argv[optind]) != null) {
552-
subFiles.add(argv[optind]);
553-
} else {
554-
System.err.println("The path " + argv[optind] +
555-
" does not correspond to a project");
556-
}
557+
for (String path : subFilesList) {
558+
path = path.substring(env.getSourceRootPath().length());
559+
if (env.hasProjects()) {
560+
// The paths need to correspond to a project.
561+
if (Project.getProject(path) != null) {
562+
subFiles.add(path);
557563
} else {
558-
subFiles.add(argv[optind]);
564+
System.err.println("The path " + path +
565+
" does not correspond to a project");
559566
}
560-
++optind;
567+
} else {
568+
subFiles.add(path);
561569
}
570+
}
562571

563-
if ((orig_optind < argv.length) && subFiles.isEmpty()) {
564-
System.err.println("None of the paths were added, exiting");
565-
System.exit(1);
566-
}
572+
if (!subFilesList.isEmpty() && subFiles.isEmpty()) {
573+
System.err.println("None of the paths were added, exiting");
574+
System.exit(1);
567575
}
568576

569577
// Issue a warning when JDBC is used with renamed file handling.

0 commit comments

Comments
 (0)