mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git: simplify the rebase line listener: used only for progress now
It fixes IDEA-194024 which was introduced by 116c1b6: when editor is cancelled, Git produces an error messages (which made the Status to be ERROR), but it is not a fatal error, and it is followed by a message about "stopped for editing". Receiving two status messages was unexpected by the GitRebaseLineListener.
This commit is contained in:
@@ -26,60 +26,18 @@ import java.util.regex.Pattern;
|
||||
* This listener gathers information relevant to the progress of the rebase operation
|
||||
*/
|
||||
public class GitRebaseLineListener extends GitLineHandlerAdapter {
|
||||
/**
|
||||
* Git rebase progress message
|
||||
*/
|
||||
private static final Pattern PROGRESS = Pattern.compile("^Rebasing \\((\\d+)/(\\d+)\\)$");
|
||||
/**
|
||||
* The status
|
||||
*/
|
||||
private Status myStatus;
|
||||
/**
|
||||
* The progress line
|
||||
*/
|
||||
private String myProgressLine;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void onLineAvailable(String line, Key outputType) {
|
||||
if (outputType == ProcessOutputTypes.STDOUT) {
|
||||
if (PROGRESS.matcher(line).matches()) {
|
||||
myProgressLine = line;
|
||||
// a bit dodgy line since STDERR line could arrive before STDOUT line,
|
||||
// but in practice STDOUT comes first.
|
||||
myStatus = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (line.startsWith("You can amend the commit now")) {
|
||||
assert myStatus == null;
|
||||
myStatus = Status.EDIT;
|
||||
}
|
||||
else if (line.startsWith("Successfully rebased and updated")) {
|
||||
assert myStatus == null;
|
||||
myStatus = Status.FINISHED;
|
||||
}
|
||||
else if (line.startsWith("Automatic cherry-pick failed") || line.startsWith("When you have resolved this problem")) {
|
||||
assert myStatus == null || myStatus == Status.ERROR;
|
||||
myStatus = Status.CONFLICT;
|
||||
}
|
||||
else if (line.startsWith("Could not execute editor")) {
|
||||
assert myStatus == null;
|
||||
myStatus = myProgressLine == null ? Status.CANCELLED : Status.ERROR;
|
||||
}
|
||||
else if (line.startsWith("fatal") || line.startsWith("error: ") || line.startsWith("Cannot")) {
|
||||
if (myStatus != Status.CONFLICT) {
|
||||
myStatus = Status.ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the progress values as a pair
|
||||
*/
|
||||
public synchronized Result getResult() {
|
||||
int total;
|
||||
int current;
|
||||
@@ -97,17 +55,10 @@ public class GitRebaseLineListener extends GitLineHandlerAdapter {
|
||||
else {
|
||||
total = current = 0;
|
||||
}
|
||||
return new Result(myStatus == null ? Status.FINISHED : myStatus, total, current);
|
||||
return new Result(total, current);
|
||||
}
|
||||
|
||||
/**
|
||||
* The result of operation
|
||||
*/
|
||||
public static final class Result {
|
||||
/**
|
||||
* The operation status
|
||||
*/
|
||||
public final Status status;
|
||||
/**
|
||||
* The total number of commits
|
||||
*/
|
||||
@@ -117,43 +68,9 @@ public class GitRebaseLineListener extends GitLineHandlerAdapter {
|
||||
*/
|
||||
public final int current;
|
||||
|
||||
/**
|
||||
* A constructor
|
||||
*
|
||||
* @param status the status
|
||||
* @param total the commit count
|
||||
* @param current the current commit
|
||||
*/
|
||||
public Result(Status status, int total, int current) {
|
||||
this.status = status;
|
||||
public Result(int total, int current) {
|
||||
this.total = total;
|
||||
this.current = current;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The current rebase status
|
||||
*/
|
||||
public enum Status {
|
||||
/**
|
||||
* Rebase operation is cancelled (could not execute editor)
|
||||
*/
|
||||
CANCELLED,
|
||||
/**
|
||||
* Rebase is finished
|
||||
*/
|
||||
FINISHED,
|
||||
/**
|
||||
* Suspended for edit
|
||||
*/
|
||||
EDIT,
|
||||
/**
|
||||
* Suspended due to the conflict
|
||||
*/
|
||||
CONFLICT,
|
||||
/**
|
||||
* Suspended due to the error
|
||||
*/
|
||||
ERROR
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user