Skip to content

Commit 2b89216

Browse files
author
Vladimir Kotal
committed
ignore history should be per project tunable
fixes #1728
1 parent 9b1428c commit 2b89216

File tree

12 files changed

+176
-57
lines changed

12 files changed

+176
-57
lines changed

OpenGrok

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,6 @@ DefaultInstanceConfiguration()
308308

309309
# OPTIONAL: Ignore these patterns as names of files or directories
310310
#OPENGROK_IGNORE_PATTERNS="-i dummy"
311-
# To ignore skipping just the history cache creation for a particular
312-
# directory and all of it's subdirectories, touch an empty
313-
# .opengrok_skip_history file at the root of that directory
314311

315312
# OPTIONAL: Enable Projects
316313
# (Every directory in SRC_ROOT is considered a separate project)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ by OpenGrok.
119119

120120
Note that OpenGrok ignores symbolic links.
121121

122-
If you want to skip indexing the history of a particular directory
123-
(and all of it's subdirectories), you can touch `.opengrok_skip_history` file
124-
at the root of that directory.
122+
If you want to skip indexing the history of a particular directory,
123+
use per project settings as per
124+
https://github.com/oracle/opengrok/wiki/Per-project-configuration
125125
If you want to disable history generation for all repositories globally, then
126126
set `OPENGROK_GENERATE_HISTORY` environment variable to `off` during indexing.
127127

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public class Project implements Comparable<Project>, Nameable, Serializable {
7373
*/
7474
private Boolean handleRenamedFiles = null;
7575

76+
/**
77+
* This flag enables/disables per-project history cache.
78+
*/
79+
private Boolean historyEnabled = null;
80+
7681
/**
7782
* This marks the project as (not)ready before initial index is done. this
7883
* is to avoid all/multi-project searches referencing this project from
@@ -184,7 +189,7 @@ public void setName(String name) {
184189
* that you should ALWAYS prefix the path with current file.separator ,
185190
* current environment should always have it set up
186191
*
187-
* @param path the relative path from source sroot where this project is
192+
* @param path the relative path from source root where this project is
188193
* located.
189194
*/
190195
public void setPath(String path) {
@@ -248,6 +253,20 @@ public void setHandleRenamedFiles(boolean flag) {
248253
this.handleRenamedFiles = flag;
249254
}
250255

256+
/**
257+
* @return true if this project should have history cache.
258+
*/
259+
public boolean isHistoryEnabled() {
260+
return historyEnabled != null && historyEnabled;
261+
}
262+
263+
/**
264+
* @param flag true if project should have history cache, false otherwise.
265+
*/
266+
public void setHistoryEnabled(boolean flag) {
267+
this.historyEnabled = flag;
268+
}
269+
251270
/**
252271
* Return groups where this project belongs
253272
*
@@ -302,6 +321,11 @@ final public void completeWithDefaults(Configuration cfg) {
302321
if (handleRenamedFiles == null) {
303322
setHandleRenamedFiles(cfg.isHandleHistoryOfRenamedFiles());
304323
}
324+
325+
// Allow project to override global setting of history cache generation.
326+
if (historyEnabled == null) {
327+
setHistoryEnabled(cfg.isHistoryEnabled());
328+
}
305329
}
306330

307331
/**

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ public void removeRepositories() {
803803
public void setRepositories(String dir) {
804804
List<RepositoryInfo> repos = new ArrayList<>(HistoryGuru.getInstance().
805805
addRepositories(new File[]{new File(dir)},
806-
RuntimeEnvironment.getInstance().getIgnoredNames()));
806+
RuntimeEnvironment.getInstance().getIgnoredNames()));
807807
RuntimeEnvironment.getInstance().setRepositories(repos);
808808
}
809809

@@ -1236,18 +1236,6 @@ public void setHandleHistoryOfRenamedFiles(boolean enable) {
12361236
public boolean isHandleHistoryOfRenamedFiles() {
12371237
return threadConfig.get().isHandleHistoryOfRenamedFiles();
12381238
}
1239-
1240-
public boolean isHandleHistoryOfRenamedFilesForProject(Project project) {
1241-
if (hasProjects() && project != null) {
1242-
return project.isHandleRenamedFiles();
1243-
} else {
1244-
return isHandleHistoryOfRenamedFiles();
1245-
}
1246-
}
1247-
1248-
public boolean isHandleHistoryOfRenamedFilesFor(String path) {
1249-
return isHandleHistoryOfRenamedFilesForProject(Project.getProject(path));
1250-
}
12511239

12521240
public void setRevisionMessageCollapseThreshold(int threshold) {
12531241
threadConfig.get().setRevisionMessageCollapseThreshold(threshold);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import java.util.logging.Logger;
5555
import java.util.zip.GZIPInputStream;
5656
import java.util.zip.GZIPOutputStream;
57-
import org.opensolaris.opengrok.configuration.Project;
5857
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
5958
import org.opensolaris.opengrok.logger.LoggerFactory;
6059
import org.opensolaris.opengrok.util.ForbiddenSymlinkException;
@@ -69,8 +68,8 @@ class FileHistoryCache implements HistoryCache {
6968

7069
private final Object lock = new Object();
7170

72-
private final static String historyCacheDirName = "historycache";
73-
private final static String latestRevFileName = "OpenGroklatestRev";
71+
private final static String HISTORY_CACHE_DIR_NAME = "historycache";
72+
private final static String LATEST_REV_FILE_NAME = "OpenGroklatestRev";
7473
private final static String DIRECTORY_FILE_PREFIX = "OpenGrokDirHist";
7574

7675
private boolean historyIndexDone = false;
@@ -201,7 +200,7 @@ private static File getCachedFile(File file) throws HistoryException,
201200
StringBuilder sb = new StringBuilder();
202201
sb.append(env.getDataRootPath());
203202
sb.append(File.separatorChar);
204-
sb.append(historyCacheDirName);
203+
sb.append(HISTORY_CACHE_DIR_NAME);
205204

206205
try {
207206
String add = env.getPathRelativeToSourceRoot(file);
@@ -589,7 +588,8 @@ public History get(File file, Repository repository, boolean withFiles)
589588
* fetched in the first phase of indexing.
590589
*/
591590
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
592-
if (isHistoryIndexDone() && repository.hasHistoryForDirectories() &&
591+
if (isHistoryIndexDone() && repository.isHistoryEnabled() &&
592+
repository.hasHistoryForDirectories() &&
593593
!env.isFetchHistoryWhenNotInCache()) {
594594
return null;
595595
}
@@ -651,7 +651,7 @@ public boolean hasCacheForDirectory(File directory, Repository repository)
651651
}
652652
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
653653
File dir = env.getDataRootFile();
654-
dir = new File(dir, FileHistoryCache.historyCacheDirName);
654+
dir = new File(dir, FileHistoryCache.HISTORY_CACHE_DIR_NAME);
655655
try {
656656
dir = new File(dir, env.getPathRelativeToSourceRoot(
657657
new File(repos.getDirectoryName())));
@@ -692,14 +692,14 @@ public String getRepositoryHistDataDirname(Repository repository) {
692692
}
693693

694694
return env.getDataRootPath() + File.separatorChar
695-
+ FileHistoryCache.historyCacheDirName
695+
+ FileHistoryCache.HISTORY_CACHE_DIR_NAME
696696
+ repoDirBasename;
697697
}
698698

699699
private String getRepositoryCachedRevPath(Repository repository) {
700700
String histDir = getRepositoryHistDataDirname(repository);
701701
if (histDir == null) return null;
702-
return histDir + File.separatorChar + latestRevFileName;
702+
return histDir + File.separatorChar + LATEST_REV_FILE_NAME;
703703
}
704704

705705
/**

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public History getHistory(File file, boolean withFiles, boolean ui)
250250
|| (rscm == RemoteSCM.ON)
251251
|| (ui || ((rscm == RemoteSCM.DIRBASED) && (repo != null) && repo.hasHistoryForDirectories()));
252252

253-
if (repo != null && repo.isWorking() && repo.fileHasHistory(file)
253+
if (repo != null && repo.isHistoryEnabled() && repo.isWorking() && repo.fileHasHistory(file)
254254
&& (!repo.isRemote() || doRemote)) {
255255

256256
if (useCache() && historyCache.supportsRepository(repo)) {
@@ -387,14 +387,6 @@ private Collection<RepositoryInfo> addRepositories(File[] files,
387387
String path;
388388
try {
389389
path = file.getCanonicalPath();
390-
File skipRepository = new File(path, ".opengrok_skip_history");
391-
// Should potential repository be ignored?
392-
if (skipRepository.exists()) {
393-
LOGGER.log(Level.INFO,
394-
"Skipping history cache creation for {0} and its subdirectories",
395-
file.getAbsolutePath());
396-
continue;
397-
}
398390

399391
Repository repository = null;
400392
try {
@@ -576,6 +568,12 @@ private void createCache(Repository repository, String sinceRevision) {
576568
String path = repository.getDirectoryName();
577569
String type = repository.getClass().getSimpleName();
578570

571+
if (!repository.isHistoryEnabled()) {
572+
LOGGER.log(Level.INFO,
573+
"Skipping history cache creation of {0} repository in {1} and its subdirectories",
574+
new Object[]{type, path});
575+
}
576+
579577
if (repository.isWorking()) {
580578
boolean verbose = RuntimeEnvironment.getInstance().isVerbose();
581579
Statistics elapsed = new Statistics();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public static Repository getRepository(File file, boolean interactive)
161161
repo.buildTagList(file, interactive);
162162
}
163163

164+
repo.fillFromProject();
165+
164166
break;
165167
}
166168
}

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Objects;
3131
import java.util.logging.Level;
3232
import java.util.logging.Logger;
33+
import org.opensolaris.opengrok.configuration.Project;
3334
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
3435
import org.opensolaris.opengrok.logger.LoggerFactory;
3536
import org.opensolaris.opengrok.util.ClassUtil;
@@ -67,6 +68,7 @@ public class RepositoryInfo implements Serializable {
6768
protected String currentVersion;
6869

6970
private boolean handleRenamedFiles;
71+
private boolean historyEnabled;
7072

7173
/**
7274
* format used for printing the date in {@code currentVersion}
@@ -98,6 +100,24 @@ public boolean isHandleRenamedFiles() {
98100
return this.handleRenamedFiles;
99101
}
100102

103+
/**
104+
* @param flag true if the repository should handle renamed files, false otherwise.
105+
*/
106+
public void setHandleRenamedFiles(boolean flag) {
107+
this.handleRenamedFiles = flag;
108+
}
109+
110+
/**
111+
* @return true if the repository should have history cache.
112+
*/
113+
public boolean isHistoryEnabled() {
114+
return this.historyEnabled;
115+
}
116+
117+
public void setHistoryEnabled(boolean flag) {
118+
this.historyEnabled = flag;
119+
}
120+
101121
/**
102122
* @return relative path to source root
103123
*/
@@ -111,9 +131,6 @@ public String getDirectoryNameRelative() {
111131
*/
112132
public void setDirectoryNameRelative(String dir) {
113133
this.directoryNameRelative = dir;
114-
115-
handleRenamedFiles = RuntimeEnvironment.getInstance().
116-
isHandleHistoryOfRenamedFilesFor(dir);
117134
}
118135

119136
/**
@@ -256,6 +273,22 @@ public void setCurrentVersion(String currentVersion) {
256273
this.currentVersion = currentVersion;
257274
}
258275

276+
/**
277+
* Fill configurable properties from associated project (if any) or Configuration.
278+
*/
279+
public void fillFromProject() {
280+
Project proj = Project.getProject(getDirectoryNameRelative());
281+
if (proj != null) {
282+
setHistoryEnabled(proj.isHistoryEnabled());
283+
setHandleRenamedFiles(proj.isHandleRenamedFiles());
284+
} else {
285+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
286+
287+
setHistoryEnabled(env.isHistoryEnabled());
288+
setHandleRenamedFiles(env.isHandleHistoryOfRenamedFiles());
289+
}
290+
}
291+
259292
@Override
260293
public boolean equals(Object obj) {
261294
if (!(obj instanceof RepositoryInfo)) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public final class IgnoredFiles extends Filter {
5555
".vsmdi", // Visual Studio tests
5656
"*.dll",
5757
"*.DLL",
58-
".opengrok_skip_history",
5958
};
6059

6160
public IgnoredFiles() {

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,8 @@ public void prepareIndexer(RuntimeEnvironment env,
884884
throw new IndexerException("Internal error, zapCache shouldn't be null");
885885
}
886886

887+
// Projects need to be created first since when adding repositories below,
888+
// some of the project properties might be needed for that.
887889
if (addProjects) {
888890
File files[] = env.getSourceRootFile().listFiles();
889891
Map<String,Project> projects = env.getProjects();
@@ -921,11 +923,10 @@ public void prepareIndexer(RuntimeEnvironment env,
921923
if (searchRepositories || listRepoPaths || !zapCache.isEmpty()) {
922924
LOGGER.log(Level.INFO, "Scanning for repositories...");
923925
long start = System.currentTimeMillis();
924-
if (env.isHistoryEnabled()) {
925-
env.setRepositories(env.getSourceRootPath());
926-
}
926+
env.setRepositories(env.getSourceRootPath());
927927
long time = (System.currentTimeMillis() - start) / 1000;
928928
LOGGER.log(Level.INFO, "Done scanning for repositories ({0}s)", time);
929+
929930
if (listRepoPaths || !zapCache.isEmpty()) {
930931
List<RepositoryInfo> repos = env.getRepositories();
931932
String prefix = env.getSourceRootPath();
@@ -990,18 +991,17 @@ public void prepareIndexer(RuntimeEnvironment env,
990991
}
991992
}
992993

993-
if (env.isHistoryEnabled()) {
994-
if (repositories != null && !repositories.isEmpty()) {
995-
LOGGER.log(Level.INFO, "Generating history cache for repositories: " +
996-
repositories.stream().collect(Collectors.joining(",")));
997-
HistoryGuru.getInstance().createCache(repositories);
998-
LOGGER.info("Done...");
999-
} else {
1000-
LOGGER.log(Level.INFO, "Generating history cache for all repositories ...");
1001-
HistoryGuru.getInstance().createCache();
1002-
LOGGER.info("Done...");
1003-
}
1004-
}
994+
// Even if history is disabled globally, it can be enabled for some repositories.
995+
if (repositories != null && !repositories.isEmpty()) {
996+
LOGGER.log(Level.INFO, "Generating history cache for repositories: " +
997+
repositories.stream().collect(Collectors.joining(",")));
998+
HistoryGuru.getInstance().createCache(repositories);
999+
LOGGER.info("Done...");
1000+
} else {
1001+
LOGGER.log(Level.INFO, "Generating history cache for all repositories ...");
1002+
HistoryGuru.getInstance().createCache();
1003+
LOGGER.info("Done...");
1004+
}
10051005

10061006
if (listFiles) {
10071007
for (String file : IndexDatabase.getAllFiles(subFiles)) {

0 commit comments

Comments
 (0)