Example usage for org.eclipse.jgit.lib AsyncObjectSizeQueue next

List of usage examples for org.eclipse.jgit.lib AsyncObjectSizeQueue next

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib AsyncObjectSizeQueue next.

Prototype

boolean next() throws MissingObjectException, IOException;

Source Link

Document

Position this queue onto the next available result.

Usage

From source file:org.kuali.student.git.importer.ReportBlobSizePerBranch.java

License:Educational Community License

/**
 * @param args//from w  w w. ja  va2s. co m
 */
public static void main(String[] args) {

    if (args.length != 3 && args.length != 4) {
        System.err.println(
                "USAGE: <git repository> <bare: 0 or 1> <output file name>[<refs prefix: default to refs/heads >]");
        System.exit(-1);
    }

    String gitRepositoryPath = args[0];

    String bareString = args[1].trim();

    boolean bare = false;

    if (bareString.equals("1"))
        bare = true;

    String refPrefix = Constants.R_HEADS;

    String outputFileName = args[2].trim();

    if (args.length == 4)
        refPrefix = args[3].trim();

    try {

        PrintWriter outputWriter = new PrintWriter(outputFileName);
        Repository repo = GitRepositoryUtils.buildFileRepository(new File(gitRepositoryPath).getAbsoluteFile(),
                false, bare);

        Map<String, Ref> branchHeads = repo.getRefDatabase().getRefs(refPrefix);

        ObjectReader objectReader = repo.newObjectReader();

        RevWalk rw = new RevWalk(objectReader);

        TreeWalk tw = new TreeWalk(objectReader);

        tw.setRecursive(true);

        String header = String.format(
                "Branch Name :: Total Commits in Graph :: Total Blob Size in Bytes :: Total Blob Size in Mega Bytes :: Total Blob Size in Giga Bytes");

        System.out.println(header);

        outputWriter.println(header);

        for (Map.Entry<String, Ref> entry : branchHeads.entrySet()) {

            String branchName = entry.getKey();
            Ref branchRef = entry.getValue();

            Set<ObjectId> blobIds = new HashSet<>();

            RevCommit commit = rw.parseCommit(branchRef.getObjectId());

            RevWalk commitHistoryWalk = new RevWalk(objectReader);

            commitHistoryWalk.markStart(commit);

            processCommit(commit, tw, blobIds);

            int totalReachableCommits = 0;

            while ((commit = commitHistoryWalk.next()) != null) {

                processCommit(commit, tw, blobIds);

                totalReachableCommits++;
            }

            long totalSize = 0L;

            AsyncObjectSizeQueue<ObjectId> sq = objectReader.getObjectSize(blobIds, true);

            while (sq.next())
                totalSize += sq.getSize();

            BigDecimal totalCounter = new BigDecimal(totalSize);

            String output = String.format("%s::%d::%s::%s::%s", branchName, totalReachableCommits,
                    totalCounter.toString(), getMB(totalCounter).toString(), getGB(totalCounter).toString());

            System.out.println(output);
            outputWriter.println(output);

            commitHistoryWalk.release();

        }

        tw.release();
        rw.release();
        objectReader.release();

        outputWriter.close();

    } catch (Exception e) {

        log.error("unexpected exception", e);

    }

}