本文整理匯總了Java中org.eclipse.jgit.lib.Repository.open方法的典型用法代碼示例。如果您正苦於以下問題:Java Repository.open方法的具體用法?Java Repository.open怎麽用?Java Repository.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.lib.Repository
的用法示例。
在下文中一共展示了Repository.open方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLoaderFrom
import org.eclipse.jgit.lib.Repository; //導入方法依賴的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;
}
示例2: indexBlob
import org.eclipse.jgit.lib.Repository; //導入方法依賴的package包/類
private void indexBlob(IndexWriter writer, Repository repository,
SymbolExtractor<Symbol> extractor, ObjectId blobId, String blobPath) throws IOException {
Document document = new Document();
document.add(new StoredField(BLOB_INDEX_VERSION.name(), getCurrentBlobIndexVersion(extractor)));
document.add(new StringField(BLOB_HASH.name(), blobId.name(), Store.NO));
document.add(new StringField(BLOB_PATH.name(), blobPath, Store.YES));
String blobName = blobPath;
if (blobPath.indexOf('/') != -1)
blobName = StringUtils.substringAfterLast(blobPath, "/");
document.add(new StringField(BLOB_NAME.name(), blobName.toLowerCase(), Store.NO));
ObjectLoader objectLoader = repository.open(blobId);
if (objectLoader.getSize() <= MAX_INDEXABLE_SIZE) {
byte[] bytes = objectLoader.getCachedBytes();
String content = ContentDetector.convertToText(bytes, blobName);
if (content != null) {
document.add(new TextField(BLOB_TEXT.name(), content, Store.NO));
if (extractor != null) {
try {
List<Symbol> symbols = extractor.extract(blobName, content);
for (Symbol symbol: symbols) {
String fieldValue = symbol.getName();
if (fieldValue != null && symbol.isSearchable()) {
fieldValue = fieldValue.toLowerCase();
String fieldName;
if (symbol.isPrimary())
fieldName = BLOB_PRIMARY_SYMBOLS.name();
else
fieldName = BLOB_SECONDARY_SYMBOLS.name();
document.add(new StringField(fieldName, fieldValue, Store.NO));
}
}
byte[] bytesOfSymbols = SerializationUtils.serialize((Serializable) symbols);
document.add(new StoredField(BLOB_SYMBOL_LIST.name(), bytesOfSymbols));
} catch (ExtractException e) {
logger.debug("Error extracting symbols from blob (hash:" + blobId.name() + ", path:" + blobPath + ")", e);
}
}
} else {
logger.debug("Ignore content of binary file '{}'.", blobPath);
}
} else {
logger.debug("Ignore content of large file '{}'.", blobPath);
}
writer.addDocument(document);
}