Example usage for org.eclipse.jgit.treewalk CanonicalTreeParser getEntryPathLength

List of usage examples for org.eclipse.jgit.treewalk CanonicalTreeParser getEntryPathLength

Introduction

In this page you can find the example usage for org.eclipse.jgit.treewalk CanonicalTreeParser getEntryPathLength.

Prototype

public int getEntryPathLength() 

Source Link

Document

Get length of the path in #getEntryPathBuffer() .

Usage

From source file:playRepository.BareCommit.java

License:Apache License

private TreeFormatter rebuildExistingTreeWith(String fileName, ObjectId fileObjectId) throws IOException {
    TreeFormatter formatter = new TreeFormatter();
    CanonicalTreeParser treeParser = getCanonicalTreeParser(this.repository);

    boolean isInsertedInTree = false;
    while (!treeParser.eof()) {
        String entryName = new String(treeParser.getEntryPathBuffer(), 0, treeParser.getEntryPathLength(),
                Config.getCharset());/* ww  w  .  j a va2s .co  m*/
        String nameForComparison = entryName;

        if (treeParser.getEntryFileMode() == FileMode.TREE) {
            nameForComparison = entryName.concat("/"); //for tree ordering comparison
        }
        if (nameForComparison.compareTo(fileName) == 0 && isInsertedInTree == false) {
            formatter.append(fileName, FileMode.REGULAR_FILE, fileObjectId);
            isInsertedInTree = true;
        } else if (nameForComparison.compareTo(fileName) > 0 && isInsertedInTree == false) {
            formatter.append(fileName, FileMode.REGULAR_FILE, fileObjectId);
            formatter.append(entryName.getBytes(Config.getCharset()), treeParser.getEntryFileMode(),
                    treeParser.getEntryObjectId());
            isInsertedInTree = true;
        } else {
            formatter.append(entryName.getBytes(Config.getCharset()), treeParser.getEntryFileMode(),
                    treeParser.getEntryObjectId());
        }

        treeParser = treeParser.next();
    }
    if (!isInsertedInTree) {
        formatter.append(fileName, FileMode.REGULAR_FILE, fileObjectId);
    }
    return formatter;
}