Skip to content

control history tagging per project #4794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public class Project implements Comparable<Project>, Nameable, Serializable {
*/
private Boolean mergeCommitsEnabled = null;

/**
* This flag enables/disables per project tagging of history entries.
*/
private Boolean tagsEnabled = null;

/**
* Username to used for repository authentication. This is propagated to all repositories of this project.
*/
Expand Down Expand Up @@ -285,6 +290,13 @@ public boolean isMergeCommitsEnabled() {
return mergeCommitsEnabled != null && mergeCommitsEnabled;
}

/**
* @return whether tagging of history entries is on
*/
public boolean isTagsEnabled() {
return tagsEnabled != null && tagsEnabled;
}

/**
* @param flag true if project should handle renamed files, false otherwise.
*/
Expand Down Expand Up @@ -341,6 +353,13 @@ public final void setMergeCommitsEnabled(boolean flag) {
this.mergeCommitsEnabled = flag;
}

/**
* @param flag whether to tag history entries
*/
public final void setTagsEnabled(boolean flag) {
this.tagsEnabled = flag;
}

/**
* @return true if this project handles renamed files.
*/
Expand Down Expand Up @@ -555,6 +574,10 @@ public final void completeWithDefaults() {
if (historyBasedReindex == null) {
setHistoryBasedReindex(env.isHistoryBasedReindex());
}

if (tagsEnabled == null) {
setTagsEnabled(env.isTagsEnabled());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2018, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;
Expand Down Expand Up @@ -206,7 +206,7 @@ History getHistory(File file, String sinceRevision) throws HistoryException {
History result = new BazaarHistoryParser(this).parse(file, sinceRevision);
// Assign tags to changesets they represent
// We don't need to check if this repository supports tags, because we know it:-)
if (env.isTagsEnabled()) {
if (this.isTagsEnabled()) {
assignTagsInHistory(result);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ History getHistory(File file, String sinceRevision) throws HistoryException {
// Assign tags to changesets they represent
// We don't need to check if this repository supports tags,
// because we know it :-)
if (env.isTagsEnabled()) {
if (this.isTagsEnabled()) {
assignTagsInHistory(history);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void doFileHistory(String filename, History history, Repository reposito
}

// Assign tags to changesets they represent.
if (env.isTagsEnabled() && repository.hasFileBasedTags()) {
if (repository.isTagsEnabled() && repository.hasFileBasedTags()) {
repository.assignTagsInHistory(history);
}

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

// Read tags from separate file.
if (env.isTagsEnabled() && repository.hasFileBasedTags()) {
if (repository.isTagsEnabled() && repository.hasFileBasedTags()) {
File tagFile = getTagsFile(cacheFile);
try (SmileParser parser = factory.createParser(tagFile)) {
parser.setCodec(mapper);
Expand Down Expand Up @@ -290,11 +290,11 @@ public void storeFile(History history, File file, Repository repository) throws
*
* @param histNew history object to store
* @param file file to store the history object into
* @param repo repository for the file
* @param repository repository for the file
* @param mergeHistory whether to merge the history with existing or store the histNew as is
* @throws HistoryException if there was any problem with history cache generation
*/
private void storeFile(History histNew, File file, Repository repo, boolean mergeHistory) throws HistoryException {
private void storeFile(History histNew, File file, Repository repository, boolean mergeHistory) throws HistoryException {
File cacheFile;
try {
cacheFile = getCachedFile(file);
Expand All @@ -321,7 +321,7 @@ private void storeFile(History histNew, File file, Repository repo, boolean merg
throw new HistoryException("Failed to write history", ioe);
}

boolean assignTags = env.isTagsEnabled() && repo.hasFileBasedTags();
boolean assignTags = repository.isTagsEnabled() && repository.hasFileBasedTags();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ final void createCache(HistoryCache cache, String sinceRevision) throws HistoryE
void finishCreateCache(HistoryCache cache, History history, String tillRevision) throws CacheException {
// We need to refresh list of tags for incremental reindex.
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (env.isTagsEnabled() && this.hasFileBasedTags()) {
if (this.isTagsEnabled() && this.hasFileBasedTags()) {
this.buildTagList(new File(this.getDirectoryName()), CommandTimeoutType.INDEXER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

if (repo.getType() == null || repo.getType().length() == 0) {
if (repo.getType() == null || repo.getType().isEmpty()) {
repo.setType(repo.getClass().getSimpleName());
}

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

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

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

// This has to be called before building tag list below as it depends on the repository properties
// inherited from the project/configuration.
repo.fillFromProject();

// If this repository displays tags only for files changed by tagged
// revision, we need to prepare list of all tags in advance.
if (cmdType.equals(CommandTimeoutType.INDEXER) && env.isTagsEnabled() && repo.hasFileBasedTags()) {
if (cmdType.equals(CommandTimeoutType.INDEXER) && repo.isTagsEnabled() && repo.hasFileBasedTags()) {
repo.buildTagList(file, cmdType);
}

repo.fillFromProject();

break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class RepositoryInfo implements Serializable {
@DTOElement
private boolean mergeCommitsEnabled;
@DTOElement
private boolean tagsEnabled;
@DTOElement
private boolean historyBasedReindex;
@DTOElement
private String username;
Expand Down Expand Up @@ -112,6 +114,7 @@ public RepositoryInfo(RepositoryInfo orig) {
this.handleRenamedFiles = orig.handleRenamedFiles;
this.mergeCommitsEnabled = orig.mergeCommitsEnabled;
this.historyBasedReindex = orig.historyBasedReindex;
this.tagsEnabled = orig.tagsEnabled;
this.username = orig.username;
this.password = orig.password;
}
Expand Down Expand Up @@ -145,13 +148,27 @@ public boolean isMergeCommitsEnabled() {
return this.mergeCommitsEnabled;
}

/**
* @return whether history entries should be tagged
*/
public boolean isTagsEnabled() {
return this.tagsEnabled;
}

/**
* @param flag true if the repository should handle merge commits, false otherwise.
*/
public void setMergeCommitsEnabled(boolean flag) {
this.mergeCommitsEnabled = flag;
}

/**
* @param flag whether to tag history entries
*/
public void setTagsEnabled(boolean flag) {
this.tagsEnabled = flag;
}

/**
* @return true if history based reindex is enabled for the repository, false otherwise
*/
Expand Down Expand Up @@ -399,6 +416,7 @@ public void fillFromProject() {
setAnnotationCacheEnabled(proj.isAnnotationCacheEnabled());
setHandleRenamedFiles(proj.isHandleRenamedFiles());
setMergeCommitsEnabled(proj.isMergeCommitsEnabled());
setTagsEnabled(proj.isTagsEnabled());
setHistoryBasedReindex(proj.isHistoryBasedReindex());
setUsername(proj.getUsername());
setPassword(proj.getPassword());
Expand All @@ -410,6 +428,7 @@ public void fillFromProject() {
setAnnotationCacheEnabled(env.isAnnotationCacheEnabled());
setHandleRenamedFiles(env.isHandleHistoryOfRenamedFiles());
setMergeCommitsEnabled(env.isMergeCommitsEnabled());
setTagsEnabled(env.isTagsEnabled());
setHistoryBasedReindex(env.isHistoryBasedReindex());
}
}
Expand Down Expand Up @@ -458,7 +477,7 @@ public String toString() {
if (!isHistoryCacheEnabled()) {
stringBuilder.append("historyCache=off");
} else {
stringBuilder.append("historyCache=on,");
stringBuilder.append("historyCache=on");
}

if (isHandleRenamedFiles()) {
Expand All @@ -480,6 +499,13 @@ public String toString() {
stringBuilder.append("annotationCache=off");
}

stringBuilder.append(",");
if (isTagsEnabled()) {
stringBuilder.append("tagsEnabled=on");
} else {
stringBuilder.append("tagsEnabled=off");
}

if (getUsername() != null) {
stringBuilder.append(",");
stringBuilder.append("username:set");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public History getHistory(File file, String sinceRevision, String tillRevision,
historyCollector.latestRev);

// Assign tags to changesets they represent.
if (RuntimeEnvironment.getInstance().isTagsEnabled() && hasFileBasedTags()) {
if (this.isTagsEnabled() && hasFileBasedTags()) {
assignTagsInHistory(history);
}

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

// Assign tags to changesets they represent.
if (env.isTagsEnabled() && hasFileBasedTags()) {
if (this.isTagsEnabled() && hasFileBasedTags()) {
assignTagsInHistory(history);
}

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

// Assign tags to changesets they represent.
if (env.isTagsEnabled() && hasFileBasedTags()) {
if (this.isTagsEnabled() && hasFileBasedTags()) {
assignTagsInHistory(history);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.configuration;

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

Project p1 = new Project();
assertNotNull(p1);
Expand All @@ -161,7 +162,8 @@ void testMergeProjects1() {
() -> assertEquals(env.getBugPage(), p1.getBugPage()),
() -> assertEquals(env.getBugPattern(), p1.getBugPattern()),
() -> assertEquals(env.getReviewPage(), p1.getReviewPage()),
() -> assertEquals(env.getReviewPattern(), p1.getReviewPattern())
() -> assertEquals(env.getReviewPattern(), p1.getReviewPattern()),
() -> assertEquals(env.isTagsEnabled(), p1.isTagsEnabled())
);
}

Expand Down Expand Up @@ -205,6 +207,7 @@ void testMergeProjects2() {
p1.setTabSize(new Project().getTabSize() + 9737);
p1.setNavigateWindowEnabled(true);
p1.setHandleRenamedFiles(true);
p1.setTagsEnabled(true);
final String customBugPage = "http://example.com/bugPage";
p1.setBugPage(customBugPage);
final String customBugPattern = "([1-9][0-1]{6,7})";
Expand All @@ -220,11 +223,12 @@ void testMergeProjects2() {
() -> assertNotNull(p1),
() -> assertTrue(p1.isNavigateWindowEnabled(), "Navigate window should be turned on"),
() -> assertTrue(p1.isHandleRenamedFiles(), "Renamed file handling should be true"),
() -> assertTrue(p1.isTagsEnabled(), "Tags should be turned on"),
() -> assertEquals(new Project().getTabSize() + 9737, p1.getTabSize()),
() -> assertEquals(p1.getBugPage(), customBugPage),
() -> assertEquals(p1.getBugPattern(), customBugPattern),
() -> assertEquals(p1.getReviewPage(), customReviewPage),
() -> assertEquals(p1.getReviewPattern(), customReviewPattern)
() -> assertEquals(customBugPage, p1.getBugPage()),
() -> assertEquals(customBugPattern, p1.getBugPattern()),
() -> assertEquals(customReviewPage, p1.getReviewPage()),
() -> assertEquals(customReviewPattern, p1.getReviewPattern())
);
}

Expand Down
Loading
Loading