org.eclipse.jgit.util.IO Java Examples

The following examples show how to use org.eclipse.jgit.util.IO. 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 File: CherryPickCommand.java    From netbeans with 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 File: GitUtils.java    From orion.server with 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 File: CheckoutRevisionCommand.java    From netbeans with 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
Source File: SquashActionHandler.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: EditActionHandler.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: RebaseStateUtils.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
}