From c468cd513b44eb496498818d1e2ce11fda91c25d Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Thu, 24 Nov 2016 04:48:36 +0300 Subject: [PATCH] [git] simplify lines processing (cherry picked from commit 0426492) --- .../src/git4idea/history/GitHistoryUtils.java | 84 +++++++++---------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java index 68320224cbdb..1b8fbace07ef 100644 --- a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java +++ b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java @@ -1014,7 +1014,7 @@ public class GitHistoryUtils { @Nullable private VcsException myException = null; private int myRecords = 0; - private boolean myFoundRecordEnd = false; + private boolean myIsInsideBody = true; public MyGitLineHandlerListener(@NotNull GitLineHandler handler, @NotNull Consumer recordConsumer, @@ -1033,49 +1033,7 @@ public class GitHistoryUtils { } else if (outputType == ProcessOutputTypes.STDOUT) { try { - // format of the record is .*.* - // then next record goes - // (rather inconveniently, after RECORD_END there is a list of modified files) - // so here I'm trying to find text between two RECORD_START symbols - // that simultaneously contains a RECORD_END - // this helps to deal with commits like a929478f6720ac15d949117188cd6798b4a9c286 in linux repo that have RECORD_START symbols in the message - // wont help with RECORD_END symbols in the message however (have not seen those yet) - - String tail = null; - if (!myFoundRecordEnd) { - int recordEnd = line.indexOf(GitLogParser.RECORD_END); - if (recordEnd != -1) { - myFoundRecordEnd = true; - myOutput.append(line.substring(0, recordEnd + 1)); - line = line.substring(recordEnd + 1); - } - else { - myOutput.append(line).append("\n"); - } - } - - if (myFoundRecordEnd) { - int nextRecordStart = line.indexOf(GitLogParser.RECORD_START); - if (nextRecordStart == -1) { - myOutput.append(line).append("\n"); - } - else if (nextRecordStart == 0) { - tail = line + "\n"; - } - else { - myOutput.append(line.substring(0, nextRecordStart)); - tail = line.substring(nextRecordStart) + "\n"; - } - } - - if (tail != null) { - if (++myRecords > myBufferSize) { - myRecordConsumer.consume(myOutput); - myOutput.setLength(0); - } - myOutput.append(tail); - myFoundRecordEnd = tail.contains(GitLogParser.RECORD_END); - } + processOutputLine(line); } catch (Exception e) { myException = new VcsException(e); @@ -1083,6 +1041,44 @@ public class GitHistoryUtils { } } + private void processOutputLine(@NotNull String line) { + // format of the record is + // then next record goes + // (rather inconveniently, after RECORD_END there is a list of modified files) + // so here I'm trying to find text between two RECORD_START symbols + // that simultaneously contains a RECORD_END + // this helps to deal with commits like a929478f6720ac15d949117188cd6798b4a9c286 in linux repo that have RECORD_START symbols in the message + // wont help with RECORD_END symbols in the message however (have not seen those yet) + + if (myIsInsideBody) { + // find body + int bodyEnd = line.indexOf(GitLogParser.RECORD_END); + if (bodyEnd >= 0) { + myIsInsideBody = false; + myOutput.append(line.substring(0, bodyEnd + 1)); + processOutputLine(line.substring(bodyEnd + 1)); + } + else { + myOutput.append(line).append("\n"); + } + } + else { + int nextRecordStart = line.indexOf(GitLogParser.RECORD_START); + if (nextRecordStart >= 0) { + myOutput.append(line.substring(0, nextRecordStart)); + if (++myRecords > myBufferSize) { + myRecordConsumer.consume(myOutput); + myOutput.setLength(0); + } + myIsInsideBody = true; + processOutputLine(line.substring(nextRecordStart)); + } + else { + myOutput.append(line).append("\n"); + } + } + } + @Override public void processTerminated(int exitCode) { if (exitCode != 0) {