当前位置: 首页>>代码示例>>Java>>正文


Java EditList类代码示例

本文整理汇总了Java中org.eclipse.jgit.diff.EditList的典型用法代码示例。如果您正苦于以下问题:Java EditList类的具体用法?Java EditList怎么用?Java EditList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EditList类属于org.eclipse.jgit.diff包,在下文中一共展示了EditList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatEdits

import org.eclipse.jgit.diff.EditList; //导入依赖的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;
}
 
开发者ID:m4rzEE1,项目名称:ninja_chic-,代码行数:20,代码来源:LineContextDiffer.java

示例2: diff

import org.eclipse.jgit.diff.EditList; //导入依赖的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;
}
 
开发者ID:wumpz,项目名称:java-diff-utils,代码行数:25,代码来源:HistogramDiff.java

示例3: diffWhitespaceLineEndings

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
/**
 * Returns a git-style diff between the two unix strings.
 *
 * Output has no trailing newlines.
 *
 * Boolean args determine whether whitespace or line endings will be visible.
 */
private static String diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException {
	dirty = visibleWhitespaceLineEndings(dirty, whitespace, lineEndings);
	clean = visibleWhitespaceLineEndings(clean, whitespace, lineEndings);

	RawText a = new RawText(dirty.getBytes(StandardCharsets.UTF_8));
	RawText b = new RawText(clean.getBytes(StandardCharsets.UTF_8));
	EditList edits = new EditList();
	edits.addAll(MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT, a, b));

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	try (DiffFormatter formatter = new DiffFormatter(out)) {
		formatter.format(edits, a, b);
	}
	String formatted = out.toString(StandardCharsets.UTF_8.name());

	// we don't need the diff to show this, since we display newlines ourselves
	formatted = formatted.replace("\\ No newline at end of file\n", "");
	return NEWLINE_MATCHER.trimTrailingFrom(formatted);
}
 
开发者ID:diffplug,项目名称:spotless,代码行数:27,代码来源:DiffMessageFormatter.java

示例4: getNewLineGivenOld

import org.eclipse.jgit.diff.EditList; //导入依赖的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);
}
 
开发者ID:mast-group,项目名称:naturalize,代码行数:33,代码来源:ChangingIdentifiersRepositoryWalker.java

示例5: retrieveEditListBetween

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
public List<EditList> retrieveEditListBetween(final RevCommit to,
		final RevCommit from) throws GitAPIException, IOException,
		LargeObjectException, MissingObjectException,
		IncorrectObjectTypeException {
	final List<DiffEntry> diffs = repository.diff()
			.setNewTree(getTreeIterator(to.name()))
			.setOldTree(getTreeIterator(from.name())).call();

	renameDetector.reset();
	renameDetector.addAll(diffs);

	final List<EditList> edits = Lists.newArrayList();
	for (final DiffEntry entry : renameDetector.compute()) {
		if (!editListFileFilter.accept(new File(entry.getNewPath()))
				&& !editListFileFilter.accept(new File(entry.getOldPath()))) {
			continue;
		}

		final EditList el = getEditList(entry);

		edits.add(el);
	}
	return edits;
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:25,代码来源:EditListRetriever.java

示例6: diff

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
private EditList diff(RawText a, RawText b) {
	return diffAlgorithm.diff(comparator, a, b);
}
 
开发者ID:devhub-tud,项目名称:git-server,代码行数:4,代码来源:DiffContextFormatter.java

示例7: createPatchListEntry

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
private static PatchListEntry createPatchListEntry(
    RawTextComparator cmp, RevCommit aCommit, Text aText, Text bText, String fileName) {
  byte[] rawHdr = getRawHeader(aCommit != null, fileName);
  byte[] aContent = aText.getContent();
  byte[] bContent = bText.getContent();
  long size = bContent.length;
  long sizeDelta = bContent.length - aContent.length;
  RawText aRawText = new RawText(aContent);
  RawText bRawText = new RawText(bContent);
  EditList edits = new HistogramDiff().diff(cmp, aRawText, bRawText);
  FileHeader fh = new FileHeader(rawHdr, edits, PatchType.UNIFIED);
  return new PatchListEntry(fh, edits, ImmutableSet.of(), size, sizeDelta);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:PatchListLoader.java

示例8: getChangeChurn

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
/**
 * Get the line change churn for the given edit list.
 *
 * @param editList
 * @return
 */
public static long getChangeChurn(final EditList editList) {
	long lineChurn = 0;
	for (final Edit edit : editList) {
		final int nALines = edit.getEndA() - edit.getBeginA();
		final int nBLines = edit.getEndB() - edit.getBeginB();
		if (nALines > nBLines) {
			lineChurn += nALines;
		} else {
			lineChurn += nBLines;
		}
	}
	return lineChurn;
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:20,代码来源:EditListRetriever.java

示例9: getDiff

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
/**
 * @param currentObj
 * @param parentObj
 * @return
 */
private EditList getDiff(final byte[] currentObj, final byte[] parentObj) {
	final EditList el = MyersDiff.INSTANCE.diff(
			RawTextComparator.WS_IGNORE_ALL,
			parentObj.length > 0 ? new RawText(parentObj)
					: RawText.EMPTY_TEXT,
			currentObj.length > 0 ? new RawText(currentObj)
					: RawText.EMPTY_TEXT);
	return el;
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:15,代码来源:EditListRetriever.java

示例10: getEditList

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
private EditList getEditList(final DiffEntry entry)
		throws LargeObjectException, MissingObjectException,
		IncorrectObjectTypeException, IOException {
	final ObjectId baseOid = entry.getNewId().toObjectId();
	final byte[] currentObj = getBytesForObject(baseOid);

	final ObjectId parentOid = entry.getOldId().toObjectId();
	final byte[] parentObj = getBytesForObject(parentOid);

	if (RawText.isBinary(currentObj) || RawText.isBinary(parentObj)) {
		return new EditList();
	}

	return getDiff(currentObj, parentObj);
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:16,代码来源:EditListRetriever.java

示例11: retrieveEditListBetweenAndCallback

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
/**
 * Retrieve the edit list between the from and the to commit.
 *
 * @param to 
 * @param from the original revision or null to compare from an empty tree
 * @throws GitAPIException
 * @throws IOException
 * @throws LargeObjectException
 * @throws MissingObjectException
 * @throws IncorrectObjectTypeException
 */
public void retrieveEditListBetweenAndCallback(final RevCommit to,
		final RevCommit from, final IEditListCallback callback)
		throws GitAPIException, IOException, LargeObjectException,
		MissingObjectException, IncorrectObjectTypeException {
	final List<DiffEntry> diffs;
	if (from != null) {
		diffs= repository.diff()
			.setNewTree(getTreeIterator(to.name()))
			.setOldTree(getTreeIterator(from.name())).call();
	} else {
		diffs= repository.diff()
				.setNewTree(getTreeIterator(to.name()))
				.setOldTree(new EmptyTreeIterator()).call();
	}
	renameDetector.reset();
	renameDetector.addAll(diffs);

	for (final DiffEntry entry : renameDetector.compute()) {
		try {
			if (!editListFileFilter.accept(new File(entry.getNewPath()))
					&& !editListFileFilter.accept(new File(entry
							.getOldPath()))) {
				continue;
			}

			final EditList el = getEditList(entry);

			callback.visitDiffEntry(entry, el, to);
		} catch (final Throwable t) {
			LOGGER.warning("Failed fully executing callback for DiffEntry because "
					+ ExceptionUtils.getFullStackTrace(t));
		}
	}
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:46,代码来源:EditListRetriever.java

示例12: visitCommitFiles

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
@Override
public void visitCommitFiles(final RevCommit commit) {
	if (!diffs.containsKey(commit.name())) {
		return;
	}

	final List<DiffEdits> edits = diffs.get(commit.name());
	for (final DiffEdits entry : edits) {
		final EditList el = entry.edits;
		for (final Edit edit : el) {
			try {
				if (edit.getType() == Edit.Type.DELETE
						|| edit.getType() == Edit.Type.REPLACE) {
					/*
					 * System.out.println("Trying for " + edit + " at "
					 * + entry.entry.getOldPath() + " at commit " +
					 * commit.name());
					 */
					getBlameForLines(entry.entry.getOldPath(),
							edit.getBeginA(), edit.getEndA(),
							entry.timestamp);
				}
			} catch (final IOException e) {
				System.err.println(e.getMessage());
			}
		}
	}
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:29,代码来源:LineLifecycle.java

示例13: visitDiffEntry

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
@Override
public void visitDiffEntry(final DiffEntry entry, final EditList el,
		final RevCommit commit) throws IOException {

	final String commitId = commit.getParent(0).name(); // Assign edit
														// to the
														// previous
														// commit.
	if (!diffs.containsKey(commitId)) {
		diffs.put(commitId, new ArrayList<DiffEdits>());
	}

	final List<DiffEdits> edits = diffs.get(commitId);
	edits.add(new DiffEdits(entry, el, commit.getCommitTime()));
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:16,代码来源:LineLifecycle.java

示例14: getEditedRegions

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
@Override
public List<EditedRegion> getEditedRegions(String filePath) throws GitException {
  try (ObjectReader reader = repository.newObjectReader();
      RevWalk revWalk = new RevWalk(repository);
      DiffFormatter formatter = new DiffFormatter(DisabledOutputStream.INSTANCE)) {
    formatter.setRepository(repository);
    formatter.setPathFilter(PathFilter.create(filePath));

    Ref headRef = repository.exactRef(HEAD);
    RevCommit commit = revWalk.parseCommit(headRef.getObjectId());
    RevTree tree = revWalk.parseTree(commit.getTree().getId());
    CanonicalTreeParser treeParser = new CanonicalTreeParser();
    treeParser.reset(reader, tree);

    Optional<DiffEntry> optional =
        formatter.scan(treeParser, new FileTreeIterator(repository)).stream().findAny();
    if (optional.isPresent()) {
      EditList edits = formatter.toFileHeader(optional.get()).getHunks().get(0).toEditList();
      return edits
          .stream()
          .map(
              edit -> {
                EditedRegionType type = null;
                switch (edit.getType()) {
                  case INSERT:
                    {
                      type = INSERTION;
                      break;
                    }
                  case REPLACE:
                    {
                      type = MODIFICATION;
                      break;
                    }
                  case DELETE:
                    {
                      type = DELETION;
                      break;
                    }
                  case EMPTY:
                    {
                      break;
                    }
                }
                return newDto(EditedRegion.class)
                    .withBeginLine(
                        edit.getType() == DELETE ? edit.getBeginB() : edit.getBeginB() + 1)
                    .withEndLine(edit.getEndB())
                    .withType(type);
              })
          .collect(toList());
    }
  } catch (Exception e) {
    throw new GitException(e.getMessage());
  }
  return Collections.emptyList();
}
 
开发者ID:eclipse,项目名称:che,代码行数:58,代码来源:JGitConnection.java

示例15: wordEdit

import org.eclipse.jgit.diff.EditList; //导入依赖的package包/类
private static List<Edit> wordEdit(int as, int ae, int bs, int be) {
  return EditList.singleton(new Edit(as, ae, bs, be));
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:4,代码来源:IntraLineLoaderTest.java


注:本文中的org.eclipse.jgit.diff.EditList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。