Example usage for org.eclipse.jgit.lib RefDatabase ALL

List of usage examples for org.eclipse.jgit.lib RefDatabase ALL

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib RefDatabase ALL.

Prototype

String ALL

To view the source code for org.eclipse.jgit.lib RefDatabase ALL.

Click Source Link

Document

Magic value for #getRefsByPrefix(String) to return all references.

Usage

From source file:com.google.gerrit.server.ChangeUtil.java

License:Apache License

public static PatchSet.Id nextPatchSetId(Repository git, PatchSet.Id id) throws IOException {
    return nextPatchSetId(git.getRefDatabase().getRefs(RefDatabase.ALL), id);
}

From source file:com.google.gerrit.server.git.TagSet.java

License:Apache License

void build(Repository git, TagSet old, TagMatcher m) {
    if (old != null && m != null && refresh(old, m)) {
        return;/*from ww w  . j  a v  a  2s  . c om*/
    }

    try (TagWalk rw = new TagWalk(git)) {
        rw.setRetainBody(false);
        for (Ref ref : git.getRefDatabase().getRefs(RefDatabase.ALL).values()) {
            if (skip(ref)) {
                continue;

            } else if (isTag(ref)) {
                // For a tag, remember where it points to.
                addTag(rw, git.peel(ref));

            } else {
                // New reference to include in the set.
                addRef(rw, ref);
            }
        }

        // Traverse the complete history. Copy any flags from a commit to
        // all of its ancestors. This automatically updates any Tag object
        // as the TagCommit and the stored Tag object share the same
        // underlying bit set.
        TagCommit c;
        while ((c = (TagCommit) rw.next()) != null) {
            BitSet mine = c.refFlags;
            int pCnt = c.getParentCount();
            for (int pIdx = 0; pIdx < pCnt; pIdx++) {
                ((TagCommit) c.getParent(pIdx)).refFlags.or(mine);
            }
        }
    } catch (IOException e) {
        log.warn("Error building tags for repository " + projectName, e);
    }
}

From source file:com.google.gerrit.server.git.VisibleRefFilter.java

License:Apache License

@Override
protected Map<String, Ref> getAdvertisedRefs(Repository repository, RevWalk revWalk)
        throws ServiceMayNotContinueException {
    try {/*www . j  av  a  2 s .c om*/
        return filter(repository.getRefDatabase().getRefs(RefDatabase.ALL));
    } catch (ServiceMayNotContinueException e) {
        throw e;
    } catch (IOException e) {
        ServiceMayNotContinueException ex = new ServiceMayNotContinueException();
        ex.initCause(e);
        throw ex;
    }
}

From source file:com.google.gerrit.sshd.commands.Receive.java

License:Apache License

@Override
protected void runImpl() throws IOException, Failure {
    if (!projectControl.canRunReceivePack()) {
        throw new Failure(1, "fatal: receive-pack not permitted on this server");
    }//from w  ww  .  j av  a 2s .  c om

    final ReceiveCommits receive = factory.create(projectControl, repo).getReceiveCommits();

    Capable r = receive.canUpload();
    if (r != Capable.OK) {
        throw new UnloggedFailure(1, "\nfatal: " + r.getMessage());
    }

    verifyProjectVisible("reviewer", reviewerId);
    verifyProjectVisible("CC", ccId);

    receive.addReviewers(reviewerId);
    receive.addExtraCC(ccId);

    final ReceivePack rp = receive.getReceivePack();
    rp.setRefLogIdent(currentUser.newRefLogIdent());
    rp.setTimeout(config.getTimeout());
    rp.setMaxObjectSizeLimit(config.getEffectiveMaxObjectSizeLimit(projectControl.getProjectState()));
    init(rp);
    rp.setPostReceiveHook(PostReceiveHookChain.newChain(Lists.newArrayList(postReceiveHooks)));
    try {
        rp.receive(in, out, err);
    } catch (UnpackException badStream) {
        // In case this was caused by the user pushing an object whose size
        // is larger than the receive.maxObjectSizeLimit gerrit.config parameter
        // we want to present this error to the user
        if (badStream.getCause() instanceof TooLargeObjectInPackException) {
            StringBuilder msg = new StringBuilder();
            msg.append("Receive error on project \"").append(projectControl.getProject().getName())
                    .append("\"");
            msg.append(" (user ");
            msg.append(currentUser.getAccount().getUserName());
            msg.append(" account ");
            msg.append(currentUser.getAccountId());
            msg.append("): ");
            msg.append(badStream.getCause().getMessage());
            log.info(msg.toString());
            throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage());
        }

        // This may have been triggered by branch level access controls.
        // Log what the heck is going on, as detailed as we can.
        //
        StringBuilder msg = new StringBuilder();
        msg.append("Unpack error on project \"").append(projectControl.getProject().getName()).append("\":\n");

        msg.append("  AdvertiseRefsHook: ").append(rp.getAdvertiseRefsHook());
        if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) {
            msg.append("DEFAULT");
        } else if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) {
            msg.append("VisibleRefFilter");
        } else {
            msg.append(rp.getAdvertiseRefsHook().getClass());
        }
        msg.append("\n");

        if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) {
            Map<String, Ref> adv = rp.getAdvertisedRefs();
            msg.append("  Visible references (").append(adv.size()).append("):\n");
            for (Ref ref : adv.values()) {
                msg.append("  - ").append(ref.getObjectId().abbreviate(8).name()).append(" ")
                        .append(ref.getName()).append("\n");
            }

            Map<String, Ref> allRefs = rp.getRepository().getRefDatabase().getRefs(RefDatabase.ALL);
            List<Ref> hidden = new ArrayList<>();
            for (Ref ref : allRefs.values()) {
                if (!adv.containsKey(ref.getName())) {
                    hidden.add(ref);
                }
            }

            msg.append("  Hidden references (").append(hidden.size()).append("):\n");
            for (Ref ref : hidden) {
                msg.append("  - ").append(ref.getObjectId().abbreviate(8).name()).append(" ")
                        .append(ref.getName()).append("\n");
            }
        }

        IOException detail = new IOException(msg.toString(), badStream);
        throw new Failure(128, "fatal: Unpack error, check server log", detail);
    }
}

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

License:Open Source License

private static Map<String, Ref> getRefs(RefDatabase refdb, String path) throws IOException {
    path = GitilesView.maybeTrimLeadingAndTrailingSlash(path);
    if (path.isEmpty()) {
        return refdb.getRefs(RefDatabase.ALL);
    }/*w ww  .  j a v  a  2s.  com*/
    path = Constants.R_REFS + path;
    Ref singleRef = refdb.getRef(path);
    if (singleRef != null) {
        return ImmutableMap.of(singleRef.getName(), singleRef);
    }
    return refdb.getRefs(path + '/');
}

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

License:Open Source License

private boolean isVisible(Repository repo, RevWalk walk, ObjectId id) throws IOException {
    RevCommit commit;/*from ww w .  j a  v a  2 s  .  c  o m*/
    try {
        commit = walk.parseCommit(id);
    } catch (IncorrectObjectTypeException e) {
        return false;
    }

    // If any reference directly points at the requested object, permit display.
    // Common for displays of pending patch sets in Gerrit Code Review, or
    // bookmarks to the commit a tag points at.
    Collection<Ref> allRefs = repo.getRefDatabase().getRefs(RefDatabase.ALL).values();
    for (Ref ref : allRefs) {
        ref = repo.getRefDatabase().peel(ref);
        if (id.equals(ref.getObjectId()) || id.equals(ref.getPeeledObjectId())) {
            return true;
        }
    }

    // Check heads first under the assumption that most requests are for refs
    // close to a head. Tags tend to be much further back in history and just
    // clutter up the priority queue in the common case.
    return isReachableFrom(walk, commit, filter(allRefs, refStartsWith(Constants.R_HEADS)))
            || isReachableFrom(walk, commit, filter(allRefs, refStartsWith(Constants.R_TAGS)))
            || isReachableFrom(walk, commit, filter(allRefs, not(refStartsWith("refs/changes/"))));
}

From source file:com.microsoft.gittf.core.util.RepositoryUtil.java

License:Open Source License

public static boolean isEmptyRepository(final Repository repository) throws IOException {
    final RefDatabase refsDB = repository.getRefDatabase();
    final Map<String, Ref> refs = refsDB.getRefs(RefDatabase.ALL);
    return refs.isEmpty();
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitServerUtil.java

License:Apache License

/**
 * Check all refs successfully updated, throws exception if they are not
 * @param result fetch result/*from  www  . j a v  a  2s .  c  o m*/
 * @throws VcsException if any ref was not successfully updated
 */
public static void checkFetchSuccessful(Repository db, FetchResult result) throws VcsException {
    for (TrackingRefUpdate update : result.getTrackingRefUpdates()) {
        String localRefName = update.getLocalName();
        RefUpdate.Result status = update.getResult();
        if (status == RefUpdate.Result.REJECTED || status == RefUpdate.Result.LOCK_FAILURE
                || status == RefUpdate.Result.IO_FAILURE) {
            if (status == RefUpdate.Result.LOCK_FAILURE) {
                TreeSet<String> caseSensitiveConflicts = new TreeSet<>();
                TreeSet<String> conflicts = new TreeSet<>();
                try {
                    OSInfo.OSType os = OSInfo.getOSType();
                    if (os == OSInfo.OSType.WINDOWS || os == OSInfo.OSType.MACOSX) {
                        Set<String> refNames = db.getRefDatabase().getRefs(RefDatabase.ALL).keySet();
                        for (String ref : refNames) {
                            if (!localRefName.equals(ref) && localRefName.equalsIgnoreCase(ref))
                                caseSensitiveConflicts.add(ref);
                        }
                    }
                    conflicts.addAll(db.getRefDatabase().getConflictingNames(localRefName));
                } catch (Exception e) {
                    //ignore
                }
                String msg;
                if (!conflicts.isEmpty()) {
                    msg = "Failed to fetch ref " + localRefName + ": it clashes with "
                            + StringUtil.join(", ", conflicts)
                            + ". Please remove conflicting refs from repository.";
                } else if (!caseSensitiveConflicts.isEmpty()) {
                    msg = "Failed to fetch ref " + localRefName
                            + ": on case-insensitive file system it clashes with "
                            + StringUtil.join(", ", caseSensitiveConflicts)
                            + ". Please remove conflicting refs from repository.";
                } else {
                    msg = "Fail to update '" + localRefName + "' (" + status.name() + ")";
                }
                throw new VcsException(msg);
            } else {
                throw new VcsException("Fail to update '" + localRefName + "' (" + status.name() + ")");
            }
        }
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitServerUtil.java

License:Apache License

public static boolean isCloned(@NotNull Repository db) throws VcsException, IOException {
    if (!db.getObjectDatabase().exists())
        return false;
    ObjectReader reader = db.getObjectDatabase().newReader();
    try {/*from  w  w w.ja v a 2 s .  c o  m*/
        for (Ref ref : db.getRefDatabase().getRefs(RefDatabase.ALL).values()) {
            if (reader.has(ref.getObjectId()))
                return true;
        }
    } finally {
        reader.release();
    }
    return false;
}

From source file:kr.re.ec.grigit.graph.ui.RevWalker.java

License:Eclipse Distribution License

public void init() throws Exception {

    logger = LoggerFactory.getLogger(RevWalker.class);

    db = CurrentRepository.getInstance().getRepository();

    walk = createWalk();/*from   ww w .jav  a2 s. c o  m*/
    for (final RevSort s : sorting)
        walk.sort(s, true);
    /*
    if (pathFilter == TreeFilter.ALL) {
       if (followPath != null)
    walk.setTreeFilter(FollowFilter.create(followPath, db
          .getConfig().get(DiffConfig.KEY)));
    } else if (pathFilter != TreeFilter.ALL) {
       walk.setTreeFilter(AndTreeFilter.create(pathFilter,
       TreeFilter.ANY_DIFF));
    }*/

    if (revLimiter.size() == 1)
        walk.setRevFilter(revLimiter.get(0));
    else if (revLimiter.size() > 1)
        walk.setRevFilter(AndRevFilter.create(revLimiter));

    if (all) {
        Map<String, Ref> refs = db.getRefDatabase().getRefs(RefDatabase.ALL);
        for (Ref a : refs.values()) {
            ObjectId oid = a.getPeeledObjectId();
            if (oid == null)
                oid = a.getObjectId();
            try {
                commits.add(walk.parseCommit(oid));
            } catch (IncorrectObjectTypeException e) {
                // Ignore all refs which are not commits
            }
        }
    }

    if (commits.isEmpty()) {
        final ObjectId head = db.resolve(Constants.HEAD);
        if (head == null)
            //logger.info(MessageFormat.format(CLIText.get().cannotResolve,
            //   Constants.HEAD));
            commits.add(walk.parseCommit(head));
    }
    for (final RevCommit c : commits) {
        final RevCommit real = argWalk == walk ? c : walk.parseCommit(c);
        if (c.has(RevFlag.UNINTERESTING))
            walk.markUninteresting(real);
        else
            walk.markStart(real);
    }

    //final long start = System.currentTimeMillis();
    //logger.info("i'm here1");
    final int n = walkLoop();
    //logger.info("i'm here2");
    if (count) {
        //final long end = System.currentTimeMillis();
        logger.info("" + n);
        logger.info(" ");
        //   logger.info(MessageFormat.format(CLIText.get().timeInMilliSeconds,
        //      Long.valueOf(end - start)));
    }
}