Skip to content

Commit 57c0c6c

Browse files
committed
allow control of history tagging per project
fixes #4792
1 parent e34493b commit 57c0c6c

File tree

12 files changed

+152
-64
lines changed

12 files changed

+152
-64
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Project.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public class Project implements Comparable<Project>, Nameable, Serializable {
103103
*/
104104
private Boolean mergeCommitsEnabled = null;
105105

106+
/**
107+
* This flag enables/disables per project tagging of history entries.
108+
*/
109+
private Boolean tagsEnabled = null;
110+
106111
/**
107112
* Username to used for repository authentication. This is propagated to all repositories of this project.
108113
*/
@@ -285,6 +290,13 @@ public boolean isMergeCommitsEnabled() {
285290
return mergeCommitsEnabled != null && mergeCommitsEnabled;
286291
}
287292

293+
/**
294+
* @return whether tagging of history entries is on
295+
*/
296+
public boolean isTagsEnabled() {
297+
return tagsEnabled != null && tagsEnabled;
298+
}
299+
288300
/**
289301
* @param flag true if project should handle renamed files, false otherwise.
290302
*/
@@ -341,6 +353,13 @@ public final void setMergeCommitsEnabled(boolean flag) {
341353
this.mergeCommitsEnabled = flag;
342354
}
343355

356+
/**
357+
* @param flag whether to tag history entries
358+
*/
359+
public final void setTagsEnabled(boolean flag) {
360+
this.tagsEnabled = flag;
361+
}
362+
344363
/**
345364
* @return true if this project handles renamed files.
346365
*/
@@ -555,6 +574,10 @@ public final void completeWithDefaults() {
555574
if (historyBasedReindex == null) {
556575
setHistoryBasedReindex(env.isHistoryBasedReindex());
557576
}
577+
578+
if (tagsEnabled == null) {
579+
setTagsEnabled(env.isTagsEnabled());
580+
}
558581
}
559582

560583
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/history/BazaarRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -206,7 +206,7 @@ History getHistory(File file, String sinceRevision) throws HistoryException {
206206
History result = new BazaarHistoryParser(this).parse(file, sinceRevision);
207207
// Assign tags to changesets they represent
208208
// We don't need to check if this repository supports tags, because we know it:-)
209-
if (env.isTagsEnabled()) {
209+
if (this.isTagsEnabled()) {
210210
assignTagsInHistory(result);
211211
}
212212
return result;

opengrok-indexer/src/main/java/org/opengrok/indexer/history/BitKeeperRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ History getHistory(File file, String sinceRevision) throws HistoryException {
293293
// Assign tags to changesets they represent
294294
// We don't need to check if this repository supports tags,
295295
// because we know it :-)
296-
if (env.isTagsEnabled()) {
296+
if (this.isTagsEnabled()) {
297297
assignTagsInHistory(history);
298298
}
299299

opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void doFileHistory(String filename, History history, Repository reposito
129129
}
130130

131131
// Assign tags to changesets they represent.
132-
if (env.isTagsEnabled() && repository.hasFileBasedTags()) {
132+
if (repository.isTagsEnabled() && repository.hasFileBasedTags()) {
133133
repository.assignTagsInHistory(history);
134134
}
135135

@@ -183,7 +183,7 @@ static History readHistory(File cacheFile, Repository repository) throws IOExcep
183183
History history = new History(historyEntryList);
184184

185185
// Read tags from separate file.
186-
if (env.isTagsEnabled() && repository.hasFileBasedTags()) {
186+
if (repository.isTagsEnabled() && repository.hasFileBasedTags()) {
187187
File tagFile = getTagsFile(cacheFile);
188188
try (SmileParser parser = factory.createParser(tagFile)) {
189189
parser.setCodec(mapper);
@@ -290,11 +290,11 @@ public void storeFile(History history, File file, Repository repository) throws
290290
*
291291
* @param histNew history object to store
292292
* @param file file to store the history object into
293-
* @param repo repository for the file
293+
* @param repository repository for the file
294294
* @param mergeHistory whether to merge the history with existing or store the histNew as is
295295
* @throws HistoryException if there was any problem with history cache generation
296296
*/
297-
private void storeFile(History histNew, File file, Repository repo, boolean mergeHistory) throws HistoryException {
297+
private void storeFile(History histNew, File file, Repository repository, boolean mergeHistory) throws HistoryException {
298298
File cacheFile;
299299
try {
300300
cacheFile = getCachedFile(file);
@@ -321,7 +321,7 @@ private void storeFile(History histNew, File file, Repository repo, boolean merg
321321
throw new HistoryException("Failed to write history", ioe);
322322
}
323323

324-
boolean assignTags = env.isTagsEnabled() && repo.hasFileBasedTags();
324+
boolean assignTags = repository.isTagsEnabled() && repository.hasFileBasedTags();
325325

326326
// Append the contents of the pre-existing cache file to the temporary file.
327327
if (mergeHistory && cacheFile.exists()) {
@@ -353,7 +353,7 @@ private void storeFile(History histNew, File file, Repository repo, boolean merg
353353
// to this somewhat crude solution of re-tagging from scratch.
354354
if (assignTags) {
355355
histNew.strip();
356-
repo.assignTagsInHistory(histNew);
356+
repository.assignTagsInHistory(histNew);
357357
}
358358
}
359359

opengrok-indexer/src/main/java/org/opengrok/indexer/history/Repository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ final void createCache(HistoryCache cache, String sinceRevision) throws HistoryE
415415
void finishCreateCache(HistoryCache cache, History history, String tillRevision) throws CacheException {
416416
// We need to refresh list of tags for incremental reindex.
417417
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
418-
if (env.isTagsEnabled() && this.hasFileBasedTags()) {
418+
if (this.isTagsEnabled() && this.hasFileBasedTags()) {
419419
this.buildTagList(new File(this.getDirectoryName()), CommandTimeoutType.INDEXER);
420420
}
421421

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryFactory.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -215,11 +215,11 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType, bo
215215
});
216216
}
217217

218-
if (repo.getType() == null || repo.getType().length() == 0) {
218+
if (repo.getType() == null || repo.getType().isEmpty()) {
219219
repo.setType(repo.getClass().getSimpleName());
220220
}
221221

222-
if (repo.getParent() == null || repo.getParent().length() == 0) {
222+
if (repo.getParent() == null || repo.getParent().isEmpty()) {
223223
try {
224224
repo.setParent(repo.determineParent(cmdType));
225225
} catch (IOException ex) {
@@ -229,7 +229,7 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType, bo
229229
}
230230
}
231231

232-
if (repo.getBranch() == null || repo.getBranch().length() == 0) {
232+
if (repo.getBranch() == null || repo.getBranch().isEmpty()) {
233233
try {
234234
repo.setBranch(repo.determineBranch(cmdType));
235235
} catch (IOException ex) {
@@ -239,7 +239,7 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType, bo
239239
}
240240
}
241241

242-
if (repo.getCurrentVersion() == null || repo.getCurrentVersion().length() == 0) {
242+
if (repo.getCurrentVersion() == null || repo.getCurrentVersion().isEmpty()) {
243243
try {
244244
repo.setCurrentVersion(repo.determineCurrentVersion(cmdType));
245245
} catch (IOException ex) {
@@ -249,14 +249,16 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType, bo
249249
}
250250
}
251251

252+
// This has to be called before building tag list below as it depends on the repository properties
253+
// inherited from the project/configuration.
254+
repo.fillFromProject();
255+
252256
// If this repository displays tags only for files changed by tagged
253257
// revision, we need to prepare list of all tags in advance.
254-
if (cmdType.equals(CommandTimeoutType.INDEXER) && env.isTagsEnabled() && repo.hasFileBasedTags()) {
258+
if (cmdType.equals(CommandTimeoutType.INDEXER) && repo.isTagsEnabled() && repo.hasFileBasedTags()) {
255259
repo.buildTagList(file, cmdType);
256260
}
257261

258-
repo.fillFromProject();
259-
260262
break;
261263
}
262264
}

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryInfo.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public class RepositoryInfo implements Serializable {
8484
@DTOElement
8585
private boolean mergeCommitsEnabled;
8686
@DTOElement
87+
private boolean tagsEnabled;
88+
@DTOElement
8789
private boolean historyBasedReindex;
8890
@DTOElement
8991
private String username;
@@ -112,6 +114,7 @@ public RepositoryInfo(RepositoryInfo orig) {
112114
this.handleRenamedFiles = orig.handleRenamedFiles;
113115
this.mergeCommitsEnabled = orig.mergeCommitsEnabled;
114116
this.historyBasedReindex = orig.historyBasedReindex;
117+
this.tagsEnabled = orig.tagsEnabled;
115118
this.username = orig.username;
116119
this.password = orig.password;
117120
}
@@ -145,13 +148,27 @@ public boolean isMergeCommitsEnabled() {
145148
return this.mergeCommitsEnabled;
146149
}
147150

151+
/**
152+
* @return whether history entries should be tagged
153+
*/
154+
public boolean isTagsEnabled() {
155+
return this.tagsEnabled;
156+
}
157+
148158
/**
149159
* @param flag true if the repository should handle merge commits, false otherwise.
150160
*/
151161
public void setMergeCommitsEnabled(boolean flag) {
152162
this.mergeCommitsEnabled = flag;
153163
}
154164

165+
/**
166+
* @param flag whether to tag history entries
167+
*/
168+
public void setTagsEnabled(boolean flag) {
169+
this.tagsEnabled = flag;
170+
}
171+
155172
/**
156173
* @return true if history based reindex is enabled for the repository, false otherwise
157174
*/
@@ -399,6 +416,7 @@ public void fillFromProject() {
399416
setAnnotationCacheEnabled(proj.isAnnotationCacheEnabled());
400417
setHandleRenamedFiles(proj.isHandleRenamedFiles());
401418
setMergeCommitsEnabled(proj.isMergeCommitsEnabled());
419+
setTagsEnabled(proj.isTagsEnabled());
402420
setHistoryBasedReindex(proj.isHistoryBasedReindex());
403421
setUsername(proj.getUsername());
404422
setPassword(proj.getPassword());
@@ -410,6 +428,7 @@ public void fillFromProject() {
410428
setAnnotationCacheEnabled(env.isAnnotationCacheEnabled());
411429
setHandleRenamedFiles(env.isHandleHistoryOfRenamedFiles());
412430
setMergeCommitsEnabled(env.isMergeCommitsEnabled());
431+
setTagsEnabled(env.isTagsEnabled());
413432
setHistoryBasedReindex(env.isHistoryBasedReindex());
414433
}
415434
}
@@ -480,6 +499,13 @@ public String toString() {
480499
stringBuilder.append("annotationCache=off");
481500
}
482501

502+
stringBuilder.append(",");
503+
if (isTagsEnabled()) {
504+
stringBuilder.append("tagsEnabled=on");
505+
} else {
506+
stringBuilder.append("tagsEnabled=off");
507+
}
508+
483509
if (getUsername() != null) {
484510
stringBuilder.append(",");
485511
stringBuilder.append("username:set");

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryWithHistoryTraversal.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public History getHistory(File file, String sinceRevision, String tillRevision,
116116
historyCollector.latestRev);
117117

118118
// Assign tags to changesets they represent.
119-
if (RuntimeEnvironment.getInstance().isTagsEnabled() && hasFileBasedTags()) {
119+
if (this.isTagsEnabled() && hasFileBasedTags()) {
120120
assignTagsInHistory(history);
121121
}
122122

@@ -155,7 +155,7 @@ protected void doCreateCache(HistoryCache cache, String sinceRevision, File dire
155155
historyCollector.latestRev);
156156

157157
// Assign tags to changesets they represent.
158-
if (env.isTagsEnabled() && hasFileBasedTags()) {
158+
if (this.isTagsEnabled() && hasFileBasedTags()) {
159159
assignTagsInHistory(history);
160160
}
161161

@@ -197,7 +197,7 @@ protected void doCreateCache(HistoryCache cache, String sinceRevision, File dire
197197
historyCollector.latestRev);
198198

199199
// Assign tags to changesets they represent.
200-
if (env.isTagsEnabled() && hasFileBasedTags()) {
200+
if (this.isTagsEnabled() && hasFileBasedTags()) {
201201
assignTagsInHistory(history);
202202
}
203203

opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/ProjectTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.configuration;
2424

@@ -149,6 +149,7 @@ void testMergeProjects1() {
149149
env.setBugPattern("([1-9][0-9]{6,7})");
150150
env.setReviewPage("http://example.com/reviewPage");
151151
env.setReviewPattern("([A-Z]{2}ARC[ \\\\/]\\\\d{4}/\\\\d{3})");
152+
env.setTagsEnabled(!new Configuration().isTagsEnabled());
152153

153154
Project p1 = new Project();
154155
assertNotNull(p1);
@@ -161,7 +162,8 @@ void testMergeProjects1() {
161162
() -> assertEquals(env.getBugPage(), p1.getBugPage()),
162163
() -> assertEquals(env.getBugPattern(), p1.getBugPattern()),
163164
() -> assertEquals(env.getReviewPage(), p1.getReviewPage()),
164-
() -> assertEquals(env.getReviewPattern(), p1.getReviewPattern())
165+
() -> assertEquals(env.getReviewPattern(), p1.getReviewPattern()),
166+
() -> assertEquals(env.isTagsEnabled(), p1.isTagsEnabled())
165167
);
166168
}
167169

@@ -205,6 +207,7 @@ void testMergeProjects2() {
205207
p1.setTabSize(new Project().getTabSize() + 9737);
206208
p1.setNavigateWindowEnabled(true);
207209
p1.setHandleRenamedFiles(true);
210+
p1.setTagsEnabled(true);
208211
final String customBugPage = "http://example.com/bugPage";
209212
p1.setBugPage(customBugPage);
210213
final String customBugPattern = "([1-9][0-1]{6,7})";
@@ -220,11 +223,12 @@ void testMergeProjects2() {
220223
() -> assertNotNull(p1),
221224
() -> assertTrue(p1.isNavigateWindowEnabled(), "Navigate window should be turned on"),
222225
() -> assertTrue(p1.isHandleRenamedFiles(), "Renamed file handling should be true"),
226+
() -> assertTrue(p1.isTagsEnabled(), "Tags should be turned on"),
223227
() -> assertEquals(new Project().getTabSize() + 9737, p1.getTabSize()),
224-
() -> assertEquals(p1.getBugPage(), customBugPage),
225-
() -> assertEquals(p1.getBugPattern(), customBugPattern),
226-
() -> assertEquals(p1.getReviewPage(), customReviewPage),
227-
() -> assertEquals(p1.getReviewPattern(), customReviewPattern)
228+
() -> assertEquals(customBugPage, p1.getBugPage()),
229+
() -> assertEquals(customBugPattern, p1.getBugPattern()),
230+
() -> assertEquals(customReviewPage, p1.getReviewPage()),
231+
() -> assertEquals(customReviewPattern, p1.getReviewPattern())
228232
);
229233
}
230234

0 commit comments

Comments
 (0)