本文整理匯總了Java中org.eclipse.jgit.lib.ObjectReader類的典型用法代碼示例。如果您正苦於以下問題:Java ObjectReader類的具體用法?Java ObjectReader怎麽用?Java ObjectReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ObjectReader類屬於org.eclipse.jgit.lib包,在下文中一共展示了ObjectReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getHeadFiles
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
private List<IdentifiableResource> getHeadFiles (Repository aRepository, String... aSearchPaths) {
List<String> searchPaths = Arrays.asList(aSearchPaths);
List<IdentifiableResource> resources = new ArrayList<>();
try (ObjectReader reader = aRepository.newObjectReader(); RevWalk walk = new RevWalk(reader); TreeWalk treeWalk = new TreeWalk(aRepository,reader);) {
final ObjectId id = aRepository.resolve(Constants.HEAD);
RevCommit commit = walk.parseCommit(id);
RevTree tree = commit.getTree();
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
while (treeWalk.next()) {
String path = treeWalk.getPathString();
if(searchPaths.stream().anyMatch((sp)->path.startsWith(sp))) {
ObjectId objectId = treeWalk.getObjectId(0);
logger.debug("Loading {} [{}]",path,objectId.name());
resources.add(readBlob(aRepository, path.substring(0, path.indexOf('.')), objectId.name()));
}
}
return resources;
}
catch (Exception e) {
throw Throwables.propagate(e);
}
}
示例2: getIterator
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
private AbstractTreeIterator getIterator (String commit, ObjectReader or) throws IOException, GitException {
Repository repository = getRepository();
switch (commit) {
case Constants.HEAD:
return getHeadIterator(or);
case GitClient.INDEX:
return new DirCacheIterator(repository.readDirCache());
case GitClient.WORKING_TREE:
return new FileTreeIterator(repository);
default:
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(or, Utils.findCommit(repository, commit).getTree());
return p;
}
}
示例3: checkoutEntry
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
public void checkoutEntry (Repository repository, File file, DirCacheEntry e, ObjectReader od) throws IOException, GitException {
// ... create/overwrite this file ...
if (!ensureParentFolderExists(file.getParentFile())) {
return;
}
boolean exists = file.exists();
if (exists && e.getFileMode() == FileMode.SYMLINK) {
monitor.notifyWarning(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_SymLink"), file.getAbsolutePath())); //NOI18N
return;
}
if (Utils.isFromNested(e.getFileMode().getBits())) {
if (!exists) {
file.mkdirs();
}
} else {
if (exists && file.isDirectory()) {
monitor.notifyWarning(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_ReplacingDirectory"), file.getAbsolutePath())); //NOI18N
Utils.deleteRecursively(file);
}
file.createNewFile();
if (file.isFile()) {
DirCacheCheckout.checkoutEntry(repository, file, e, od);
} else {
monitor.notifyError(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_CannotCreateFile"), file.getAbsolutePath())); //NOI18N
}
}
}
示例4: testAddMissingSymlink
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
public void testAddMissingSymlink () throws Exception {
if (isWindows()) {
return;
}
String path = "folder/file";
File f = new File(workDir, path);
// try with commandline client
File link = new File(workDir, "link");
Files.createSymbolicLink(Paths.get(link.getAbsolutePath()), Paths.get(path));
getClient(workDir).add(new File[] { link }, NULL_PROGRESS_MONITOR);
DirCacheEntry e = repository.readDirCache().getEntry(link.getName());
assertEquals(FileMode.SYMLINK, e.getFileMode());
assertEquals(0, e.getLength());
ObjectReader reader = repository.getObjectDatabase().newReader();
assertTrue(reader.has(e.getObjectId()));
byte[] bytes = reader.open(e.getObjectId()).getBytes();
assertEquals(path, RawParseUtils.decode(bytes));
reader.release();
}
示例5: blockingPreviewDiff
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
private Map<String, Change<?>> blockingPreviewDiff(Revision baseRevision, Iterable<Change<?>> changes) {
requireNonNull(baseRevision, "baseRevision");
requireNonNull(changes, "changes");
baseRevision = blockingNormalize(baseRevision);
try (ObjectReader reader = jGitRepository.newObjectReader();
RevWalk revWalk = new RevWalk(reader);
DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) {
final ObjectId baseTreeId = toTreeId(revWalk, baseRevision);
final DirCache dirCache = DirCache.newInCore();
final int numEdits = applyChanges(baseRevision, baseTreeId, dirCache, changes);
if (numEdits == 0) {
return Collections.emptyMap();
}
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(reader, baseTreeId);
diffFormatter.setRepository(jGitRepository);
List<DiffEntry> result = diffFormatter.scan(p, new DirCacheIterator(dirCache));
return toChangeMap(result);
} catch (IOException e) {
throw new StorageException("failed to perform a dry-run diff", e);
}
}
示例6: getTreeIterator
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
private AbstractTreeIterator getTreeIterator( String commitId ) throws Exception {
if ( commitId == null ) {
return new EmptyTreeIterator();
}
if ( commitId.equals( WORKINGTREE ) ) {
return new FileTreeIterator( git.getRepository() );
} else if ( commitId.equals( INDEX ) ) {
return new DirCacheIterator( git.getRepository().readDirCache() );
} else {
ObjectId id = git.getRepository().resolve( commitId );
if ( id == null ) { // commitId does not exist
return new EmptyTreeIterator();
} else {
CanonicalTreeParser treeIterator = new CanonicalTreeParser();
try ( RevWalk rw = new RevWalk( git.getRepository() ) ) {
RevTree tree = rw.parseTree( id );
try ( ObjectReader reader = git.getRepository().newObjectReader() ) {
treeIterator.reset( reader, tree.getId() );
}
}
return treeIterator;
}
}
}
示例7: extractMessage
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
@Override
public RebaseResponse extractMessage(Repository repository) throws IOException {
List<RebaseTodoLine> rebaseTodoLines = repository.readRebaseTodo(getRebasePath(repository, DONE), false);
// the last rebase_todo_line
RebaseTodoLine line = rebaseTodoLines.get(rebaseTodoLines.size() - 1);
try (RevWalk walk = new RevWalk(repository)) {
ObjectReader or = repository.newObjectReader();
RevCommit commitToPick = walk.parseCommit(or.resolve(line.getCommit()).iterator().next());
String oldMessage = commitToPick.getFullMessage();
RebaseResponse response = new RebaseResponse(false, RebaseResponse.Status.INTERACTIVE_EDIT);
response.setMessage(oldMessage);
return response;
}
}
示例8: name
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
@Test public void name() throws IOException, GitAPIException {
ObjectId head = repo.resolve("HEAD^{tree}");
ObjectId oldHead = repo.resolve("HEAD^^{tree}");
ObjectReader reader = repo.newObjectReader();
CanonicalTreeParser prevParser = new CanonicalTreeParser();
prevParser.reset(reader, oldHead);
CanonicalTreeParser headParser = new CanonicalTreeParser();
headParser.reset(reader, head);
List<DiffEntry> diffs = new Git(repo).diff()
.setNewTree(headParser)
.setOldTree(prevParser)
.call();
for (DiffEntry entry : diffs)
System.out.println(entry);
}
示例9: prepareTreeParser
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
private AbstractTreeIterator prepareTreeParser(Repository repo, Ref targetRef) throws IOException {
try (RevWalk walk = newRevWalk(repo)) {
walk.markStart(walk.parseCommit(targetRef.getObjectId()));
walk.markStart(walk.parseCommit(repo.exactRef("HEAD").getObjectId()));
walk.setRevFilter(RevFilter.MERGE_BASE);
RevCommit base = walk.parseCommit(walk.next());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader objectReader = repo.newObjectReader()) {
treeParser.reset(objectReader, base.getTree());
}
walk.dispose();
return treeParser;
}
}
示例10: emptyToCommit
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
/**
* Show changes between specified revision and empty tree.
*
* @param commitId id of commit
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> emptyToCommit(String commitId, DiffFormatter formatter)
throws IOException {
ObjectId commit = repository.resolve(commitId);
checkArgument(commit != null, "Invalid commit id " + commitId);
RevTree tree;
try (RevWalk revWalkA = new RevWalk(repository)) {
tree = revWalkA.parseTree(commit);
}
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
CanonicalTreeParser iterator = new CanonicalTreeParser();
iterator.reset(reader, tree);
diff = formatter.scan(new EmptyTreeIterator(), iterator);
}
return diff;
}
示例11: getDiffBetweenCommits
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
public String getDiffBetweenCommits(int commitIndex) throws IOException,GitAPIException{
if(commitIndex+1==commitCount)
return "Nothing to Diff. This is first commit";
AbstractTreeIterator current = prepareTreeParser(repository,commitSHA.get(commitIndex));
AbstractTreeIterator parent = prepareTreeParser(repository,commitSHA.get(++commitIndex));
ObjectReader reader = repository.newObjectReader();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
// finally get the list of changed files
Git git = new Git(repository) ;
List<DiffEntry> diff = git.diff().
setOldTree(parent).
setNewTree(current).
//TODO Set the path filter to filter out the selected file
//setPathFilter(PathFilter.create("README.md")).
call();
for (DiffEntry entry : diff) {
System.out.println("Entry: " + entry + ", from: " + entry.getOldId() + ", to: " + entry.getNewId());
DiffFormatter formatter = new DiffFormatter(byteStream) ;
formatter.setRepository(repository);
formatter.format(entry);
}
// System.out.println(byteStream.toString());
String diffContent = byteStream.toString();
return byteStream.toString();
}
示例12: getPatchListEntry
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的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);
}
示例13: merge
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
@Override
public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter)
throws IOException {
if (ours == null) {
return theirs;
}
if (theirs == null) {
return ours;
}
if (ours.getData().equals(theirs.getData())) {
return ours;
}
ObjectLoader lo = reader.open(ours.getData());
byte[] sep = new byte[] {'\n'};
ObjectLoader lt = reader.open(theirs.getData());
try (ObjectStream os = lo.openStream();
ByteArrayInputStream b = new ByteArrayInputStream(sep);
ObjectStream ts = lt.openStream();
UnionInputStream union = new UnionInputStream(os, b, ts)) {
ObjectId noteData =
inserter.insert(Constants.OBJ_BLOB, lo.getSize() + sep.length + lt.getSize(), union);
return new Note(ours, noteData);
}
}
示例14: onLoad
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
metaId = handle.id();
if (metaId == null) {
loadDefaults();
return;
}
metaId = metaId.copy();
RevCommit tipCommit = handle.walk().parseCommit(metaId);
ObjectReader reader = handle.walk().getObjectReader();
revisionNoteMap =
RevisionNoteMap.parseRobotComments(args.noteUtil, reader, NoteMap.read(reader, tipCommit));
ListMultimap<RevId, RobotComment> cs = MultimapBuilder.hashKeys().arrayListValues().build();
for (RobotCommentsRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (RobotComment c : rn.getComments()) {
cs.put(new RevId(c.revId), c);
}
}
comments = ImmutableListMultimap.copyOf(cs);
}
示例15: onLoad
import org.eclipse.jgit.lib.ObjectReader; //導入依賴的package包/類
@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
ObjectId rev = handle.id();
if (rev == null) {
loadDefaults();
return;
}
RevCommit tipCommit = handle.walk().parseCommit(rev);
ObjectReader reader = handle.walk().getObjectReader();
revisionNoteMap =
RevisionNoteMap.parse(
args.noteUtil,
getChangeId(),
reader,
NoteMap.read(reader, tipCommit),
PatchLineComment.Status.DRAFT);
ListMultimap<RevId, Comment> cs = MultimapBuilder.hashKeys().arrayListValues().build();
for (ChangeRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (Comment c : rn.getComments()) {
cs.put(new RevId(c.revId), c);
}
}
comments = ImmutableListMultimap.copyOf(cs);
}