Example usage for org.eclipse.jgit.merge MergeChunk getConflictState

List of usage examples for org.eclipse.jgit.merge MergeChunk getConflictState

Introduction

In this page you can find the example usage for org.eclipse.jgit.merge MergeChunk getConflictState.

Prototype

public ConflictState getConflictState() 

Source Link

Document

Get the state of this chunk.

Usage

From source file:com.google.collide.server.shared.merge.JGitMerger.java

License:Open Source License

public static MergeResult formatMerge(org.eclipse.jgit.merge.MergeResult<RawText> results) {
    int runningIndex = 0;
    int numLines = 0;
    List<MergeChunk> mergeChunks = Lists.newArrayList();
    MergeChunk currentMergeChunk = null;
    StringBuilder fileContent = new StringBuilder();
    int conflictIndex = 0;
    for (org.eclipse.jgit.merge.MergeChunk chunk : results) {
        RawText seq = results.getSequences().get(chunk.getSequenceIndex());
        String chunkContent = seq.getString(chunk.getBegin(), chunk.getEnd(), false);

        if (chunk.getConflictState() == ConflictState.NO_CONFLICT
                || chunk.getConflictState() == ConflictState.FIRST_CONFLICTING_RANGE) {
            if (currentMergeChunk != null) {
                mergeChunks.add(currentMergeChunk);
            }/*from w  w w .jav  a  2 s  .  co  m*/
            currentMergeChunk = new MergeChunk();
        }

        switch (chunk.getConflictState()) {
        case NO_CONFLICT:
            currentMergeChunk.setHasConflict(false);
            currentMergeChunk.setMergedData(chunkContent);
            fileContent.append(chunkContent);
            numLines = chunk.getEnd() - chunk.getBegin();
            runningIndex = setRanges(currentMergeChunk, runningIndex, numLines);
            break;
        case FIRST_CONFLICTING_RANGE:
            currentMergeChunk.setHasConflict(true);
            currentMergeChunk.setChildData(chunkContent);
            fileContent.append(chunkContent);
            numLines = chunk.getEnd() - chunk.getBegin();
            runningIndex = setRanges(currentMergeChunk, runningIndex, numLines);
            break;
        case NEXT_CONFLICTING_RANGE:
            currentMergeChunk.setParentData(chunkContent);
            break;
        }
    }
    mergeChunks.add(currentMergeChunk);

    MergeResult mergeResult = new MergeResult(mergeChunks, (conflictIndex > 0) ? "" : fileContent.toString());

    return mergeResult;
}

From source file:org.openflexo.hannah.ConflictingFile.java

License:Open Source License

/**
 * <p>Computes the {@link Conflict} for given file using result.</p>
 *//*from  w  w  w  .  ja  va 2s . c  o  m*/
private List<Conflict> computeConflicts() {
    final List<Conflict> conflicts = new ArrayList<Conflict>();

    MergeChunk userChunk = null;
    for (MergeChunk chunk : result) {

        switch (chunk.getConflictState()) {
        case FIRST_CONFLICTING_RANGE:
            userChunk = chunk;
            break;

        case NEXT_CONFLICTING_RANGE:
            assert userChunk != null;

            final String user = getChunkString(userChunk);
            final String generation = getChunkString(chunk);
            final Conflict conflict = new Conflict(userChunk.getBegin(), userChunk.getEnd(), user,
                    chunk.getBegin(), chunk.getEnd(), generation);
            conflicts.add(conflict);

            // resets user
            userChunk = null;
            break;
        }
    }

    assert userChunk == null;

    return conflicts;
}

From source file:org.openflexo.hannah.ConflictingFile.java

License:Open Source License

/**
 * <p>Returns true if chunk should be printed. A chunk is printed when:
 * <ul>/* w w w . ja v a2  s . c  o m*/
 * <li>the chunk is not conflicting.</li>
 * <li>the chunk is conflicting and the corresponding {@link Conflict} 
 * resolution corresponds to it's side (USER or GENERATION).</li>
 * </ul>
 * </p>
 * @param chunk chunk to test.
 * @return true if needs to be printed.
 */
private boolean print(MergeChunk chunk) {
    switch (chunk.getConflictState()) {
    case FIRST_CONFLICTING_RANGE:
        for (Conflict conflict : conflicts) {
            if (conflict.getUserBegin() == chunk.getBegin() && conflict.getUserEnd() == chunk.getEnd()) {
                return conflict.getResolution() == Resolution.USER;
            }
        }
        return false;

    case NEXT_CONFLICTING_RANGE:
        for (Conflict conflict : conflicts) {
            if (conflict.getGenerationBegin() == chunk.getBegin()
                    && conflict.getGenerationEnd() == chunk.getEnd()) {
                return conflict.getResolution() == Resolution.GENERATION;
            }
        }
        return false;

    }
    return true;
}