Skip to content

Commit 17c862a

Browse files
author
Vladimir Kotal
committed
if economy mode is on and history off, generate xref on the fly
fixes #2316
1 parent 026d697 commit 17c862a

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/PageConfig.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ public File findDataFile() {
12211221
path, env.isCompressXref());
12221222
}
12231223

1224-
protected String getLatestRevision() {
1224+
public String getLatestRevision() {
12251225
if (!getEnv().isHistoryEnabled()) {
12261226
return null;
12271227
}
@@ -1265,15 +1265,14 @@ public boolean isLatestRevision(String rev) {
12651265
}
12661266

12671267
/**
1268-
* Get the location of cross reference for given file containing the current
1269-
* revision.
1270-
* @return location to redirect to or null if failed
1268+
* Get the location of cross reference for given file containing the given revision.
1269+
* @param revStr revision string
1270+
* @return location to redirect to or null if revision string is empty
12711271
*/
1272-
public String getLatestRevisionLocation() {
1272+
public String getRevisionLocation(String revStr) {
12731273
StringBuilder sb = new StringBuilder();
1274-
String revStr;
12751274

1276-
if ((revStr = getLatestRevision()) == null) {
1275+
if (revStr == null) {
12771276
return null;
12781277
}
12791278

opengrok-indexer/src/test/java/org/opengrok/indexer/web/PageConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public String getPathInfo() {
270270
String rev = cfg.getLatestRevision();
271271
assertNull(rev);
272272

273-
String location = cfg.getLatestRevisionLocation();
273+
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
274274
assertNull(location);
275275
}
276276

opengrok-web/src/main/webapp/list.jsp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ document.pageReady.push(function() { pageReadyList();});
8888
PageConfig cfg = PageConfig.get(request);
8989
String rev = cfg.getRequestedRevision();
9090
Project project = cfg.getProject();
91+
final String DUMMY_REVISION = "dummy";
9192
9293
String navigateWindowEnabled = project != null ? Boolean.toString(
9394
project.isNavigateWindowEnabled()) : "false";
@@ -251,8 +252,12 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
251252
if (g == Genre.PLAIN || g == Genre.HTML || g == null) {
252253
InputStream in = null;
253254
try {
254-
in = HistoryGuru.getInstance()
255-
.getRevision(resourceFile.getParent(), basename, rev);
255+
if (rev.equals(DUMMY_REVISION)) {
256+
in = new FileInputStream(resourceFile);
257+
} else {
258+
in = HistoryGuru.getInstance()
259+
.getRevision(resourceFile.getParent(), basename, rev);
260+
}
256261
} catch (Exception e) {
257262
// fall through to error message
258263
error = e.getMessage();
@@ -344,13 +349,21 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
344349
// requesting cross referenced file
345350
File xrefFile = null;
346351
347-
// Get the latest revision and redirect so that the revision number
352+
// Get the latest revision and redirect so that the revision number
348353
// appears in the URL.
349-
String location = cfg.getLatestRevisionLocation();
354+
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
350355
if (location != null) {
351356
response.sendRedirect(location);
352357
return;
353358
} else {
359+
if (!cfg.getEnv().isGenerateHtml()) {
360+
// Economy mode is on and failed to get the last revision (presumably running with history turned off).
361+
// Generate dummy revision string so that xref can be generated from the resource file directly.
362+
location = cfg.getRevisionLocation(DUMMY_REVISION);
363+
response.sendRedirect(location);
364+
return;
365+
}
366+
354367
xrefFile = cfg.findDataFile();
355368
}
356369
@@ -362,6 +375,10 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
362375
Util.dumpXref(out, xrefFile, compressed, request.getContextPath());
363376
%></pre>
364377
</div><%
378+
} else {
379+
String error = "Failed to get xref file";
380+
%>
381+
<p class="error"><%= error %></p><%
365382
}
366383
}
367384
}

0 commit comments

Comments
 (0)