Example usage for org.eclipse.jgit.lib ObjectId toString

List of usage examples for org.eclipse.jgit.lib ObjectId toString

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ObjectId toString.

Prototype

public static final String toString(ObjectId i) 

Source Link

Document

Convert an ObjectId into a hex string representation.

Usage

From source file:jbenchmarker.trace.git.model.Commit.java

License:Open Source License

public Commit(RevCommit co, Set<String> children) {
    this(ObjectId.toString(co), co, children);
}

From source file:jbenchmarker.trace.git.model.Patch.java

License:Open Source License

/**
 * Classical diff constructor.//from w w w. j  a  v  a  2s . c o m
 * @param commit
 * @param parent
 * @param listEdit 
 */
public Patch(Commit commit, RevCommit parent, List<FileEdition> listEdit) {
    this.edits = listEdit;
    this.id = commit.getId() + ObjectId.toString(parent);
}

From source file:net.riezebos.thoth.content.impl.GitContentManager.java

License:Apache License

protected Commit getCommit(Repository repository, RevCommit revCommit, String path)
        throws MissingObjectException, IncorrectObjectTypeException, IOException, UnsupportedEncodingException {
    path = ThothUtil.stripPrefix(path, "/");

    Commit commit = new Commit();
    commit.setAuthor(revCommit.getAuthorIdent().getName());
    commit.setTimestamp(new Date(((long) revCommit.getCommitTime()) * 1000));
    commit.setMessage(revCommit.getFullMessage());
    commit.setShortMessage(revCommit.getShortMessage());
    commit.setId(ObjectId.toString(revCommit.getId()));

    try (RevWalk revWalk = new RevWalk(repository); SimpleDiffFormatter df = new SimpleDiffFormatter()) {
        RevCommit[] parents = revCommit.getParents();
        if (parents != null && parents.length > 0) {
            RevCommit parent = revWalk.parseCommit(parents[0].getId());
            df.setRepository(repository);
            df.setDiffComparator(RawTextComparator.DEFAULT);
            df.setDetectRenames(true);// w w w .j ava 2 s  . c o  m
            List<DiffEntry> diffs = df.scan(parent.getTree(), revCommit.getTree());
            for (DiffEntry diff : diffs) {
                if (path == null || path.equals(diff.getNewPath()) || path.equals(diff.getOldPath())) {
                    Revision fileRevision = createFileRevision(diff, df, revCommit);
                    commit.addRevision(fileRevision);
                }
            }
        } else {
            // Initial version; no parent
            try (TreeWalk treeWalk = new TreeWalk(repository)) {
                RevTree tree = revCommit.getTree();
                treeWalk.addTree(tree);
                treeWalk.setRecursive(true);
                treeWalk.setFilter(PathFilter.create(path));
                if (treeWalk.next()) {
                    Revision fileRevision = new Revision(Action.ADD, path);
                    fileRevision.setCommitId(ObjectId.toString(revCommit.getId()) + "/" + path);
                    commit.addRevision(fileRevision);
                }
            }
        }
    }
    return commit;
}

From source file:net.riezebos.thoth.content.impl.GitContentManager.java

License:Apache License

protected Revision createFileRevision(DiffEntry diff, SimpleDiffFormatter df, RevCommit revCommit)
        throws IOException, UnsupportedEncodingException {
    Action action = translateAction(diff.getChangeType());
    Revision fileRevision = new Revision(action,
            action.equals(Action.DELETE) ? diff.getOldPath() : diff.getNewPath());
    fileRevision.setMessage(revCommit.getFullMessage());
    fileRevision.setCommitId(ObjectId.toString(revCommit.getId()) + "/" + diff.getNewPath());
    return fileRevision;
}

From source file:org.debian.dependency.sources.JGitSource.java

License:Apache License

private void setupRepo() throws GitAPIException, IOException {
    if (git.status().call().hasUncommittedChanges()) {
        throw new IllegalStateException("Uncommitted changes detected in tree. Remove before continuing.");
    }/* w  w w . j a  v  a  2  s. c o m*/

    Ref branchRef = null;
    for (Ref ref : git.branchList().call()) {
        if (WORK_BRANCH.equals(Repository.shortenRefName(ref.getName()))) {
            branchRef = ref;
            break;
        }
    }

    // assume its setup correctly if its there
    if (branchRef != null) {
        return;
    }

    // assume the current branch is the correct one
    Ref headRef = git.getRepository().getRef(Constants.HEAD).getLeaf();
    try {
        // detach head so we don't modify any existing branches
        git.checkout().setName(ObjectId.toString(headRef.getObjectId())).call();

        removeFilesEndsWith(".class", COMMIT_MESSAGE_PREFIX + " Removing class files");
        RevCommit newRef = removeFilesEndsWith(".jar", COMMIT_MESSAGE_PREFIX + " Removing jar files");

        // now all automated setup routines have been accomplished
        git.branchCreate().setName(WORK_BRANCH).setStartPoint(newRef).call();
    } finally {
        // failsafe
        git.getRepository().updateRef(Constants.HEAD).link(headRef.getName());
    }
}

From source file:org.eclipse.egit.ui.internal.reflog.command.CopyHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    Repository repo = getRepository(event);
    RevCommit commit = getSelectedCommit(event, repo);
    if (commit != null) {
        Clipboard clipboard = new Clipboard(null);
        try {// w w w. j a  va 2 s.c o m
            TextTransfer textTransfer = TextTransfer.getInstance();
            Transfer[] transfers = new Transfer[] { textTransfer };
            Object[] data = new Object[] { ObjectId.toString(commit) };
            clipboard.setContents(data, transfers);
        } finally {
            clipboard.dispose();
        }
    }
    return null;
}

From source file:org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider.java

License:Open Source License

public StyledString getStyledText(Object element) {
    if (!(element instanceof RepositoryTreeNode))
        return null;

    RepositoryTreeNode node = (RepositoryTreeNode) element;

    try {//from w w  w . j a v  a2 s .  c om
        switch (node.getType()) {
        case REPO:
            Repository repository = (Repository) node.getObject();
            File directory = repository.getDirectory();
            StyledString string = new StyledString(directory.getParentFile().getName());
            string.append(" - " + directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
            String branch = repository.getBranch();
            if (repository.getRepositoryState() != RepositoryState.SAFE)
                branch += " - " + repository.getRepositoryState().getDescription(); //$NON-NLS-1$
            string.append(" [" + branch + "]", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$//$NON-NLS-2$
            return string;
        case ADDITIONALREF:
            Ref ref = (Ref) node.getObject();
            // shorten the name
            StyledString refName = new StyledString(Repository.shortenRefName(ref.getName()));
            if (ref.isSymbolic()) {
                refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
                refName.append(ref.getLeaf().getName(), StyledString.QUALIFIER_STYLER);
                refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
                refName.append(ObjectId.toString(ref.getLeaf().getObjectId()), StyledString.QUALIFIER_STYLER);
            } else {
                refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
                refName.append(ObjectId.toString(ref.getObjectId()), StyledString.QUALIFIER_STYLER);

            }
            return refName;
        case WORKINGDIR:
            StyledString dirString = new StyledString(UIText.RepositoriesView_WorkingDir_treenode);
            dirString.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
            if (node.getRepository().isBare()) {
                dirString.append(UIText.RepositoriesViewLabelProvider_BareRepositoryMessage,
                        StyledString.QUALIFIER_STYLER);
            } else {
                dirString.append(node.getRepository().getWorkTree().getAbsolutePath(),
                        StyledString.QUALIFIER_STYLER);
            }
            return dirString;
        case PUSH:
            // fall through
        case FETCH:
            // fall through
        case FILE:
            // fall through
        case FOLDER:
            // fall through
        case BRANCHES:
            // fall through
        case LOCAL:
            // fall through
        case REMOTETRACKING:
            // fall through
        case BRANCHHIERARCHY:
            // fall through
        case TAGS:
            // fall through;
        case ADDITIONALREFS:
            // fall through
        case REMOTES:
            // fall through
        case REMOTE:
            // fall through
        case ERROR:
            // fall through
        case REF:
            // fall through
        case TAG: {
            String label = getSimpleText(node);
            if (label != null)
                return new StyledString(label);
        }

        }
    } catch (IOException e) {
        Activator.logError(e.getMessage(), e);
    }

    return null;

}

From source file:org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider.java

License:Open Source License

private String getSimpleText(RepositoryTreeNode node) {
    switch (node.getType()) {
    case REPO:/*from ww w.  j a va  2s.  co m*/
        File directory = ((Repository) node.getObject()).getDirectory();
        StringBuilder sb = new StringBuilder();
        sb.append(directory.getParentFile().getName());
        sb.append(" - "); //$NON-NLS-1$
        sb.append(directory.getAbsolutePath());
        return sb.toString();
    case FILE:
        // fall through
    case FOLDER:
        return ((File) node.getObject()).getName();
    case BRANCHES:
        return UIText.RepositoriesView_Branches_Nodetext;
    case LOCAL:
        return UIText.RepositoriesViewLabelProvider_LocalNodetext;
    case REMOTETRACKING:
        return UIText.RepositoriesViewLabelProvider_RemoteTrackingNodetext;
    case BRANCHHIERARCHY:
        IPath fullPath = (IPath) node.getObject();
        return fullPath.lastSegment();
    case TAGS:
        return UIText.RepositoriesViewLabelProvider_TagsNodeText;
    case ADDITIONALREFS:
        return UIText.RepositoriesViewLabelProvider_SymbolicRefNodeText;
    case REMOTES:
        return UIText.RepositoriesView_RemotesNodeText;
    case REF:
        // fall through
    case TAG: {
        Ref ref = (Ref) node.getObject();
        // shorten the name
        String refName = Repository.shortenRefName(ref.getName());
        if (node.getParent().getType() == RepositoryTreeNodeType.BRANCHHIERARCHY) {
            int index = refName.lastIndexOf('/');
            refName = refName.substring(index + 1);
        }
        return refName;
    }
    case ADDITIONALREF: {
        Ref ref = (Ref) node.getObject();
        // shorten the name
        String refName = Repository.shortenRefName(ref.getName());
        if (ref.isSymbolic()) {
            refName = refName + " - " //$NON-NLS-1$
                    + ref.getLeaf().getName() + " - " + ObjectId.toString(ref.getLeaf().getObjectId()); //$NON-NLS-1$
        } else {
            refName = refName + " - " //$NON-NLS-1$
                    + ObjectId.toString(ref.getObjectId());
        }
        return refName;
    }
    case WORKINGDIR:
        if (node.getRepository().isBare())
            return UIText.RepositoriesView_WorkingDir_treenode + " - " //$NON-NLS-1$
                    + UIText.RepositoriesViewLabelProvider_BareRepositoryMessage;
        else
            return UIText.RepositoriesView_WorkingDir_treenode + " - " //$NON-NLS-1$
                    + node.getRepository().getWorkTree().getAbsolutePath();
    case REMOTE:
        // fall through
    case PUSH:
        // fall through
    case FETCH:
        // fall through
    case ERROR:
        return (String) node.getObject();

    }
    return null;
}