Skip to content

Commit 0817a68

Browse files
author
Vladimir Kotal
authored
per project renamed file handling (#2134)
1 parent 38f7757 commit 0817a68

File tree

11 files changed

+117
-60
lines changed

11 files changed

+117
-60
lines changed

opengrok-web-nbproject/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bcel.version=6.2
3636
bcel.jar=bcel-${bcel.version}.jar
3737
file.reference.bcel.jar=../lib/${bcel.jar}
3838
file.reference.json-simple-1.1.1.jar=../lib/json-simple-1.1.1.jar
39-
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.6.3.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
39+
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
4040
lucene.version=7.3.1
4141
lucene-core.jar=lucene-core-${lucene.version}.jar
4242
lucene-analyzers-common.jar=lucene-analyzers-common-${lucene.version}.jar

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

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

2020
/*
21-
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
22-
*/
21+
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
22+
*/
2323
package org.opensolaris.opengrok.configuration;
2424

2525
import java.io.File;
@@ -68,6 +68,11 @@ public class Project implements Comparable<Project>, Nameable, Serializable {
6868
*/
6969
private boolean navigateWindowEnabled = false;
7070

71+
/**
72+
* This flag sets per-project handling of renamed files.
73+
*/
74+
private Boolean handleRenamedFiles = null;
75+
7176
/**
7277
* This marks the project as (not)ready before initial index is done. this
7378
* is to avoid all/multi-project searches referencing this project from
@@ -229,6 +234,20 @@ public void setNavigateWindowEnabled(boolean navigateWindowEnabled) {
229234
this.navigateWindowEnabled = navigateWindowEnabled;
230235
}
231236

237+
/**
238+
* @return true if this project handles renamed files.
239+
*/
240+
public boolean isHandleRenamedFiles() {
241+
return handleRenamedFiles != null && handleRenamedFiles;
242+
}
243+
244+
/**
245+
* @param flag true if project should handle renamed files, false otherwise.
246+
*/
247+
public void setHandleRenamedFiles(boolean flag) {
248+
this.handleRenamedFiles = flag;
249+
}
250+
232251
/**
233252
* Return groups where this project belongs
234253
*
@@ -263,7 +282,7 @@ public void addGroup(Group group) {
263282
final public void completeWithDefaults(Configuration cfg) {
264283
Configuration defaultCfg = new Configuration();
265284
/**
266-
* Choosing strategy for properties (tabSize here):
285+
* Choosing strategy for properties (tabSize used as example here):
267286
* <pre>
268287
* this cfg defaultCfg chosen value
269288
* ===============================================
@@ -278,6 +297,11 @@ final public void completeWithDefaults(Configuration cfg) {
278297
if (getTabSize() == defaultCfg.getTabSize()) {
279298
setTabSize(cfg.getTabSize());
280299
}
300+
301+
// Allow project to override global setting of renamed file handling.
302+
if (handleRenamedFiles == null) {
303+
setHandleRenamedFiles(cfg.isHandleHistoryOfRenamedFiles());
304+
}
281305
}
282306

283307
/**

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,18 @@ public boolean isHandleHistoryOfRenamedFiles() {
12371237
return threadConfig.get().isHandleHistoryOfRenamedFiles();
12381238
}
12391239

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+
}
1251+
12401252
public void setRevisionMessageCollapseThreshold(int threshold) {
12411253
threadConfig.get().setRevisionMessageCollapseThreshold(threshold);
12421254
}

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

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

2020
/*
21-
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2323
*/
2424

@@ -54,6 +54,7 @@
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;
5758
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
5859
import org.opensolaris.opengrok.logger.LoggerFactory;
5960
import org.opensolaris.opengrok.util.ForbiddenSymlinkException;
@@ -406,6 +407,7 @@ private void finishStore(Repository repository, String latestRev) {
406407
public void store(History history, Repository repository)
407408
throws HistoryException {
408409
final RuntimeEnvironment env = RuntimeEnvironment.getInstance();
410+
final boolean handleRenamedFiles = repository.isHandleRenamedFiles();
409411

410412
String latestRev = null;
411413

@@ -475,7 +477,7 @@ public void store(History history, Repository repository)
475477
int fileHistoryCount = 0;
476478
for (Map.Entry<String, List<HistoryEntry>> map_entry : map.entrySet()) {
477479
try {
478-
if (env.isHandleHistoryOfRenamedFiles() &&
480+
if (handleRenamedFiles &&
479481
isRenamedFile(map_entry.getKey(), env, repository, history)) {
480482
continue;
481483
}
@@ -491,7 +493,7 @@ public void store(History history, Repository repository)
491493

492494
LOGGER.log(Level.FINE, "Stored history for {0} files", fileHistoryCount);
493495

494-
if (!env.isHandleHistoryOfRenamedFiles()) {
496+
if (!handleRenamedFiles) {
495497
finishStore(repository, latestRev);
496498
return;
497499
}

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

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

2020
/*
21-
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opensolaris.opengrok.history;
@@ -59,6 +59,12 @@ private enum ParseState {
5959
private GitRepository repository = new GitRepository();
6060
private List<HistoryEntry> entries = new ArrayList<>();
6161

62+
private final boolean handleRenamedFiles;
63+
64+
GitHistoryParser(boolean flag) {
65+
handleRenamedFiles = flag;
66+
}
67+
6268
/**
6369
* Process the output from the log command and insert the HistoryEntries
6470
* into the history field.
@@ -177,7 +183,7 @@ History parse(File file, Repository repos, String sinceRevision) throws HistoryE
177183
status));
178184
}
179185

180-
if (RuntimeEnvironment.getInstance().isHandleHistoryOfRenamedFiles()) {
186+
if (handleRenamedFiles) {
181187
executor = repository.getRenamedFilesExecutor(file, sinceRevision);
182188
status = executor.exec(true, parser);
183189

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ Executor getHistoryLogExecutor(final File file, String sinceRevision)
122122
cmd.add("--name-only");
123123
cmd.add("--pretty=fuller");
124124
cmd.add(GIT_DATE_OPT);
125-
126-
if (file.isFile() && RuntimeEnvironment.getInstance().isHandleHistoryOfRenamedFiles()) {
125+
126+
if (file.isFile() && isHandleRenamedFiles()) {
127127
cmd.add("--follow");
128128
}
129129

@@ -481,7 +481,7 @@ History getHistory(File file) throws HistoryException {
481481
History getHistory(File file, String sinceRevision)
482482
throws HistoryException {
483483
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
484-
History result = new GitHistoryParser().parse(file, this, sinceRevision);
484+
History result = new GitHistoryParser(isHandleRenamedFiles()).parse(file, this, sinceRevision);
485485
// Assign tags to changesets they represent
486486
// We don't need to check if this repository supports tags,
487487
// because we know it :-)

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

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

2020
/*
21-
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opensolaris.opengrok.history;
@@ -93,7 +93,7 @@ public class MercurialRepository extends Repository {
9393
+ END_OF_ENTRY + "\\n";
9494

9595
/**
96-
* Template for formatting hg log output for directories.
96+
* Template for formatting {@code hg log} output for directories.
9797
*/
9898
private static final String DIR_TEMPLATE_RENAMED
9999
= TEMPLATE_STUB + FILE_LIST
@@ -104,7 +104,7 @@ public class MercurialRepository extends Repository {
104104

105105
private static final Pattern LOG_COPIES_PATTERN
106106
= Pattern.compile("^(\\d+):(.*)");
107-
107+
108108
public MercurialRepository() {
109109
type = "Mercurial";
110110
datePatterns = new String[]{
@@ -188,7 +188,7 @@ Executor getHistoryLogExecutor(File file, String sinceRevision)
188188

189189
cmd.add("--template");
190190
if (file.isDirectory()) {
191-
cmd.add(env.isHandleHistoryOfRenamedFiles() ? DIR_TEMPLATE_RENAMED : DIR_TEMPLATE);
191+
cmd.add(this.isHandleRenamedFiles() ? DIR_TEMPLATE_RENAMED : DIR_TEMPLATE);
192192
} else {
193193
cmd.add(FILE_TEMPLATE);
194194
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public class RepositoryInfo implements Serializable {
6666
protected String branch;
6767
protected String currentVersion;
6868

69+
private boolean handleRenamedFiles;
70+
6971
/**
7072
* format used for printing the date in {@code currentVersion}
7173
*/
@@ -89,6 +91,13 @@ public RepositoryInfo(RepositoryInfo orig) {
8991
this.currentVersion = orig.currentVersion;
9092
}
9193

94+
/**
95+
* @return true if the repository handles renamed files, false otherwise.
96+
*/
97+
public boolean isHandleRenamedFiles() {
98+
return this.handleRenamedFiles;
99+
}
100+
92101
/**
93102
* @return relative path to source root
94103
*/
@@ -102,6 +111,9 @@ public String getDirectoryNameRelative() {
102111
*/
103112
public void setDirectoryNameRelative(String dir) {
104113
this.directoryNameRelative = dir;
114+
115+
handleRenamedFiles = RuntimeEnvironment.getInstance().
116+
isHandleHistoryOfRenamedFilesFor(dir);
105117
}
106118

107119
/**
@@ -117,8 +129,7 @@ public String getDirectoryName() {
117129
/**
118130
* Specify the name of the root directory for this repository.
119131
*
120-
* @param dir the new name of the root directory. Can be absolute
121-
* path or relative to source root.
132+
* @param dir the new root directory
122133
*/
123134
public void setDirectoryName(File dir) {
124135
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
@@ -141,9 +152,9 @@ public void setDirectoryName(File dir) {
141152
}
142153

143154
if (path.startsWith(rootPath)) {
144-
this.directoryNameRelative = path.substring(rootPath.length());
155+
setDirectoryNameRelative(path.substring(rootPath.length()));
145156
} else {
146-
this.directoryNameRelative = path;
157+
setDirectoryNameRelative(path);
147158
}
148159
}
149160

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

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

887+
if (addProjects) {
888+
File files[] = env.getSourceRootFile().listFiles();
889+
Map<String,Project> projects = env.getProjects();
890+
891+
// Keep a copy of the old project list so that we can preserve
892+
// the customization of existing projects.
893+
Map<String, Project> oldProjects = new HashMap<>();
894+
for (Project p : projects.values()) {
895+
oldProjects.put(p.getName(), p);
896+
}
897+
898+
projects.clear();
899+
900+
// Add a project for each top-level directory in source root.
901+
for (File file : files) {
902+
String name = file.getName();
903+
String path = "/" + name;
904+
if (oldProjects.containsKey(name)) {
905+
// This is an existing object. Reuse the old project,
906+
// possibly with customizations, instead of creating a
907+
// new with default values.
908+
Project p = oldProjects.get(name);
909+
p.setPath(path);
910+
p.setName(name);
911+
p.completeWithDefaults(env.getConfiguration());
912+
projects.put(name, p);
913+
} else if (!name.startsWith(".") && file.isDirectory()) {
914+
// Found a new directory with no matching project, so
915+
// create a new project with default properties.
916+
projects.put(name, new Project(name, path, env.getConfiguration()));
917+
}
918+
}
919+
}
920+
887921
if (searchRepositories || listRepoPaths || !zapCache.isEmpty()) {
888922
LOGGER.log(Level.INFO, "Scanning for repositories...");
889923
long start = System.currentTimeMillis();
@@ -937,40 +971,6 @@ public void prepareIndexer(RuntimeEnvironment env,
937971
}
938972
}
939973

940-
if (addProjects) {
941-
File files[] = env.getSourceRootFile().listFiles();
942-
Map<String,Project> projects = env.getProjects();
943-
944-
// Keep a copy of the old project list so that we can preserve
945-
// the customization of existing projects.
946-
Map<String, Project> oldProjects = new HashMap<>();
947-
for (Project p : projects.values()) {
948-
oldProjects.put(p.getName(), p);
949-
}
950-
951-
projects.clear();
952-
953-
// Add a project for each top-level directory in source root.
954-
for (File file : files) {
955-
String name = file.getName();
956-
String path = "/" + name;
957-
if (oldProjects.containsKey(name)) {
958-
// This is an existing object. Reuse the old project,
959-
// possibly with customizations, instead of creating a
960-
// new with default values.
961-
Project p = oldProjects.get(name);
962-
p.setPath(path);
963-
p.setName(name);
964-
p.completeWithDefaults(env.getConfiguration());
965-
projects.put(name, p);
966-
} else if (!name.startsWith(".") && file.isDirectory()) {
967-
// Found a new directory with no matching project, so
968-
// create a new project with default properties.
969-
projects.put(name, new Project(name, path, env.getConfiguration()));
970-
}
971-
}
972-
}
973-
974974
if (defaultProjects != null && !defaultProjects.isEmpty()) {
975975
Set<Project> projects = new TreeSet<>();
976976
for (String projectPath : defaultProjects) {

test/org/opensolaris/opengrok/configuration/ProjectTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* CDDL HEADER END
1818
*/
1919

20-
/*
21-
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
20+
/*
21+
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.configuration;
2424

@@ -142,12 +142,10 @@ public void testMergeProjects1() {
142142
cfg.setTabSize(new Configuration().getTabSize() + 3731);
143143

144144
Project p1 = new Project();
145-
p1.setNavigateWindowEnabled(true);
146-
145+
147146
p1.completeWithDefaults(cfg);
148147

149148
assertNotNull(p1);
150-
assertTrue("Navigate window should be turned on", p1.isNavigateWindowEnabled());
151149
assertEquals(new Configuration().getTabSize() + 3731, p1.getTabSize());
152150
}
153151

@@ -161,10 +159,14 @@ public void testMergeProjects2() {
161159

162160
Project p1 = new Project();
163161
p1.setTabSize(new Project().getTabSize() + 9737);
162+
p1.setNavigateWindowEnabled(true);
163+
p1.setHandleRenamedFiles(true);
164164

165165
p1.completeWithDefaults(cfg);
166166

167167
assertNotNull(p1);
168+
assertTrue("Navigate window should be turned on", p1.isNavigateWindowEnabled());
169+
assertTrue("Renamed file handling should be true", p1.isHandleRenamedFiles());
168170
assertEquals(new Project().getTabSize() + 9737, p1.getTabSize());
169171
}
170172

0 commit comments

Comments
 (0)