Skip to content

Commit 96b0c14

Browse files
committed
getRevisionLocation() can be simplified without null handling
1 parent 963a3f8 commit 96b0c14

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,16 +1334,12 @@ public boolean isLatestRevision(String rev) {
13341334

13351335
/**
13361336
* Get the location of cross reference for given file containing the given revision.
1337-
* @param revStr revision string
1338-
* @return location to redirect to or null if revision string is empty
1337+
* @param revStr defined revision string
1338+
* @return location to redirect to
13391339
*/
13401340
public String getRevisionLocation(String revStr) {
13411341
StringBuilder sb = new StringBuilder();
13421342

1343-
if (revStr == null) {
1344-
return null;
1345-
}
1346-
13471343
sb.append(req.getContextPath());
13481344
sb.append(Prefix.XREF_P);
13491345
sb.append(Util.URIEncodePath(path));

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.web;
2425

@@ -332,9 +333,6 @@ public String getPathInfo() {
332333
PageConfig cfg = PageConfig.get(req2);
333334
String rev = cfg.getLatestRevision();
334335
assertNull(rev);
335-
336-
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
337-
assertNull(location);
338336
}
339337

340338
@Test

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ final String DUMMY_REVISION = "unknown";
7676
* Get the latest revision and redirect so that the revision number
7777
* appears in the URL.
7878
*/
79-
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
80-
if (location != null) {
79+
String latestRevision = cfg.getLatestRevision();
80+
if (latestRevision != null) {
81+
String location = cfg.getRevisionLocation(latestRevision);
8182
response.sendRedirect(location);
8283
return;
8384
}
@@ -88,7 +89,7 @@ final String DUMMY_REVISION = "unknown";
8889
* revision string so that xref can be generated from the resource
8990
* file directly.
9091
*/
91-
location = cfg.getRevisionLocation(DUMMY_REVISION);
92+
String location = cfg.getRevisionLocation(DUMMY_REVISION);
9293
response.sendRedirect(location);
9394
return;
9495
}

0 commit comments

Comments
 (0)