use of org.eclipse.jgit.lib.ObjectReader in project OpenGrok by OpenGrok.
the class GitRepository method prepareTreeParser.
private static AbstractTreeIterator prepareTreeParser(org.eclipse.jgit.lib.Repository repository, RevCommit commit) throws IOException {
// from the commit we can build the tree which allows us to construct the TreeParser
try (RevWalk walk = new RevWalk(repository)) {
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader reader = repository.newObjectReader()) {
treeParser.reset(reader, tree.getId());
}
walk.dispose();
return treeParser;
}
}
use of org.eclipse.jgit.lib.ObjectReader in project curiostack by curioswitch.
the class CurioGenericCiPlugin method computeAffectedFilesForMaster.
// Assume all tested changes are in a single commit, which works when commits are always squashed.
private static Set<String> computeAffectedFilesForMaster(Git git) throws IOException {
ObjectId oldTreeId = git.getRepository().resolve("HEAD^{tree}");
ObjectId newTreeId = git.getRepository().resolve("HEAD^^{tree}");
final CanonicalTreeParser oldTreeParser;
final CanonicalTreeParser newTreeParser;
try (ObjectReader reader = git.getRepository().newObjectReader()) {
oldTreeParser = parser(reader, oldTreeId);
newTreeParser = parser(reader, newTreeId);
}
return computeAffectedFiles(git, oldTreeParser, newTreeParser);
}
use of org.eclipse.jgit.lib.ObjectReader in project egit by eclipse.
the class FileDiff method outputDiff.
/**
* Creates a textual diff together with meta information.
* TODO So far this works only in case of one parent commit.
*
* @param d
* the StringBuilder where the textual diff is added to
* @param db
* the Repo
* @param diffFmt
* the DiffFormatter used to create the textual diff
* @param gitFormat
* if false, do not show any source or destination prefix,
* and the paths are calculated relative to the eclipse
* project, otherwise relative to the git repository
* @throws IOException
*/
public void outputDiff(final StringBuilder d, final Repository db, final DiffFormatter diffFmt, boolean gitFormat) throws IOException {
if (gitFormat) {
diffFmt.setRepository(db);
diffFmt.format(diffEntry);
return;
}
try (ObjectReader reader = db.newObjectReader()) {
outputEclipseDiff(d, db, reader, diffFmt);
}
}
use of org.eclipse.jgit.lib.ObjectReader in project egit by eclipse.
the class BlameRevision method calculateDiffToParent.
private Diff calculateDiffToParent(RevCommit parentCommit) {
try (ObjectReader reader = repository.newObjectReader()) {
DiffEntry diffEntry = CompareCoreUtils.getChangeDiffEntry(repository, sourcePath, commit, parentCommit, reader);
if (diffEntry == null)
return null;
RawText oldText = readText(diffEntry.getOldId(), reader);
RawText newText = readText(diffEntry.getNewId(), reader);
StoredConfig config = repository.getConfig();
DiffAlgorithm diffAlgorithm = DiffAlgorithm.getAlgorithm(config.getEnum(ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, SupportedAlgorithm.HISTOGRAM));
EditList editList = diffAlgorithm.diff(RawTextComparator.DEFAULT, oldText, newText);
return new Diff(diffEntry.getOldPath(), oldText, newText, editList);
} catch (IOException e) {
return null;
}
}
use of org.eclipse.jgit.lib.ObjectReader in project fuse-karaf by jboss-fuse.
the class GitPatchRepositoryImpl method getFileContent.
@Override
public String getFileContent(Git fork, String sha1, String fileName) throws IOException {
ObjectReader objectReader = fork.getRepository().newObjectReader();
RevCommit commit = new RevWalk(fork.getRepository()).parseCommit(fork.getRepository().resolve(sha1));
TreeWalk tw = new TreeWalk(fork.getRepository());
tw.addTree(commit.getTree());
tw.setRecursive(false);
tw.setFilter(PathFilter.create(fileName));
if (tw.next()) {
ObjectId objectId = tw.getObjectId(0);
ObjectLoader loader = fork.getRepository().open(objectId);
ByteArrayOutputStream out = new ByteArrayOutputStream();
loader.copyTo(out);
return new String(out.toByteArray(), "UTF-8");
}
return null;
}
Aggregations