Example usage for org.eclipse.jgit.lib Constants OBJ_COMMIT

List of usage examples for org.eclipse.jgit.lib Constants OBJ_COMMIT

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants OBJ_COMMIT.

Prototype

int OBJ_COMMIT

To view the source code for org.eclipse.jgit.lib Constants OBJ_COMMIT.

Click Source Link

Document

In-pack object type: commit.

Usage

From source file:org.webcat.core.git.GitRepository.java

License:Open Source License

/**
 * Copies an item from the repository into a container. If the item is a
 * blob, it will be copied into the destination with the specified name; if
 * the item is a tree or commit, its children will be recursively copied.
 *
 * @param objectId the id of the object to copy
 * @param name the destination name to use (only when the item is a blob)
 * @param container the container where the items should be copied
 * @throws IOException if an I/O error occurred
 */// w w  w.  ja  va  2 s. c o  m
public void copyItemToContainer(ObjectId objectId, String name, IWritableContainer container)
        throws IOException {
    int type = typeOfObject(objectId);

    if (type == Constants.OBJ_BLOB) {
        OutputStream fileStream = container.createFile(name, -1);
        writeBlobToStream(objectId, fileStream);
        fileStream.close();
    } else if (type == Constants.OBJ_TREE || type == Constants.OBJ_COMMIT) {
        GitTreeIterator iterator = new GitTreeIterator(this, objectId);

        try {
            for (GitTreeEntry entry : iterator) {
                if (entry.isTree()) {
                    IWritableContainer childContainer = container.createContainer(entry.name());

                    copyItemToContainer(entry.objectId(), entry.name(), childContainer);

                    childContainer.finish();
                } else {
                    copyItemToContainer(entry.objectId(), entry.name(), container);
                }
            }
        } finally {
            iterator.release();
        }
    }
}

From source file:org.webcat.core.git.GitTreeIterator.java

License:Open Source License

/**
 * Creates a new {@code GitTreeIterator} for the specified tree or commit
 * object.//from  w  ww .ja v  a2  s . c  o m
 *
 * @param repository the repository
 * @param treeOrCommitId the id of the tree or commit object
 * @param recursive true if the iterator should be recursive, otherwise
 *     false
 */
public GitTreeIterator(GitRepository repository, ObjectId treeOrCommitId, boolean recursive) {
    this.repository = repository;
    this.recursive = recursive;

    int type = repository.typeOfObject(treeOrCommitId);

    if (type == Constants.OBJ_TREE) {
        initializeFromTree(treeOrCommitId);
    } else if (type == Constants.OBJ_COMMIT || type == Constants.OBJ_TAG) {
        initializeFromCommit(treeOrCommitId);
    } else {
        treeWalk = null;
    }
}

From source file:svnserver.repository.git.GitFile.java

License:GNU General Public License

@NotNull
@Override//from ww  w .j  a  v  a  2 s . co m
default SVNNodeKind getKind() {
    final int objType = getFileMode().getObjectType();
    switch (objType) {
    case Constants.OBJ_TREE:
    case Constants.OBJ_COMMIT:
        return SVNNodeKind.DIR;
    case Constants.OBJ_BLOB:
        return SVNNodeKind.FILE;
    default:
        throw new IllegalStateException("Unknown obj type: " + objType);
    }
}