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


Java RawText类代码示例

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


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

示例1: formatEdits

import org.eclipse.jgit.diff.RawText; //导入依赖的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: blame

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
/**
 * Returns the list of lines in the specified source file annotated with the source commit metadata.
 * 
 * @param repository
 * @param blobPath
 * @param objectId
 * @return list of annotated lines
 */
public static List<AnnotatedLine> blame(Repository repository, String blobPath, String objectId) {
	List<AnnotatedLine> lines = new ArrayList<AnnotatedLine>();
	try {
		ObjectId object;
		if (StringUtils.isEmpty(objectId)) {
			object = JGitUtils.getDefaultBranch(repository);
		} else {
			object = repository.resolve(objectId);
		}
		BlameCommand blameCommand = new BlameCommand(repository);
		blameCommand.setFilePath(blobPath);
		blameCommand.setStartCommit(object);
		BlameResult blameResult = blameCommand.call();
		RawText rawText = blameResult.getResultContents();
		int length = rawText.size();
		for (int i = 0; i < length; i++) {
			RevCommit commit = blameResult.getSourceCommit(i);
			AnnotatedLine line = new AnnotatedLine(commit, i + 1, rawText.getString(i));
			lines.add(line);
		}
	} catch (Throwable t) {
		LOGGER.error(MessageFormat.format("failed to generate blame for {0} {1}!", blobPath, objectId), t);
	}
	return lines;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:34,代码来源:DiffUtils.java

示例3: diffWhitespaceLineEndings

import org.eclipse.jgit.diff.RawText; //导入依赖的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: format

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
/**
 * Format a patch script for one file entry.
 *
 * @param ent the entry to be formatted.
 * @throws IOException a file's content cannot be read, or the output stream cannot
 *                     be written to.
 */
public List<Hunk> format(DiffEntry ent) throws IOException {
    //writeDiffHeader(out, ent);

    if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK) {
        // writeGitLinkDiffText(out, ent);
        return emptyList();
    } else {
        byte[] aRaw, bRaw;
        try {
            aRaw = open(objectReader, ent.getOldMode(), ent.getOldId());
            bRaw = open(objectReader, ent.getNewMode(), ent.getNewId());
        } finally {
            // objectReader.release();
        }

        if (RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
            //out.write(encodeASCII("Binary files differ\n"));
            return emptyList();
        } else {
            RawText a = new RawText(aRaw);
            RawText b = new RawText(bRaw);
            return formatEdits(a, b, MyersDiff.INSTANCE.diff(DEFAULT, a, b));
        }
    }
}
 
开发者ID:m4rzEE1,项目名称:ninja_chic-,代码行数:33,代码来源:LineContextDiffer.java

示例5: format

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
@Override
public void format(FileHeader hdr, RawText a, RawText b)
    throws IOException {
  int start = hdr.getStartOffset();
  int end = hdr.getEndOffset();
  if (!hdr.getHunks().isEmpty()) {
    end = hdr.getHunks().get(0).getStartOffset();
  }
  renderHeader(RawParseUtils.decode(hdr.getBuffer(), start, end));

  if (hdr.getPatchType() == PatchType.UNIFIED) {
    getOutputStream().write(DIFF_BEGIN);
    format(hdr.toEditList(), a, b);
    getOutputStream().write(DIFF_END);
  }
}
 
开发者ID:afrojer,项目名称:gitiles,代码行数:17,代码来源:HtmlDiffFormatter.java

示例6: writeLine

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
@Override
protected void writeLine(char prefix, RawText text, int cur)
    throws IOException {
  // Manually render each line, rather than invoke a Soy template. This method
  // can be called thousands of times in a single request. Avoid unnecessary
  // overheads by formatting as-is.
  OutputStream out = getOutputStream();
  switch (prefix) {
    case '+':
      out.write(LINE_INSERT_BEGIN);
      break;
    case '-':
      out.write(LINE_DELETE_BEGIN);
      break;
    case ' ':
    default:
      out.write(LINE_CHANGE_BEGIN);
      break;
  }
  out.write(prefix);
  out.write(StringEscapeUtils.escapeHtml4(text.getString(cur)).getBytes(Charsets.UTF_8));
  out.write(LINE_END);
}
 
开发者ID:afrojer,项目名称:gitiles,代码行数:24,代码来源:HtmlDiffFormatter.java

示例7: blame

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
/**
 * Returns the list of lines in the specified source file annotated with the
 * source commit metadata.
 * 
 * @param repository
 * @param blobPath
 * @param objectId
 * @return list of annotated lines
 */
public static List<AnnotatedLine> blame(Repository repository, String blobPath, String objectId) {
	List<AnnotatedLine> lines = new ArrayList<AnnotatedLine>();
	try {
		ObjectId object;
		if (StringUtils.isEmpty(objectId)) {
			object = JGitUtils.getDefaultBranch(repository);
		} else {
			object = repository.resolve(objectId);
		}
		BlameCommand blameCommand = new BlameCommand(repository);
		blameCommand.setFilePath(blobPath);
		blameCommand.setStartCommit(object);
		BlameResult blameResult = blameCommand.call();
		RawText rawText = blameResult.getResultContents();
		int length = rawText.size();
		for (int i = 0; i < length; i++) {
			RevCommit commit = blameResult.getSourceCommit(i);
			AnnotatedLine line = new AnnotatedLine(commit, i + 1, rawText.getString(i));
			lines.add(line);
		}
	} catch (Throwable t) {
		LOGGER.error(MessageFormat.format("failed to generate blame for {0} {1}!", blobPath, objectId), t);
	}
	return lines;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:35,代码来源:DiffUtils.java

示例8: writeLine

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
@Override
protected void writeLine(final char prefix, final RawText text, final int cur)
		throws IOException {
	switch (prefix) {
	case '+':
		os.write("<span style=\"color:#008000;\">".getBytes());
		break;
	case '-':
		os.write("<span style=\"color:#800000;\">".getBytes());
		break;
	}
	os.write(prefix);
	String line = text.getString(cur);
	line = StringUtils.escapeForHtml(line, false);
	os.write(encode(line));
	switch (prefix) {
	case '+':
	case '-':
		os.write("</span>\n".getBytes());
		break;
	default:
		os.write('\n');
	}
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:25,代码来源:GitWebDiffFormatter.java

示例9: main

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
public static void main(String args[])
    throws IOException, GitAPIException {
    try (Repository repo = CookbookHelper.openJGitCookbookRepository()) {
        final String[] list = new File(".").list();
        if(list == null) {
            throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath());
        }

        for(String file : list) {
            if(new File(file).isDirectory()) {
                continue;
            }

            System.out.println("Blaming " + file);
            final BlameResult result = new Git(repo).blame().setFilePath(file).call();
            final RawText rawText = result.getResultContents();
            for (int i = 0; i < rawText.size(); i++) {
                final PersonIdent sourceAuthor = result.getSourceAuthor(i);
                final RevCommit sourceCommit = result.getSourceCommit(i);
                System.out.println(sourceAuthor.getName() +
                        (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") +
                        ": " + rawText.getString(i));
            }
        }
    }
}
 
开发者ID:centic9,项目名称:jgit-cookbook,代码行数:27,代码来源:BlameFile.java

示例10: checkoutFile

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
private void checkoutFile (MergeResult<RawText> merge, String path) throws IOException {
    File file = new File(getRepository().getWorkTree(), path);
    file.getParentFile().mkdirs();
    MergeFormatter format = new MergeFormatter();
    WorkingTreeOptions opt = getRepository().getConfig().get(WorkingTreeOptions.KEY);
    try (OutputStream fos = opt.getAutoCRLF() != CoreConfig.AutoCRLF.FALSE
            ? new AutoCRLFOutputStream(new FileOutputStream(file))
            : new FileOutputStream(file)) {
        format.formatMerge(fos, merge, Arrays.asList(new String[] { "BASE", "OURS", "THEIRS" }), //NOI18N
                Constants.CHARACTER_ENCODING);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:CheckoutRevisionCommand.java

示例11: equals

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
@Override
public boolean equals (RawText a, int ai, RawText b, int bi) {
    String line1 = a.getString(ai);
    String line2 = b.getString(bi);
    line1 = trimTrailingEoL(line1);
    line2 = trimTrailingEoL(line2);

    return line1.equals(line2);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:AutoCRLFComparator.java

示例12: flatten

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
public static FlatSource flatten(byte[] input) {
	// file is binary, ignore all contents
	if(RawText.isBinary(input)) return new FlatSource(new byte[0], new IntList());
	
	IntList realLines = new IntList();
	ByteBuffer to = ByteBuffer.allocate(input.length*2), from = ByteBuffer.wrap(input);
	boolean atLineStart = true, lastWord = false, lastSpace = false;
	while(from.hasRemaining()) {
		if(atLineStart) {
			realLines.add(to.position());
		}
		byte cur = from.get();
		if (cur == '\n') {
			atLineStart = true;
			to.put(cur);
		} else if (cur == ' ' || cur == '\t' ) {
			if(!atLineStart && !lastSpace)
				to.put((byte)'\n');
    		to.put(cur);
    		lastSpace = true;
    		lastWord = false;
			atLineStart = false;
		} else {
			if(!atLineStart && !lastWord)
				to.put((byte)'\n');
			to.put(cur);
			lastSpace = false;
			lastWord = true;
			atLineStart = false;
		}
	}
	byte[] out = new byte[to.position()];
	to.position(0);
	to.get(out);
	return new FlatSource(out, realLines);//new FlatSource(new byte[])
}
 
开发者ID:AMOSTeam3,项目名称:amos-ss15-proj3,代码行数:37,代码来源:FlatSource.java

示例13: createPatchListEntry

import org.eclipse.jgit.diff.RawText; //导入依赖的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

示例14: getDifferences

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
/**
 * Generates the differences between the contents of the 2 files.
 *
 * @param baseFile
 *            The base file to examine.
 * @param patchFile
 *            The patch file to examine.
 * @return The iterator containing the differences.
 * @throws IOException
 *             if Exceptions occur while reading the file.
 */
public static Iterator<JgitDifference> getDifferences(File baseFile, File patchFile)
        throws IOException {
    if (diffAlgorithm == null) {
        diffAlgorithm = DiffAlgorithm.getAlgorithm(SupportedAlgorithm.HISTOGRAM);
    }

    final RawText baseFileRaw = new RawText(baseFile);
    final RawText patchFileRaw = new RawText(patchFile);

    return new JgitDifferenceIterator(diffAlgorithm.diff(RawTextComparator.DEFAULT,
            baseFileRaw, patchFileRaw), baseFileRaw, patchFileRaw);
}
 
开发者ID:checkstyle,项目名称:contribution,代码行数:24,代码来源:JgitUtils.java

示例15: getFileContent

import org.eclipse.jgit.diff.RawText; //导入依赖的package包/类
private FileContent getFileContent(Git git, String path, ObjectId objectId) {
  try {
    ObjectLoader loader = git.getRepository().open(objectId);
    if (RawText.isBinary(loader.openStream())) {
      return new FileContent(path, true, null);
    }
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    loader.copyTo(stream);
    return new FileContent(path, false, stream.toString());
  } catch (IOException e) {

  }
  return null;
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:15,代码来源:GitOperation.java


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