Java Code Examples for org.eclipse.jgit.util.IO

The following examples show how to use org.eclipse.jgit.util.IO. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   Source File: CherryPickCommand.java    License: Apache License 2.0 6 votes vote down vote up
private ObjectId getOriginalCommit () throws GitException {
    Repository repository = getRepository();
    File seqHead = new File(getSequencerFolder(), SEQUENCER_HEAD);
    ObjectId originalCommitId = null;
    if (seqHead.canRead()) {
        try {
            byte[] content = IO.readFully(seqHead);
            if (content.length > 0) {
                originalCommitId = ObjectId.fromString(content, 0);
            }
            if (originalCommitId != null) {
                originalCommitId = repository.resolve(originalCommitId.getName() + "^{commit}");
            }
        } catch (IOException e) {
        }
    }
    return originalCommitId;
}
 
Example 2
Source Project: orion.server   Source File: GitUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static File getSymRef(File workTree, File dotGit, FS fs)
		throws IOException {
	byte[] content = IO.readFully(dotGit);
	if (!isSymRef(content))
		throw new IOException(MessageFormat.format(
				JGitText.get().invalidGitdirRef, dotGit.getAbsolutePath()));

	int pathStart = 8;
	int lineEnd = RawParseUtils.nextLF(content, pathStart);
	if (content[lineEnd - 1] == '\n')
		lineEnd--;
	if (lineEnd == pathStart)
		throw new IOException(MessageFormat.format(
				JGitText.get().invalidGitdirRef, dotGit.getAbsolutePath()));

	String gitdirPath = RawParseUtils.decode(content, pathStart, lineEnd);
	File gitdirFile = fs.resolve(workTree, gitdirPath);
	if (gitdirFile.isAbsolute())
		return gitdirFile;
	else
		return new File(workTree, gitdirPath).getCanonicalFile();
}
 
Example 3
Source Project: netbeans   Source File: CheckoutRevisionCommand.java    License: Apache License 2.0 5 votes vote down vote up
private void cacheContents (List<String> conflicts) throws IOException {
    File workTree = getRepository().getWorkTree();
    WorkingTreeOptions opt = getRepository().getConfig().get(WorkingTreeOptions.KEY);
    boolean autocrlf = opt.getAutoCRLF() != CoreConfig.AutoCRLF.FALSE;
    try (ObjectInserter inserter = getRepository().newObjectInserter();) {
        for (String path : conflicts) {
            File f = new File(workTree, path);
            Path p = null;
            try {
                p = f.toPath();
            } catch (InvalidPathException ex) {
                Logger.getLogger(CheckoutRevisionCommand.class.getName()).log(Level.FINE, null, ex);
            }
            if (p != null && Files.isSymbolicLink(p)) {
                Path link = Utils.getLinkPath(p);                                
                cachedContents.put(path, inserter.insert(Constants.OBJ_BLOB, Constants.encode(link.toString())));
            } else if (f.isFile()) {
                long sz = f.length();
                try (FileInputStream in = new FileInputStream(f)) {
                    if (autocrlf) {
                        ByteBuffer buf = IO.readWholeStream(in, (int) sz);
                        cachedContents.put(path, inserter.insert(Constants.OBJ_BLOB, buf.array(), buf.position(), buf.limit() - buf.position()));
                    } else {
                        cachedContents.put(path, inserter.insert(Constants.OBJ_BLOB, sz, in));
                    }
                }
            }
        }
        inserter.flush();
    }
}
 
Example 4
@Override
public RebaseResponse extractMessage(Repository repository) throws IOException {
    File messageFile = getRebaseFile(repository, MESSAGE_SQUASH);
    RebaseResponse response = new RebaseResponse(false, RebaseResponse.Status.INTERACTIVE_EDIT);

    if (messageFile.exists()) {
        response.setMessage(new String(IO.readFully(messageFile)));
    }

    return response;
}
 
Example 5
@Override
public RebaseResponse extractMessage(Repository repository) throws IOException {
    File messageFile = getRebaseFile(repository, MESSAGE);

    RebaseResponse response = new RebaseResponse(false, RebaseResponse.Status.INTERACTIVE_EDIT);

    if (messageFile.exists()) {
        response.setMessage(new String(IO.readFully(messageFile)));
    }

    return response;
}
 
Example 6
public static String readFile(File directory, String fileName)
        throws IOException {
    byte[] content = IO.readFully(new File(directory, fileName));
    // strip off the last LF
    int end = RawParseUtils.prevLF(content, content.length);
    return RawParseUtils.decode(content, 0, end + 1);
}