Skip to content

Commit 2247858

Browse files
author
Vladimir Kotal
committed
get repositories for a project automatically
fixes #2334
1 parent 708cf62 commit 2247858

File tree

1 file changed

+25
-17
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/index

1 file changed

+25
-17
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public final class Indexer {
9898
private static String configFilename = null;
9999
private static int status = 0;
100100

101-
private static final ArrayList<String> repositories = new ArrayList<>();
101+
private static final Set<String> repositories = new HashSet<>();
102102
private static final HashSet<String> allowedSymlinks = new HashSet<>();
103103
private static final Set<String> defaultProjects = new TreeSet<>();
104104
private static final ArrayList<String> zapCache = new ArrayList<>();
@@ -141,7 +141,9 @@ public static void main(String argv[]) {
141141
}
142142
System.exit(status);
143143
}
144-
144+
145+
checkConfiguration();
146+
145147
if (awaitProfiler) {
146148
pauseToAwaitProfiler();
147149
}
@@ -256,8 +258,11 @@ public static void main(String argv[]) {
256258
path = path.substring(srcPath.length());
257259
if (env.hasProjects()) {
258260
// The paths need to correspond to a project.
259-
if (Project.getProject(path) != null) {
261+
Project project;
262+
if ((project = Project.getProject(path)) != null) {
260263
subFiles.add(path);
264+
repositories.addAll(env.getProjectRepositoriesMap().get(project).
265+
stream().map(x -> x.getDirectoryNameRelative()).collect(Collectors.toSet()));
261266
} else {
262267
System.err.println("The path " + path
263268
+ " does not correspond to a project");
@@ -292,7 +297,7 @@ public static void main(String argv[]) {
292297
// Get history first.
293298
getInstance().prepareIndexer(env, searchRepositories, addProjects,
294299
defaultProjects,
295-
listFiles, createDict, subFiles, repositories,
300+
listFiles, createDict, subFiles, new ArrayList(repositories),
296301
zapCache, listRepos);
297302
if (listRepos || !zapCache.isEmpty()) {
298303
return;
@@ -499,19 +504,9 @@ public static String[] parseOptions(String[] argv) throws ParseException {
499504
cfg.setTagsEnabled(true);
500505
});
501506

502-
parser.on("-H", "--history", "=[/path/to/repository]",
503-
"Get history for specific repositories (specified as",
504-
"absolute path from source root), or ALL repositories",
505-
"when none specified.").
506-
Do( repo -> {
507-
String repository = (String) repo;
508-
if (repository.equals("")) {
509-
cfg.setHistoryEnabled(true); // all repositories
510-
} else {
511-
repositories.add((String)repository); // specific repository
512-
}
513-
}
514-
);
507+
parser.on("-H", "--history", "Enable history.").Do( v -> {
508+
cfg.setHistoryEnabled(true);
509+
});
515510

516511
parser.on("-I", "--include", "=pattern",
517512
"Only files matching this pattern will be examined.",
@@ -645,6 +640,12 @@ public static String[] parseOptions(String[] argv) throws ParseException {
645640
LoggerUtil.setBaseConsoleLogLevel(Level.WARNING);
646641
});
647642

643+
parser.on("--repository", "=repository",
644+
"Generate history for specific repository specified as relative path to source root. ",
645+
"Can be used multiple times. Assumes history is on.").Do( repo -> {
646+
repositories.add((String)repo);
647+
});
648+
648649
parser.on("-R /path/to/configuration",
649650
"Read configuration from the specified file.").Do( v-> {
650651
// Already handled above. This populates usage.
@@ -788,6 +789,13 @@ public static String[] parseOptions(String[] argv) throws ParseException {
788789
return argv;
789790
}
790791

792+
private static void checkConfiguration() {
793+
if (repositories.size() > 0 && !cfg.isHistoryEnabled()) {
794+
System.out.println("Repositories were specified however history is off");
795+
System.exit(1);
796+
}
797+
}
798+
791799
private static void die(String message) {
792800
System.err.println("ERROR: " + message);
793801
System.exit(1);

0 commit comments

Comments
 (0)