项目:gerrit
文件:ReviewNoteMerger.java
@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);
}
}
项目:git-as-svn
文件:LfsFilter.java
@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,header.length);
if (length < header.length) {
final Map<String,String> pointer = Pointer.parsePointer(header,length);
if (pointer != null) {
String md5 = getReader(pointer).getMd5();
if (md5 != null) {
return md5;
}
}
}
return GitFilterHelper.getMd5(this,cacheMd5,null,objectId);
}
public ObjectStream getRemoteContentStream(String branch,String path) throws Exception {
ObjectId id = localRepo.resolve("refs/remotes/origin/" + branch);
try (ObjectReader reader = localRepo.newObjectReader();
RevWalk walk = new RevWalk(reader)) {
RevCommit commit = walk.parseCommit(id);
RevTree tree = commit.getTree();
TreeWalk treewalk = TreeWalk.forPath(reader,path,tree);
if (treewalk != null) {
return reader.open(treewalk.getobjectId(0)).openStream();
}
else {
return null;
}
}
}
项目:ninja_chic-
文件:BlobViewFragment.java
@Override
public Loader<BlobView> onCreateLoader(int id,Bundle b) {
return new AsyncLoader<BlobView>(getActivity()) {
public BlobView loadInBackground() {
Bundle args = getArguments();
try {
Repository repo = FileRepositoryBuilder.create(gitDirFrom(args));
ObjectId revision = repo.resolve(args.getString(UNTIL_REVS));
RevWalk revWalk = new RevWalk(repo);
RevCommit commit = revWalk.parseCommit(revision);
TreeWalk treeWalk = TreeWalk.forPath(repo,args.getString(PATH),commit.getTree());
ObjectId blobId = treeWalk.getobjectId(0);
ObjectLoader objectLoader = revWalk.getobjectReader().open(blobId,Constants.OBJ_BLOB);
ObjectStream binaryTestStream = objectLoader.openStream();
boolean blobIsBinary = RawText.isBinary(binaryTestStream);
binaryTestStream.close();
Log.d(TAG,"blobIsBinary="+blobIsBinary);
return blobIsBinary?new BinaryBlobView(objectLoader,treeWalk.getNameString()):new TextBlobView(objectLoader);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
项目:ninja_chic-
文件:BlobViewFragment.java
BinaryBlobView(ObjectLoader objectLoader,String nameString) throws IOException {
this.nameString = nameString;
ObjectStream stream = objectLoader.openStream();
tempFile= new File(getActivity().getExternalCacheDir(),nameString);
copyInputStreamToFile(stream,tempFile);
mimeType=URLConnection.getFileNameMap().getContentTypeFor(nameString);
Log.d(TAG,"mimeType="+mimeType+" tempFile="+tempFile);
}
项目:git-server
文件:JGitRepositoryFacade.java
private static EntryType of(org.eclipse.jgit.lib.Repository repo,TreeWalk walker,String entry) throws IOException {
if (entry.endsWith("/")) {
return EntryType.FOLDER;
}
ObjectId objectId = walker.getobjectId(0);
ObjectLoader loader = repo.open(objectId);
try (ObjectStream stream = loader.openStream()) {
if (RawText.isBinary(stream)) {
return EntryType.BINARY;
}
return EntryType.TEXT;
}
}
项目:git-as-svn
文件:LfsFilter.java
@Override
public long getSize(@NotNull GitObject<? extends ObjectId> objectId) throws IOException {
final ObjectLoader loader = objectId.openObject();
final ObjectStream stream = loader.openStream();
final byte[] header = new byte[Constants.POINTER_MAX_SIZE];
int length = ByteStreams.read(stream,length);
if (pointer != null) {
return getReader(pointer).getSize();
}
}
return loader.getSize();
}
项目:git-as-svn
文件:LfsFilter.java
@NotNull
@Override
public InputStream inputStream(@NotNull GitObject<? extends ObjectId> objectId) throws IOException {
final ObjectLoader loader = objectId.openObject();
final ObjectStream stream = loader.openStream();
final byte[] header = new byte[Constants.POINTER_MAX_SIZE];
int length = ByteStreams.read(stream,length);
if (pointer != null) {
return getReader(pointer).openStream();
}
}
return new TemporaryInputStream(header,length,stream);
}
/**
* Find the tree that contains the required identity.
*
* @return The ObjectId of the tree (directory) that contains the matching
* identity within the supplied hierarchy.
*/
private ObjectId findMatchingIdentity(
IdentityValidator identityValidator,ObjectId tree) throws IOException {
TreeWalk treeWalk = new TreeWalk(repo.getRepository());
try {
treeWalk.setRecursive(false);
treeWalk.addTree(tree);
while (treeWalk.next()) {
if (treeWalk.isSubtree()) {
ObjectId candidateId = findMatchingIdentity(
identityValidator,treeWalk.getobjectId(0));
if (ObjectId.zeroId().equals(candidateId)) {
// Keep searching
} else {
return candidateId;
}
} else if (identityValidator.getIdentityFilename().equals(treeWalk.getNameString())) {
// Read the identity file
ObjectLoader loader = repo.getRepository().open(
treeWalk.getobjectId(0));
ObjectStream stream = loader.openStream();
InputStreamReader reader = new InputStreamReader(stream,StandardCharsets.UTF_8);
if (identityValidator.isIdentityMatched(new BufferedReader(reader))) {
// We found it
return tree;
}
}
}
return ObjectId.zeroId();
} finally {
treeWalk.release();
}
}
@Override
public BufferedReader getBufferedReader(
IdentityValidator identityValidator,String filename,Optional<String> label) throws IOException {
if (label.isPresent()) {
Pair<String,ObjectId> diff = findDiff(identityValidator,label.get());
if (ObjectId.zeroId().equals(diff.getValue())) {
// No such tree
throw new FileNotFoundException(identityValidator.getPath() + " does not exist for label " + label.get());
} else {
// Find the file in this tree
TreeWalk treeWalk = new TreeWalk(repo.getRepository());
try {
treeWalk.setRecursive(false);
treeWalk.addTree(diff.getValue());
while (treeWalk.next()) {
if (filename.equals(treeWalk.getNameString())) {
// Read the file
ObjectLoader loader = repo.getRepository().open(
treeWalk.getobjectId(0));
ObjectStream stream = loader.openStream();
InputStreamReader reader = new InputStreamReader(stream,StandardCharsets.UTF_8);
return new BufferedReader(reader);
}
}
// No such file
throw new FileNotFoundException(filename + " does not exist for label " + label.get()
);
} finally {
treeWalk.release();
}
}
} else {
return delegate.getBufferedReader(identityValidator,filename,label);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。