Example usage for org.eclipse.jgit.lib RefComparator sort

List of usage examples for org.eclipse.jgit.lib RefComparator sort

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib RefComparator sort.

Prototype

public static Collection<Ref> sort(Collection<Ref> refs) 

Source Link

Document

Sorts the collection of refs, returning a new collection.

Usage

From source file:com.google.gitiles.RepositoryIndexServlet.java

License:Open Source License

private List<Map<String, String>> getRefs(HttpServletRequest req, String prefix) throws IOException {
    RefDatabase refdb = ServletUtils.getRepository(req).getRefDatabase();
    String repoName = ViewFilter.getView(req).getRepositoryName();
    Collection<Ref> refs = RefComparator.sort(refdb.getRefs(prefix).values());
    List<Map<String, String>> result = Lists.newArrayListWithCapacity(refs.size());

    for (Ref ref : refs) {
        String name = ref.getName().substring(prefix.length());
        boolean needPrefix = !ref.getName().equals(refdb.getRef(name).getName());
        result.add(ImmutableMap.of("url", GitilesView.log().copyFrom(req)
                .setRevision(Revision.unpeeled(needPrefix ? ref.getName() : name, ref.getObjectId())).toUrl(),
                "name", name));
    }//  ww  w .j  ava2 s.c om

    return result;
}

From source file:net.erdfelt.android.sdkfido.git.internal.GitInfo.java

License:Apache License

private static void infoRefs(Repository db) {
    Map<String, Ref> refs = db.getAllRefs();
    System.out.printf("%nAll Refs (%d)%n", refs.size());
    Ref head = refs.get(Constants.HEAD);

    if (head == null) {
        System.out.println(" HEAD ref is dead and/or non-existent?");
        return;//from w ww .  j  a va 2  s  .c  o m
    }

    Map<String, Ref> printRefs = new TreeMap<String, Ref>();

    String current = head.getLeaf().getName();
    if (current.equals(Constants.HEAD)) {
        printRefs.put("(no branch)", head);
    }

    for (Ref ref : RefComparator.sort(refs.values())) {
        String name = ref.getName();
        if (name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_REMOTES)) {
            printRefs.put(name, ref);
        }
    }

    int maxLength = 0;
    for (String name : printRefs.keySet()) {
        maxLength = Math.max(maxLength, name.length());
    }

    System.out.printf("Refs (Heads/Remotes) (%d)%n", printRefs.size());
    for (Entry<String, Ref> e : printRefs.entrySet()) {
        Ref ref = e.getValue();
        ObjectId objectId = ref.getObjectId();
        System.out.printf("%c %-" + maxLength + "s %s%n", (current.equals(ref.getName()) ? '*' : ' '),
                e.getKey(), objectId.abbreviate(ABBREV_LEN).name());
    }
}

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

License:Open Source License

private NSArray<GitRef> filteredRefs(RefFilter filter) {
    NSMutableArray<GitRef> result = new NSMutableArray<GitRef>();

    Map<String, Ref> refs = repository.getAllRefs();

    for (Ref ref : RefComparator.sort(refs.values())) {
        if (filter == null || filter.accepts(ref)) {
            result.addObject(new GitRef(this, ref));
        }/*from   w  w w. ja  v  a  2  s . co  m*/
    }

    return result;
}