List of usage examples for org.eclipse.jgit.merge MergeChunk getBegin
public int getBegin()
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); }/* w w w. j a v a 2 s .c om*/ 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 ww w . j a v a2 s .co 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 ww.ja v a 2s. c om * <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; }
From source file:org.openflexo.hannah.ConflictingFile.java
License:Open Source License
/** * <p>Constructs string from a {@link MergeChunk}.</p> * @param chunk chunk to construct./*from w w w . j ava 2s . c om*/ * @param text the referenced {@link RawText}. * @return a String. */ private String getChunkString(MergeChunk chunk) { final RawText text = result.getSequences().get(chunk.getSequenceIndex()); final StringBuilder string = new StringBuilder(); for (int i = chunk.getBegin(); i < chunk.getEnd(); i++) { string.append(text.getString(i)); string.append("\n"); } return string.toString(); }