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

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

Introduction

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

Prototype

public final String getName() 

Source Link

Document

Get string form of the SHA-1, in lower case hexadecimal.

Usage

From source file:Node.java

License:Open Source License

public static Node createNode(RevWalk walk, ObjectId id, boolean recur) throws IOException {
    String key = id.getName();
    RevCommit commit;//from   ww  w  .ja v a 2s  .com
    Node node;

    if (nodeMap.containsKey(key)) {
        // commit node was already mapped
        node = nodeMap.get(key);
    } else {
        // create new commit node
        commit = walk.parseCommit(id);
        node = new Node(key, commit.getAuthorIdent().getEmailAddress(), commit.getCommitTime(),
                commit.getFullMessage(), commit.getShortMessage());
        node.setBackground(new Color(240, 240, 255));
        node.setForeground(new Color(0, 0, 127));

        if (recur) {
            // add parent nodes
            for (ObjectId parentCommit : commit.getParents())
                node.addParent(Node.createNode(walk, parentCommit, recur));
        }
    }

    return node;
}

From source file:br.edu.ifpb.scm.api.loads.LoaderVersions.java

public static void capturaOCodigoDeCadaHashDaArvoreDeArquivos() throws IOException {
    org.eclipse.jgit.api.Git git = org.eclipse.jgit.api.Git.open(PATH);
    try (org.eclipse.jgit.lib.Repository repository = git.getRepository()) {
        // The {tree} will return the underlying tree-id instead of the commit-id itself!
        // For a description of what the carets do see e.g. http://www.paulboxley.com/blog/2011/06/git-caret-and-tilde
        // This means we are selecting the parent of the parent of the parent of the parent of current HEAD and
        // take the tree-ish of it
        //id da tree

        ObjectId oldHead = repository.resolve("HEAD{61c0f8c738b2ae20a91621337bffbfb164f7cc77}");
        ObjectId head = repository.resolve("HEAD^^{tree}");

        //Pegando o codigo de cada commit pra arvore
        System.out.println("Printing diff between tree: " + oldHead.getName() + " and " + head.getName());

    }//from www. j a va2  s.  c  o m
}

From source file:br.edu.ifpb.scm.api.loads.LoaderVersions.java

public static void funcionando(final String commit) throws IOException, GitAPIException {
    org.eclipse.jgit.api.Git git = org.eclipse.jgit.api.Git.open(PATH);
    try (org.eclipse.jgit.lib.Repository repository = git.getRepository()) {
        // The {tree} will return the underlying tree-id instead of the commit-id itself!
        // For a description of what the carets do see e.g. http://www.paulboxley.com/blog/2011/06/git-caret-and-tilde
        // This means we are selecting the parent of the parent of the parent of the parent of current HEAD and
        // take the tree-ish of it
        //id da tree
        // a RevWalk allows to walk over commits based on some filtering that is defined

        ObjectId obj = ObjectId.fromString(commit);
        RevWalk walk = new RevWalk(repository);
        RevCommit revCommit = walk.parseCommit(obj);

        RevCommit[] arra = revCommit.getParents();

        ObjectId obj2 = ObjectId.fromString(arra[0].getName());
        RevWalk walk2 = new RevWalk(repository);
        RevCommit revCommit2 = walk2.parseCommit(obj2);

        ObjectId oldHead = repository.resolve(revCommit2.getTree().getName());
        ObjectId head = repository.resolve(revCommit.getTree().getName());

        //Pegando o codigo de cada commit pra arvore
        System.out.println("Printing diff between tree: " + oldHead.getName() + " and " + head.getName());

        // prepare the two iterators to compute the diff between
        try (ObjectReader reader = repository.newObjectReader()) {
            CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
            oldTreeIter.reset(reader, oldHead);
            CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
            newTreeIter.reset(reader, head);

            // finally get the list of changed files
            try (org.eclipse.jgit.api.Git g = new org.eclipse.jgit.api.Git(repository)) {
                List<DiffEntry> diffs = g.diff().setNewTree(newTreeIter).setOldTree(oldTreeIter).call();
                diffs.stream().forEach((entry) -> {
                    System.out.println("Entry: " + entry);
                });//from  w  w  w . j a  v a 2  s  .  c o m
            }
        }
    }

    System.out.println("Done");

}

From source file:co.turnus.versioning.impl.GitVersioner.java

License:Open Source License

private String getRevision(ObjectId revision) {
    String rev = revision.getName();
    return rev != null ? rev : "";
}

From source file:com.buildautomation.jgit.api.ListFilesOfCommitAndTag.java

License:Apache License

public static void listFilesOfCommitAndTag() throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
        List<String> paths = readElementsAt(repository, "6409ee1597a53c6fbee31edf9cde31dc3afbe20f",
                "src/main/java/org/dstadler/jgit/porcelain");

        System.out.println("Had paths for commit: " + paths);

        final ObjectId testbranch = repository.resolve("testbranch");
        paths = readElementsAt(repository, testbranch.getName(), "src/main/java/org/dstadler/jgit/porcelain");

        System.out.println("Had paths for tag: " + paths);
    }/*  w  w w. ja va  2 s .c o  m*/
}

From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java

License:Apache License

public String getCommit() throws IOException {
    ObjectId head = localRepo.resolve(Constants.HEAD);
    if (head != null)
        return head.getName();
    else/*from ww  w .ja  va 2  s .  c  o m*/
        return null;
}

From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java

License:Apache License

/**
 * Get remote HEAD commit.// w  w  w . j  a v  a2s. c o m
 */
public String getRemoteCommit(String branch) throws Exception {
    fetch();
    ObjectId commit = localRepo.resolve("origin/" + branch);
    if (commit != null)
        return commit.getName();
    else
        return null;
}

From source file:com.chungkwong.jgitgui.Main.java

License:Open Source License

private FlowPane createColumnsChooser(TreeTableView<Object> nav) {
    FlowPane chooser = new FlowPane();
    chooser.getChildren()//w  w  w . j  ava2  s.c om
            .add(createColumnChooser(
                    java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("NAME"),
                    new Callback<TreeTableColumn.CellDataFeatures<Object, String>, ObservableValue<String>>() {
                        @Override
                        public ObservableValue<String> call(
                                TreeTableColumn.CellDataFeatures<Object, String> p) {
                            return new ReadOnlyObjectWrapper<>(p.getValue().toString());
                        }
                    }, true, nav));
    chooser.getChildren()
            .add(createColumnChooser(
                    java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("MESSAGE"),
                    new Callback<TreeTableColumn.CellDataFeatures<Object, String>, ObservableValue<String>>() {
                        @Override
                        public ObservableValue<String> call(
                                TreeTableColumn.CellDataFeatures<Object, String> p) {
                            if (p.getValue() instanceof CommitTreeItem)
                                return new ReadOnlyObjectWrapper<>(
                                        ((RevCommit) p.getValue().getValue()).getShortMessage());
                            else
                                return new ReadOnlyObjectWrapper<>("");
                        }
                    }, false, nav));
    chooser.getChildren()
            .add(createColumnChooser(
                    java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("AUTHOR"),
                    new Callback<TreeTableColumn.CellDataFeatures<Object, String>, ObservableValue<String>>() {
                        @Override
                        public ObservableValue<String> call(
                                TreeTableColumn.CellDataFeatures<Object, String> p) {
                            if (p.getValue() instanceof CommitTreeItem)
                                return new ReadOnlyObjectWrapper<>(((RevCommit) p.getValue().getValue())
                                        .getAuthorIdent().toExternalString());
                            else
                                return new ReadOnlyObjectWrapper<>("");
                        }
                    }, false, nav));
    chooser.getChildren()
            .add(createColumnChooser(
                    java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("COMMITTER"),
                    new Callback<TreeTableColumn.CellDataFeatures<Object, String>, ObservableValue<String>>() {
                        @Override
                        public ObservableValue<String> call(
                                TreeTableColumn.CellDataFeatures<Object, String> p) {
                            if (p.getValue() instanceof CommitTreeItem)
                                return new ReadOnlyObjectWrapper<>(((RevCommit) p.getValue().getValue())
                                        .getCommitterIdent().toExternalString());
                            else
                                return new ReadOnlyObjectWrapper<>("");
                        }
                    }, false, nav));
    chooser.getChildren()
            .add(createColumnChooser(
                    java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("TIME"),
                    new Callback<TreeTableColumn.CellDataFeatures<Object, String>, ObservableValue<String>>() {
                        @Override
                        public ObservableValue<String> call(
                                TreeTableColumn.CellDataFeatures<Object, String> p) {
                            if (p.getValue() instanceof CommitTreeItem)
                                return new ReadOnlyObjectWrapper<>(
                                        timeToString(((RevCommit) p.getValue().getValue()).getCommitTime()));
                            else
                                return new ReadOnlyObjectWrapper<>("");
                        }
                    }, false, nav));
    chooser.getChildren()
            .add(createColumnChooser(
                    java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("REFERNECE"),
                    new Callback<TreeTableColumn.CellDataFeatures<Object, String>, ObservableValue<String>>() {
                        @Override
                        public ObservableValue<String> call(
                                TreeTableColumn.CellDataFeatures<Object, String> p) {
                            if (p.getValue() instanceof CommitTreeItem) {
                                ObjectId id = ((RevCommit) p.getValue().getValue()).getId();
                                return new ReadOnlyObjectWrapper<>(id == null ? "" : id.getName());
                            } else if (p.getValue() instanceof BranchTreeItem) {
                                ObjectId id = ((Ref) p.getValue().getValue()).getLeaf().getObjectId();
                                return new ReadOnlyObjectWrapper<>(id == null ? "" : id.getName());
                            } else if (p.getValue() instanceof TagTreeItem) {
                                ObjectId id = ((Ref) p.getValue().getValue()).getTarget().getLeaf()
                                        .getObjectId();
                                return new ReadOnlyObjectWrapper<>(id == null ? "" : id.getName());
                            } else
                                return new ReadOnlyObjectWrapper<>("");
                        }
                    }, false, nav));
    chooser.getChildren()
            .add(createColumnChooser(
                    java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("URI"),
                    new Callback<TreeTableColumn.CellDataFeatures<Object, String>, ObservableValue<String>>() {
                        @Override
                        public ObservableValue<String> call(
                                TreeTableColumn.CellDataFeatures<Object, String> p) {
                            if (p.getValue() instanceof RemoteTreeItem) {
                                String uris = ((RemoteConfig) p.getValue().getValue()).getURIs().stream()
                                        .map((url) -> url.toString()).collect(Collectors.joining(" "));
                                return new ReadOnlyObjectWrapper<>(uris);
                            } else
                                return new ReadOnlyObjectWrapper<>("");
                        }
                    }, false, nav));

    return chooser;
}

From source file:com.gitblit.utils.CommitCache.java

License:Apache License

/**
 * Returns a list of commits for the specified repository branch since the specified commit.
 *
 * @param repositoryName//from w ww  .j a  v  a  2s.c  o m
 * @param repository
 * @param branch
 * @param sinceCommit
 * @return a list of commits
 */
protected List<RepositoryCommit> get(String repositoryName, Repository repository, String branch,
        ObjectId sinceCommit) {
    Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, false);
    List<RevCommit> revLog = JGitUtils.getRevLog(repository, sinceCommit.getName(), branch);
    List<RepositoryCommit> commits = new ArrayList<RepositoryCommit>(revLog.size());
    for (RevCommit commit : revLog) {
        RepositoryCommit commitModel = new RepositoryCommit(repositoryName, branch, commit);
        List<RefModel> commitRefs = allRefs.get(commitModel.getId());
        commitModel.setRefs(commitRefs);
        commits.add(commitModel);
    }
    return commits;
}

From source file:com.gitblit.utils.JGitUtils.java

License:Apache License

/**
 * Returns the list of files changed in a specified commit. If the
 * repository does not exist or is empty, an empty list is returned.
 *
 * @param repository/*  w w w. j  av  a  2 s  . c om*/
 * @param commit
 *            if null, HEAD is assumed.
 * @param calculateDiffStat
 *            if true, each PathChangeModel will have insertions/deletions
 * @return list of files changed in a commit
 */
public static List<PathChangeModel> getFilesInCommit(Repository repository, RevCommit commit,
        boolean calculateDiffStat) {
    List<PathChangeModel> list = new ArrayList<PathChangeModel>();
    if (!hasCommits(repository)) {
        return list;
    }
    RevWalk rw = new RevWalk(repository);
    try {
        if (commit == null) {
            ObjectId object = getDefaultBranch(repository);
            commit = rw.parseCommit(object);
        }

        if (commit.getParentCount() == 0) {
            TreeWalk tw = new TreeWalk(repository);
            tw.reset();
            tw.setRecursive(true);
            tw.addTree(commit.getTree());
            while (tw.next()) {
                long size = 0;
                FilestoreModel filestoreItem = null;
                ObjectId objectId = tw.getObjectId(0);

                try {
                    if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) {

                        size = tw.getObjectReader().getObjectSize(objectId, Constants.OBJ_BLOB);

                        if (isPossibleFilestoreItem(size)) {
                            filestoreItem = getFilestoreItem(tw.getObjectReader().open(objectId));
                        }
                    }
                } catch (Throwable t) {
                    error(t, null, "failed to retrieve blob size for " + tw.getPathString());
                }

                list.add(new PathChangeModel(tw.getPathString(), tw.getPathString(), filestoreItem, size,
                        tw.getRawMode(0), objectId.getName(), commit.getId().getName(), ChangeType.ADD));
            }
            tw.close();
        } else {
            RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
            DiffStatFormatter df = new DiffStatFormatter(commit.getName(), repository);
            df.setRepository(repository);
            df.setDiffComparator(RawTextComparator.DEFAULT);
            df.setDetectRenames(true);
            List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
            for (DiffEntry diff : diffs) {
                // create the path change model
                PathChangeModel pcm = PathChangeModel.from(diff, commit.getName(), repository);

                if (calculateDiffStat) {
                    // update file diffstats
                    df.format(diff);
                    PathChangeModel pathStat = df.getDiffStat().getPath(pcm.path);
                    if (pathStat != null) {
                        pcm.insertions = pathStat.insertions;
                        pcm.deletions = pathStat.deletions;
                    }
                }
                list.add(pcm);
            }
        }
    } catch (Throwable t) {
        error(t, repository, "{0} failed to determine files in commit!");
    } finally {
        rw.dispose();
    }
    return list;
}