url, proj.getRevision(), copyfile.src); objectId = inserter.insert(Constants.OBJ_BLOB, rf.getContents()); dcEntry = new DirCacheEntry(copyfile.dest); dcEntry.setObjectId(objectId); dcEntry.setFileMode(rf.getFileMode()); builder.add(dcEntry);
url, proj.getRevision(), copyfile.src); objectId = inserter.insert(Constants.OBJ_BLOB, rf.getContents()); dcEntry = new DirCacheEntry(copyfile.dest); dcEntry.setObjectId(objectId); dcEntry.setFileMode(rf.getFileMode()); builder.add(dcEntry);
@Override public RemoteFile readFileWithMode(String uri, String ref, String path) throws GitAPIException, IOException { File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$ try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir) .setURI(uri).call()) { Repository repo = git.getRepository(); ObjectId refCommitId = sha1(uri, ref); if (refCommitId == null) { throw new InvalidRefNameException(MessageFormat .format(JGitText.get().refNotResolved, ref)); } RevCommit commit = repo.parseCommit(refCommitId); TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree()); // TODO(ifrade): Cope better with big files (e.g. using // InputStream instead of byte[]) return new RemoteFile( tw.getObjectReader().open(tw.getObjectId(0)) .getCachedBytes(Integer.MAX_VALUE), tw.getFileMode(0)); } finally { FileUtils.delete(dir, FileUtils.RECURSIVE); } } }
/** * Read a file from a remote repository. * * @param uri * The URI of the remote repository * @param ref * The ref (branch/tag/etc.) to read * @param path * The relative path (inside the repo) to the file to read * @return the file content. * @throws GitAPIException * @throws IOException * @since 3.5 * * @deprecated Use {@link #readFileWithMode(String, String, String)} * instead */ @Deprecated public default byte[] readFile(String uri, String ref, String path) throws GitAPIException, IOException { return readFileWithMode(uri, ref, path).getContents(); }
@Override public RemoteFile readFileWithMode(String uri, String ref, String path) throws GitAPIException, IOException { File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$ try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir) .setURI(uri).call()) { Repository repo = git.getRepository(); ObjectId refCommitId = sha1(uri, ref); if (refCommitId == null) { throw new InvalidRefNameException(MessageFormat .format(JGitText.get().refNotResolved, ref)); } RevCommit commit = repo.parseCommit(refCommitId); TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree()); // TODO(ifrade): Cope better with big files (e.g. using // InputStream instead of byte[]) return new RemoteFile( tw.getObjectReader().open(tw.getObjectId(0)) .getCachedBytes(Integer.MAX_VALUE), tw.getFileMode(0)); } finally { FileUtils.delete(dir, FileUtils.RECURSIVE); } } }
/** * Read a file from a remote repository. * * @param uri * The URI of the remote repository * @param ref * The ref (branch/tag/etc.) to read * @param path * The relative path (inside the repo) to the file to read * @return the file content. * @throws GitAPIException * @throws IOException * @since 3.5 * * @deprecated Use {@link #readFileWithMode(String, String, String)} * instead */ @Deprecated public default byte[] readFile(String uri, String ref, String path) throws GitAPIException, IOException { return readFileWithMode(uri, ref, path).getContents(); }