Skip to content

Commit 5d55b5f

Browse files
authored
unify file quoting in SCCS/Mercurial (#4565)
1 parent 261ac2c commit 5d55b5f

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

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

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

2020
/*
21-
* Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -81,13 +81,12 @@ void parse(File file, String sinceRevision, String tillRevision, Integer numComm
8181
Executor executor = repository.getHistoryLogExecutor(file, sinceRevision, tillRevision, false,
8282
numCommits);
8383
int status = executor.exec(true, this);
84-
8584
if (status != 0) {
86-
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() +
87-
"\" Exit code: " + status);
85+
throw new HistoryException(String.format("Failed to get history for '%s' (exit status %d)",
86+
file.getAbsolutePath(), status));
8887
}
8988
} catch (IOException e) {
90-
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
89+
throw new HistoryException(String.format("Failed to get history for '%s'", file.getAbsolutePath()), e);
9190
}
9291

9392
// If a changeset to start from is specified, remove that changeset from the list,
@@ -151,7 +150,7 @@ private void removeChangesets(List<RepositoryWithHistoryTraversal.ChangesetInfo>
151150
* {@link org.opengrok.indexer.history.RepositoryWithHistoryTraversal.ChangesetInfo} elements.
152151
*
153152
* @param input The output from the process
154-
* @throws java.io.IOException If an error occurs while reading the stream
153+
* @throws IOException If an error occurs while reading the stream
155154
*/
156155
@Override
157156
public void processStream(InputStream input) throws IOException {
@@ -182,7 +181,7 @@ public void processStream(InputStream input) throws IOException {
182181
} else if (s.startsWith(MercurialRepository.FILES) && entry != null) {
183182
String[] strings = s.split(" ");
184183
for (int ii = 1; ii < strings.length; ++ii) {
185-
if (strings[ii].length() > 0) {
184+
if (!strings[ii].isEmpty()) {
186185
File f = new File(mydir, strings[ii]);
187186
try {
188187
String path = env.getPathRelativeToSourceRoot(f);
@@ -221,7 +220,7 @@ public void processStream(InputStream input) throws IOException {
221220
} else if (s.equals(MercurialRepository.END_OF_ENTRY)
222221
&& entry != null) {
223222
entry = null;
224-
} else if (s.length() > 0) {
223+
} else if (!s.isEmpty()) {
225224
LOGGER.log(Level.WARNING,
226225
"Invalid/unexpected output {0} from hg log for repo {1}",
227226
new Object[]{s, repository.getDirectoryName()});
@@ -235,10 +234,10 @@ public void processStream(InputStream input) throws IOException {
235234
* This is to prevent problems if the log message contains one of the
236235
* prefixes that {@link #processStream(InputStream)} is looking for (bug
237236
* #405).
238-
*
237+
* <p>
239238
* This method is way too tolerant, and won't complain if the line has
240239
* a different format than expected. It will return weird results, though.
241-
*
240+
* </p>
242241
* @param line the XML encoded line
243242
* @return the decoded description
244243
*/

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

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

2020
/*
21-
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.history;
2424

@@ -68,14 +68,13 @@ History parse(File file) throws HistoryException {
6868
try {
6969
return parseFile(file);
7070
} catch (IOException e) {
71-
throw new HistoryException("Failed to get history for " +
72-
"\"" + file.getAbsolutePath() + "\":", e);
71+
throw new HistoryException(String.format("Failed to get history for '%s'", file.getAbsolutePath()), e);
7372
} catch (ParseException e) {
74-
throw new HistoryException("Failed to parse history for " +
75-
"\"" + file.getAbsolutePath() + "\":", e);
73+
throw new HistoryException(String.format("Failed to parse history for '%s'", file.getAbsolutePath()), e);
7674
}
7775
}
7876

77+
@Nullable
7978
private History parseFile(File file) throws IOException, ParseException {
8079
File f = getSCCSFile(file);
8180
if (f == null) {
@@ -110,9 +109,9 @@ private History parseFile(File file) throws IOException, ParseException {
110109
* Read a single line of delta record into the {@link #sccsRecord} member.
111110
*
112111
* @return boolean indicating whether there is another record.
113-
* @throws java.io.IOException on I/O error
112+
* @throws IOException on I/O error
114113
*/
115-
private boolean next() throws java.io.IOException {
114+
private boolean next() throws IOException {
116115
sep = true;
117116
sccsRecord.setLength(0);
118117
int c;
@@ -189,7 +188,7 @@ private boolean isActive() {
189188
return active;
190189
}
191190

192-
private int read() throws java.io.IOException {
191+
private int read() throws IOException {
193192
int c, d, dt;
194193
while ((c = in.read()) != -1) {
195194
switch (c) { //NOPMD

0 commit comments

Comments
 (0)