Example usage for org.eclipse.jgit.lib ReflogReader getReverseEntries

List of usage examples for org.eclipse.jgit.lib ReflogReader getReverseEntries

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ReflogReader getReverseEntries.

Prototype

List<ReflogEntry> getReverseEntries(int max) throws IOException;

Source Link

Document

Get all reflog entries in reverse order

Usage

From source file:com.google.gerrit.server.project.GetReflog.java

License:Apache License

@Override
public List<ReflogEntryInfo> apply(BranchResource rsrc)
        throws AuthException, ResourceNotFoundException, RepositoryNotFoundException, IOException {
    if (!rsrc.getControl().isOwner()) {
        throw new AuthException("not project owner");
    }/*from   w ww.j av a2  s .c om*/

    try (Repository repo = repoManager.openRepository(rsrc.getNameKey())) {
        ReflogReader r = repo.getReflogReader(rsrc.getRef());
        if (r == null) {
            throw new ResourceNotFoundException(rsrc.getRef());
        }
        List<ReflogEntry> entries;
        if (from == null && to == null) {
            entries = limit > 0 ? r.getReverseEntries(limit) : r.getReverseEntries();
        } else {
            entries = limit > 0 ? new ArrayList<ReflogEntry>(limit) : new ArrayList<ReflogEntry>();
            for (ReflogEntry e : r.getReverseEntries()) {
                Timestamp timestamp = new Timestamp(e.getWho().getWhen().getTime());
                if ((from == null || from.before(timestamp)) && (to == null || to.after(timestamp))) {
                    entries.add(e);
                }
                if (limit > 0 && entries.size() >= limit) {
                    break;
                }
            }
        }
        return Lists.transform(entries, new Function<ReflogEntry, ReflogEntryInfo>() {
            @Override
            public ReflogEntryInfo apply(ReflogEntry e) {
                return new ReflogEntryInfo(e);
            }
        });
    }
}