本文整理汇总了Java中org.eclipse.jgit.lib.ObjectLoader类的典型用法代码示例。如果您正苦于以下问题:Java ObjectLoader类的具体用法?Java ObjectLoader怎么用?Java ObjectLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectLoader类属于org.eclipse.jgit.lib包,在下文中一共展示了ObjectLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putEntry
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
@Override
public void putEntry(ZipOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) throws IOException {
// loader is null for directories...
if (loader != null) {
ZipEntry entry = new ZipEntry(path);
if (tree instanceof RevCommit) {
long t = ((RevCommit) tree).getCommitTime() * 1000L;
entry.setTime(t);
}
out.putNextEntry(entry);
out.write(loader.getBytes());
out.closeEntry();
}
}
示例2: getLoaderFrom
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
/**
* Gets the loader for a file from a specified commit and its path
*
* @param commit
* - the commit from which to get the loader
* @param path
* - the path to the file
* @return the loader
* @throws MissingObjectException
* @throws IncorrectObjectTypeException
* @throws CorruptObjectException
* @throws IOException
*/
public ObjectLoader getLoaderFrom(ObjectId commit, String path)
throws IOException {
Repository repository = git.getRepository();
RevWalk revWalk = new RevWalk(repository);
RevCommit revCommit = revWalk.parseCommit(commit);
// and using commit's tree find the path
RevTree tree = revCommit.getTree();
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(path));
ObjectLoader loader = null;
if (treeWalk.next()) {
ObjectId objectId = treeWalk.getObjectId(0);
loader = repository.open(objectId);
}
treeWalk.close();
revWalk.close();
return loader;
}
示例3: getProjectList
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
public List<String> getProjectList(String projectName){
FileRepositoryBuilder builder = new FileRepositoryBuilder();
List list= new ArrayList();
try {
log.debug("errororororoor123 "+ "\n");
Repository repository = builder
.readEnvironment() // scan environment GIT_* variables
.setGitDir(new File("C:/test0101/" + projectName +"/.git")) // scan up the file system tree
.build();
DirCache index = DirCache.read(repository);
ObjectLoader loader = null;
log.debug("DirCache has " + index.getEntryCount() + " items");
for (int i = 0; i < index.getEntryCount(); i++) {
log.debug(index.getEntry(i).getPathString()+ "\n");
list.add(index.getEntry(i).getPathString());
}
} catch (IOException e) {
log.debug("errororororoor "+ "\n");
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
示例4: getRevisionGitNotes
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
/**
* Storing revisions in Git Notes causes object hash computation, which is expensive.
*/
public AssetRevision getRevisionGitNotes(File file) throws IOException {
AssetRevision rev = file2rev.get(file);
if (rev == null) {
ObjectId workingId = getObjectId(file);
try (RevWalk walk = new RevWalk(localRepo)) {
Ref ref = localRepo.findRef(NOTES_REF);
if (ref != null) {
RevCommit notesCommit = walk.parseCommit(ref.getObjectId());
NoteMap notes = NoteMap.read(walk.getObjectReader(), notesCommit);
Note note = notes.getNote(workingId);
if (note != null) {
ObjectLoader loader = localRepo.open(note.getData());
String noteStr = new String(loader.getBytes()).trim();
rev = parseAssetRevision(noteStr);
file2rev.put(file, rev);
return rev;
}
}
}
}
return rev;
}
示例5: readFromCommit
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
public byte[] readFromCommit(String commitId, String path) throws Exception {
try (RevWalk revWalk = new RevWalk(localRepo)) {
RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId));
// use commit's tree find the path
RevTree tree = commit.getTree();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(path));
if (!treeWalk.next()) {
return null;
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = localRepo.open(objectId);
loader.copyTo(baos);
}
revWalk.dispose();
return baos.toByteArray();
}
}
示例6: getFileFromCommit
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
public static boolean getFileFromCommit(final OutputStream os, final String file, final Repository repo, final RevTree tree) throws IOException, GitAPIException {
final TreeWalk treeWalk = new TreeWalk(repo);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(file));
if (!treeWalk.next()) {
logger.info("Did not find expected file '" + file + "'");
return false;
}
final ObjectId objectId = treeWalk.getObjectId(0);
final ObjectLoader loader = repo.open(objectId);
// and then one can the loader to read the file
loader.copyTo(os);
return true;
}
示例7: merge
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的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);
}
}
示例8: zipBlob
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
@SuppressWarnings("resource")
private BinaryResult zipBlob(
final String path, ObjectLoader obj, RevCommit commit, @Nullable final String suffix) {
final String commitName = commit.getName();
final long when = commit.getCommitTime() * 1000L;
return new BinaryResult() {
@Override
public void writeTo(OutputStream os) throws IOException {
try (ZipOutputStream zipOut = new ZipOutputStream(os)) {
String decoration = randSuffix();
if (!Strings.isNullOrEmpty(suffix)) {
decoration = suffix + '-' + decoration;
}
ZipEntry e = new ZipEntry(safeFileName(path, decoration));
e.setComment(commitName + ":" + path);
e.setSize(obj.getSize());
e.setTime(when);
zipOut.putNextEntry(e);
obj.copyTo(zipOut);
zipOut.closeEntry();
}
}
}.setContentType(ZIP_TYPE).setAttachmentName(safeFileName(path, suffix) + ".zip").disableGzip();
}
示例9: execute
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
public Ref execute() {
try {
final Ref value = repo.getRefDatabase().getRef(name);
if (value != null) {
return value;
}
final ObjectId treeRef = repo.resolve(name + "^{tree}");
if (treeRef != null) {
final ObjectLoader loader = repo.getObjectDatabase().newReader().open(treeRef);
if (loader.getType() == OBJ_TREE) {
return new ObjectIdRef.PeeledTag(Ref.Storage.NEW,
name,
ObjectId.fromString(name),
treeRef);
}
}
} catch (final Exception ignored) {
}
return null;
}
示例10: parseBlobs
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
private void parseBlobs(String repositoryPath, String syntaxTreeDirPath) {
File repoDir = new File(repositoryPath);
try {
Repository repo = new FileRepository(repoDir);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
while ( (line = br.readLine()) != null) {
root = new Tree("");
ObjectId obj = ObjectId.fromString(line);
ObjectLoader loader = repo.open(obj);
char[] src = IOUtils.toCharArray(loader.openStream());
File outputFile = new File(syntaxTreeDirPath, line);
parseSourcecodeAndWriteSyntaxTree(src, outputFile);
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例11: open
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
private byte[] open(ObjectReader reader, FileMode mode,
AbbreviatedObjectId id) throws IOException {
if (mode == FileMode.MISSING)
return new byte[] { };
if (mode.getObjectType() != Constants.OBJ_BLOB)
return new byte[] { };
if (!id.isComplete()) {
Collection<ObjectId> ids = reader.resolve(id);
if (ids.size() == 1)
id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
else if (ids.size() == 0)
throw new MissingObjectException(id, Constants.OBJ_BLOB);
else
throw new AmbiguousObjectException(id, ids);
}
ObjectLoader ldr = reader.open(id.toObjectId());
return ldr.getCachedBytes(bigFileThreshold);
}
示例12: extractPackage
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
private void extractPackage(Repository _repo) throws MissingObjectException, IOException{
ObjectLoader newFile = _repo.open(this.newObjId);
String newData = readStream(newFile.openStream());
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(newData.toCharArray());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
Hashtable<String, String> options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED);
parser.setCompilerOptions(options);
final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.accept(new ASTVisitor() {
public boolean visit(PackageDeclaration _package){
packageName = _package.getName().getFullyQualifiedName();
return false;
}
});
}
示例13: getByteContent
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
/**
* Retrieves the raw byte content of a file in the specified tree.
*
* @param repository
* @param tree
* if null, the RevTree from HEAD is assumed.
* @param path
* @return content as a byte []
*/
public static byte[] getByteContent(Repository repository, RevTree tree, final String path, boolean throwError) {
RevWalk rw = new RevWalk(repository);
byte[] content = null;
try (TreeWalk tw = new TreeWalk(repository)) {
tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
if (tree == null) {
ObjectId object = getDefaultBranch(repository);
if (object == null) {
return null;
}
RevCommit commit = rw.parseCommit(object);
tree = commit.getTree();
}
tw.reset(tree);
while (tw.next()) {
if (tw.isSubtree() && !path.equals(tw.getPathString())) {
tw.enterSubtree();
continue;
}
ObjectId entid = tw.getObjectId(0);
FileMode entmode = tw.getFileMode(0);
if (entmode != FileMode.GITLINK) {
ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
content = ldr.getCachedBytes();
}
}
} catch (Throwable t) {
if (throwError) {
error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name());
}
} finally {
rw.close();
rw.dispose();
}
return content;
}
示例14: getMd5
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
@NotNull
@Override
public String getMd5(@NotNull GitObject<? extends ObjectId> objectId) throws IOException, SVNException {
final ObjectLoader loader = objectId.openObject();
final ObjectStream stream = loader.openStream();
final byte[] header = new byte[Constants.POINTER_MAX_SIZE];
int length = ByteStreams.read(stream, header, 0, header.length);
if (length < header.length) {
final Map<String, String> pointer = Pointer.parsePointer(header, 0, length);
if (pointer != null) {
String md5 = getReader(pointer).getMd5();
if (md5 != null) {
return md5;
}
}
}
return GitFilterHelper.getMd5(this, cacheMd5, null, objectId);
}
示例15: getByteContent
import org.eclipse.jgit.lib.ObjectLoader; //导入依赖的package包/类
/**
* Gets the raw byte content of the specified blob object.
*
* @param repository
* @param objectId
* @return byte [] blob content
*/
public static byte[] getByteContent(Repository repository, String objectId) {
RevWalk rw = new RevWalk(repository);
byte[] content = null;
try {
RevBlob blob = rw.lookupBlob(ObjectId.fromString(objectId));
rw.parseBody(blob);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ObjectLoader ldr = repository.open(blob.getId(), Constants.OBJ_BLOB);
byte[] tmp = new byte[4096];
InputStream in = ldr.openStream();
int n;
while ((n = in.read(tmp)) > 0) {
os.write(tmp, 0, n);
}
in.close();
content = os.toByteArray();
} catch (Throwable t) {
error(t, repository, "{0} can't find blob {1}", objectId);
} finally {
rw.dispose();
}
return content;
}