Skip to content
Snippets Groups Projects
Commit 49a39a28 authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

improve robustness of LocalRepository#blameUnmergedFile #3

parent 18d93436
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,10 @@ import java.util.stream.Collectors;
import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.ExecRes;
import org.apache.commons.io.FileUtils;
import static de.uni_passau.fim.seibt.gitwrapper.repo.LocalRepository.ConflictMarker.CONFLICT_END;
import static de.uni_passau.fim.seibt.gitwrapper.repo.LocalRepository.ConflictMarker.CONFLICT_MIDDLE;
import static de.uni_passau.fim.seibt.gitwrapper.repo.LocalRepository.ConflictMarker.CONFLICT_START;
/**
* A git {@link Repository}.
*/
......@@ -46,9 +50,24 @@ public class LocalRepository extends Repository {
// The type returned for commits by 'git cat-file -t".
private static final String TYPE_COMMIT = "commit";
private static final String CONFLICT_START = "<<<<<<<";
private static final String CONFLICT_MIDDLE = "=======";
private static final String CONFLICT_END = ">>>>>>>";
/**
* An enumeration of the three possible conflict markers in an unmerged file.
*/
enum ConflictMarker {
CONFLICT_START("<<<<<<<"),
CONFLICT_MIDDLE("======="),
CONFLICT_END(">>>>>>>");
/**
* The expected characters at the beginning of a line representing a
* conflict marker.
*/
public final String prefix;
ConflictMarker(String prefix) {
this.prefix = prefix;
}
}
// The prefixes of the full symbolic names of (remote) branches.
private static final String FULL_SYMBOLIC_BRANCH = "refs/heads/";
......@@ -472,22 +491,22 @@ public class LocalRepository extends Repository {
List<BlameLine> left = null;
List<BlameLine> right = null;
String lastMarker = null;
ConflictMarker lastMarker = null;
for (BlameLine line : blame.get()) {
if (line.line.startsWith(CONFLICT_START)) {
if (line.line.startsWith(CONFLICT_START.prefix)) {
left = new ArrayList<>();
right = new ArrayList<>();
lastMarker = CONFLICT_START;
} else if (line.line.startsWith(CONFLICT_MIDDLE)) {
} else if (lastMarker == CONFLICT_START && line.line.startsWith(CONFLICT_MIDDLE.prefix)) {
lastMarker = CONFLICT_MIDDLE;
} else if (line.line.startsWith(CONFLICT_END)) {
} else if (lastMarker == CONFLICT_MIDDLE && line.line.startsWith(CONFLICT_END.prefix)) {
conflicts.add(new MergeConflict(left, right));
lastMarker = CONFLICT_END;
} else if (CONFLICT_START.equals(lastMarker)) {
assert left != null; left.add(line);
} else if (CONFLICT_MIDDLE.equals(lastMarker)) {
assert right != null; right.add(line);
} else if (CONFLICT_START == lastMarker) {
left.add(line);
} else if (CONFLICT_MIDDLE == lastMarker) {
right.add(line);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment