本文整理汇总了Java中org.eclipse.jgit.diff.Edit类的典型用法代码示例。如果您正苦于以下问题:Java Edit类的具体用法?Java Edit怎么用?Java Edit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Edit类属于org.eclipse.jgit.diff包,在下文中一共展示了Edit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatEdits
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
public List<Hunk> formatEdits(final RawText a, final RawText b, final EditList edits) throws IOException {
List<Hunk> hunks = newArrayList();
for (int curIdx = 0; curIdx < edits.size(); ) {
Edit curEdit = edits.get(curIdx);
final int endIdx = findCombinedEnd(edits, curIdx);
// Log.i("BUCK", "Will do edits "+curIdx+" - "+endIdx);
final Edit endEdit = edits.get(endIdx);
int aCur = max(0, curEdit.getBeginA() - context);
int bCur = max(0, curEdit.getBeginB() - context);
final int aEnd = min(a.size(), endEdit.getEndA() + context);
final int bEnd = min(b.size(), endEdit.getEndB() + context);
String before = extractHunk(a, aCur, aEnd), after = extractHunk(b, bCur, bEnd);
hunks.add(new Hunk(before, after));
curIdx = endIdx + 1;
}
return hunks;
}
示例2: diff
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
@Override
public List<Change> diff(List<T> original, List<T> revised) throws DiffException {
Objects.requireNonNull(original, "original list must not be null");
Objects.requireNonNull(revised, "revised list must not be null");
EditList diffList = new EditList();
diffList.addAll(new org.eclipse.jgit.diff.HistogramDiff().diff(new DataListComparator<>(), new DataList<>(original), new DataList<>(revised)));
List<Change> patch = new ArrayList<>();
for (Edit edit : diffList) {
DeltaType type = DeltaType.EQUAL;
switch (edit.getType()) {
case DELETE:
type = DeltaType.DELETE;
break;
case INSERT:
type = DeltaType.INSERT;
break;
case REPLACE:
type = DeltaType.CHANGE;
break;
}
patch.add(new Change(type, edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB()));
}
return patch;
}
示例3: PatchListEntry
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private PatchListEntry(
ChangeType changeType,
PatchType patchType,
String oldName,
String newName,
byte[] header,
ImmutableList<Edit> edits,
ImmutableSet<Edit> editsDueToRebase,
int insertions,
int deletions,
long size,
long sizeDelta) {
this.changeType = changeType;
this.patchType = patchType;
this.oldName = oldName;
this.newName = newName;
this.header = header;
this.edits = edits;
this.editsDueToRebase = editsDueToRebase;
this.insertions = insertions;
this.deletions = deletions;
this.size = size;
this.sizeDelta = sizeDelta;
}
示例4: writeObject
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private void writeObject(ObjectOutputStream out) throws IOException {
writeEnum(out, status);
writeVarInt32(out, edits.size());
for (Edit e : edits) {
writeEdit(out, e);
if (e instanceof ReplaceEdit) {
ReplaceEdit r = (ReplaceEdit) e;
writeVarInt32(out, r.getInternalEdits().size());
for (Edit i : r.getInternalEdits()) {
writeEdit(out, i);
}
} else {
writeVarInt32(out, 0);
}
}
}
示例5: readObject
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private void readObject(ObjectInputStream in) throws IOException {
status = readEnum(in, Status.values());
int editCount = readVarInt32(in);
Edit[] editArray = new Edit[editCount];
for (int i = 0; i < editCount; i++) {
editArray[i] = readEdit(in);
int innerCount = readVarInt32(in);
if (0 < innerCount) {
Edit[] inner = new Edit[innerCount];
for (int j = 0; j < innerCount; j++) {
inner[j] = readEdit(in);
}
editArray[i] = new ReplaceEdit(editArray[i], toList(inner));
}
}
edits = ImmutableList.copyOf(editArray);
}
示例6: mapA2B
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private int mapA2B(int a) {
if (edits.isEmpty()) {
// Magic special case of an unmodified file.
//
return a;
}
for (int i = 0; i < edits.size(); i++) {
final Edit e = edits.get(i);
if (a < e.getBeginA()) {
if (i == 0) {
// Special case of context at start of file.
//
return a;
}
return e.getBeginB() - (e.getBeginA() - a);
}
if (e.getBeginA() <= a && a <= e.getEndA()) {
return -1;
}
}
final Edit last = edits.get(edits.size() - 1);
return last.getEndB() + (a - last.getEndA());
}
示例7: mapB2A
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private int mapB2A(int b) {
if (edits.isEmpty()) {
// Magic special case of an unmodified file.
//
return b;
}
for (int i = 0; i < edits.size(); i++) {
final Edit e = edits.get(i);
if (b < e.getBeginB()) {
if (i == 0) {
// Special case of context at start of file.
//
return b;
}
return e.getBeginA() - (e.getBeginB() - b);
}
if (e.getBeginB() <= b && b <= e.getEndB()) {
return -1;
}
}
final Edit last = edits.get(edits.size() - 1);
return last.getEndA() + (b - last.getEndB());
}
示例8: getPatchListEntry
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private Optional<PatchListEntry> getPatchListEntry(
ObjectReader objectReader,
DiffFormatter diffFormatter,
DiffEntry diffEntry,
RevTree treeA,
RevTree treeB,
Set<ContextAwareEdit> editsDueToRebase)
throws IOException {
FileHeader fileHeader = toFileHeader(key.getNewId(), diffFormatter, diffEntry);
long oldSize = getFileSize(objectReader, diffEntry.getOldMode(), diffEntry.getOldPath(), treeA);
long newSize = getFileSize(objectReader, diffEntry.getNewMode(), diffEntry.getNewPath(), treeB);
Set<Edit> contentEditsDueToRebase = getContentEdits(editsDueToRebase);
PatchListEntry patchListEntry =
newEntry(treeA, fileHeader, contentEditsDueToRebase, newSize, newSize - oldSize);
// All edits in a file are due to rebase -> exclude the file from the diff.
if (EditTransformer.toEdits(patchListEntry).allMatch(editsDueToRebase::contains)) {
return Optional.empty();
}
return Optional.of(patchListEntry);
}
示例9: harmfulMutationsOfEditsAreNotPossibleForIntraLineDiffArgsAndCachedValue
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
@Test
public void harmfulMutationsOfEditsAreNotPossibleForIntraLineDiffArgsAndCachedValue()
throws Exception {
String a = "First line\nSecond line\n";
String b = "1st line\n2nd line\n";
Text aText = new Text(a.getBytes(UTF_8));
Text bText = new Text(b.getBytes(UTF_8));
Edit inputEdit = new Edit(0, 2, 0, 2);
List<Edit> inputEdits = new ArrayList<>(ImmutableList.of(inputEdit));
IntraLineDiffKey diffKey =
IntraLineDiffKey.create(ObjectId.zeroId(), ObjectId.zeroId(), Whitespace.IGNORE_NONE);
IntraLineDiffArgs diffArgs =
IntraLineDiffArgs.create(aText, bText, inputEdits, project, ObjectId.zeroId(), "file.txt");
IntraLineDiff intraLineDiff = patchListCache.getIntraLineDiff(diffKey, diffArgs);
Edit outputEdit = Iterables.getOnlyElement(intraLineDiff.getEdits());
outputEdit.shift(5);
inputEdit.shift(7);
inputEdits.add(new Edit(43, 47, 50, 51));
Edit originalEdit = new Edit(0, 2, 0, 2);
assertThat(diffArgs.edits()).containsExactly(originalEdit);
assertThat(intraLineDiff.getEdits()).containsExactly(originalEdit);
}
示例10: intraline
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private static List<Edit> intraline(String a, String b, Edit lines) throws Exception {
Text aText = new Text(a.getBytes(UTF_8));
Text bText = new Text(b.getBytes(UTF_8));
IntraLineDiff diff = IntraLineLoader.compute(aText, bText, ImmutableList.of(lines));
assertThat(diff.getStatus()).isEqualTo(IntraLineDiff.Status.EDIT_LIST);
List<Edit> actualEdits = diff.getEdits();
assertThat(actualEdits).hasSize(1);
Edit actualEdit = actualEdits.get(0);
assertThat(actualEdit.getBeginA()).isEqualTo(lines.getBeginA());
assertThat(actualEdit.getEndA()).isEqualTo(lines.getEndA());
assertThat(actualEdit.getBeginB()).isEqualTo(lines.getBeginB());
assertThat(actualEdit.getEndB()).isEqualTo(lines.getEndB());
assertThat(actualEdit).isInstanceOf(ReplaceEdit.class);
return ((ReplaceEdit) actualEdit).getInternalEdits();
}
示例11: getNewLineGivenOld
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
/**
* Return a range of the possible line positions of the old line number in
* the new file.
*
* @param declarationLineNumber
* @param editList
* @return
*/
private Range<Integer> getNewLineGivenOld(final int oldLineNumber,
final EditList editList) {
int offsetAbove = 0;
for (final Edit edit : editList) {
if (edit.getBeginA() < oldLineNumber
&& edit.getEndA() < oldLineNumber) {
offsetAbove += -(edit.getEndA() - edit.getBeginA())
+ (edit.getEndB() - edit.getBeginB());
} else if (edit.getBeginA() <= oldLineNumber
&& edit.getEndA() >= oldLineNumber) {
// if it was in the old range, it is now in the new range
checkArgument(
edit.getBeginA() + offsetAbove == edit.getBeginB(),
"Beggining was %s but expected %s", edit.getBeginB(),
edit.getBeginA() + offsetAbove);
return Range.closed(edit.getBeginB(), edit.getEndB());
} else {
return Range.closed(oldLineNumber + offsetAbove, oldLineNumber
+ offsetAbove);
}
}
return Range.closed(oldLineNumber + offsetAbove, oldLineNumber
+ offsetAbove);
}
示例12: getReviewersFromBlame
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
/**
* Fill a map of all the possible reviewers based on the provided blame data
*
* @param edits List of edits that were made for this patch
* @param blameResult Result of blame computation
* @param reviewers the reviewer hash table to fill
*/
private void getReviewersFromBlame(final List<Edit> edits,
final BlameResult blameResult, Map<Account, Integer> reviewers) {
for (Edit edit : edits) {
for (int i = edit.getBeginA(); i < edit.getEndA(); i++) {
RevCommit commit = blameResult.getSourceCommit(i);
Set<Account.Id> ids =
byEmailCache.get(commit.getAuthorIdent().getEmailAddress());
for (Account.Id id : ids) {
Account account = accountCache.get(id).getAccount();
addAccount(account, reviewers, weightBlame);
}
}
}
}
示例13: combineLineEdits
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private static void combineLineEdits(List<Edit> edits, Text a, Text b) {
for (int j = 0; j < edits.size() - 1; ) {
Edit c = edits.get(j);
Edit n = edits.get(j + 1);
// Combine edits that are really close together. Right now our rule
// is, coalesce two line edits which are only one line apart if that
// common context line is either a "pointless line", or is identical
// on both sides and starts a new block of code. These are mostly
// block reindents to add or remove control flow operators.
//
final int ad = n.getBeginA() - c.getEndA();
final int bd = n.getBeginB() - c.getEndB();
if ((1 <= ad && isBlankLineGap(a, c.getEndA(), n.getBeginA()))
|| (1 <= bd && isBlankLineGap(b, c.getEndB(), n.getBeginB()))
|| (ad == 1 && bd == 1 && isControlBlockStart(a, c.getEndA()))) {
int ab = c.getBeginA();
int ae = n.getEndA();
int bb = c.getBeginB();
int be = n.getEndB();
edits.set(j, new Edit(ab, ae, bb, be));
edits.remove(j + 1);
continue;
}
j++;
}
}
示例14: toEdits
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
public static Stream<ContextAwareEdit> toEdits(PatchListEntry patchListEntry) {
ImmutableList<Edit> edits = patchListEntry.getEdits();
if (edits.isEmpty()) {
return Stream.of(ContextAwareEdit.createForNoContentEdit(patchListEntry));
}
return edits.stream().map(edit -> ContextAwareEdit.create(patchListEntry, edit));
}
示例15: transformEdits
import org.eclipse.jgit.diff.Edit; //导入依赖的package包/类
private static List<ContextAwareEdit> transformEdits(
SideStrategy sideStrategy,
List<ContextAwareEdit> unorderedOriginalEdits,
List<Edit> unorderedTransformingEdits,
String adjustedFilePath) {
List<ContextAwareEdit> originalEdits = new ArrayList<>(unorderedOriginalEdits);
originalEdits.sort(comparing(sideStrategy::getBegin).thenComparing(sideStrategy::getEnd));
List<Edit> transformingEdits = new ArrayList<>(unorderedTransformingEdits);
transformingEdits.sort(comparing(Edit::getBeginA).thenComparing(Edit::getEndA));
int shiftedAmount = 0;
int transIndex = 0;
int origIndex = 0;
List<ContextAwareEdit> resultingEdits = new ArrayList<>(originalEdits.size());
while (origIndex < originalEdits.size() && transIndex < transformingEdits.size()) {
ContextAwareEdit originalEdit = originalEdits.get(origIndex);
Edit transformingEdit = transformingEdits.get(transIndex);
if (transformingEdit.getEndA() < sideStrategy.getBegin(originalEdit)) {
shiftedAmount = transformingEdit.getEndB() - transformingEdit.getEndA();
transIndex++;
} else if (sideStrategy.getEnd(originalEdit) < transformingEdit.getBeginA()) {
resultingEdits.add(sideStrategy.create(originalEdit, shiftedAmount, adjustedFilePath));
origIndex++;
} else {
// Overlapping -> ignore.
origIndex++;
}
}
for (int i = origIndex; i < originalEdits.size(); i++) {
resultingEdits.add(
sideStrategy.create(originalEdits.get(i), shiftedAmount, adjustedFilePath));
}
return resultingEdits;
}