List of usage examples for org.eclipse.jgit.lib Ref getLeaf
@NonNull Ref getLeaf();
From source file:com.genuitec.eclipse.gerrit.tools.internal.fbranches.commands.MergeStableIntoCurrentBranchCommand.java
License:Open Source License
private boolean canMerge(final Repository repository) { String message = null;//www . j av a 2 s .c om Exception ex = null; try { Ref head = repository.getRef(Constants.HEAD); if (head == null || !head.isSymbolic()) message = UIText.MergeAction_HeadIsNoBranch; else if (!repository.getRepositoryState().equals(RepositoryState.SAFE)) message = NLS.bind(UIText.MergeAction_WrongRepositoryState, repository.getRepositoryState()); else if (!head.getLeaf().getName().startsWith("refs/heads/features")) { //$NON-NLS-1$ message = "Current branch is not a feature branch."; } } catch (IOException e) { message = e.getMessage(); ex = e; } if (message != null) org.eclipse.egit.ui.Activator.handleError(message, ex, true); return (message == null); }
From source file:com.google.gerrit.httpd.rpc.project.ListBranchesTest.java
License:Apache License
private Set<String> targets(Map<String, Ref> refs) { Set<String> targets = new HashSet<String>(); for (Ref ref : refs.values()) { if (ref.isSymbolic()) { targets.add(ref.getLeaf().getName()); }/* ww w. j a v a2 s . c o m*/ } return targets; }
From source file:com.google.gerrit.httpd.rpc.project.ProjectDetailFactory.java
License:Apache License
@Override public ProjectDetail call() throws NoSuchProjectException, IOException { final ProjectControl pc = projectControlFactory.validateFor(projectName, ProjectControl.OWNER | ProjectControl.VISIBLE); final ProjectState projectState = pc.getProjectState(); final ProjectDetail detail = new ProjectDetail(); detail.setProject(projectState.getProject()); final boolean userIsOwner = pc.isOwner(); final boolean userIsOwnerAnyRef = pc.isOwnerAnyRef(); detail.setCanModifyAccess(userIsOwnerAnyRef); detail.setCanModifyAgreements(userIsOwner); detail.setCanModifyDescription(userIsOwner); detail.setCanModifyMergeType(userIsOwner); detail.setCanModifyState(userIsOwner); final InheritedBoolean useContributorAgreements = new InheritedBoolean(); final InheritedBoolean useSignedOffBy = new InheritedBoolean(); final InheritedBoolean useContentMerge = new InheritedBoolean(); final InheritedBoolean requireChangeID = new InheritedBoolean(); useContributorAgreements.setValue(projectState.getProject().getUseContributorAgreements()); useSignedOffBy.setValue(projectState.getProject().getUseSignedOffBy()); useContentMerge.setValue(projectState.getProject().getUseContentMerge()); requireChangeID.setValue(projectState.getProject().getRequireChangeID()); ProjectState parentState = Iterables.getFirst(projectState.parents(), null); if (parentState != null) { useContributorAgreements.setInheritedValue(parentState.isUseContributorAgreements()); useSignedOffBy.setInheritedValue(parentState.isUseSignedOffBy()); useContentMerge.setInheritedValue(parentState.isUseContentMerge()); requireChangeID.setInheritedValue(parentState.isRequireChangeID()); }/*from w w w. ja v a2 s. c om*/ detail.setUseContributorAgreements(useContributorAgreements); detail.setUseSignedOffBy(useSignedOffBy); detail.setUseContentMerge(useContentMerge); detail.setRequireChangeID(requireChangeID); final Project.NameKey projectName = projectState.getProject().getNameKey(); Repository git; try { git = gitRepositoryManager.openRepository(projectName); } catch (RepositoryNotFoundException err) { throw new NoSuchProjectException(projectName); } try { Ref head = git.getRef(Constants.HEAD); if (head != null && head.isSymbolic() && GitRepositoryManager.REF_CONFIG.equals(head.getLeaf().getName())) { detail.setPermissionOnly(true); } } catch (IOException err) { throw new NoSuchProjectException(projectName); } finally { git.close(); } return detail; }
From source file:com.google.gerrit.server.git.VisibleRefFilter.java
License:Apache License
public Map<String, Ref> filter(Map<String, Ref> refs, boolean filterTagsSeparately) { if (projectCtl.allRefsAreVisible(ImmutableSet.of(RefNames.REFS_CONFIG))) { Map<String, Ref> r = Maps.newHashMap(refs); if (!projectCtl.controlForRef(RefNames.REFS_CONFIG).isVisible()) { r.remove(RefNames.REFS_CONFIG); }// w ww .j av a 2 s.c o m return r; } Account.Id currAccountId; boolean canViewMetadata; if (projectCtl.getCurrentUser().isIdentifiedUser()) { IdentifiedUser user = ((IdentifiedUser) projectCtl.getCurrentUser()); currAccountId = user.getAccountId(); canViewMetadata = user.getCapabilities().canAccessDatabase(); } else { currAccountId = null; canViewMetadata = false; } Set<Change.Id> visibleChanges = visibleChanges(); Map<String, Ref> result = new HashMap<>(); List<Ref> deferredTags = new ArrayList<>(); for (Ref ref : refs.values()) { Change.Id changeId; Account.Id accountId; if (ref.getName().startsWith(RefNames.REFS_CACHE_AUTOMERGE)) { continue; } else if ((accountId = Account.Id.fromRef(ref.getName())) != null) { // Reference related to an account is visible only for the current // account. // // TODO(dborowitz): If a ref matches an account and a change, verify // both (to exclude e.g. edits on changes that the user has lost access // to). if (showMetadata && (canViewMetadata || accountId.equals(currAccountId))) { result.put(ref.getName(), ref); } } else if ((changeId = Change.Id.fromRef(ref.getName())) != null) { // Reference related to a change is visible if the change is visible. // if (showMetadata && (canViewMetadata || visibleChanges.contains(changeId))) { result.put(ref.getName(), ref); } } else if (isTag(ref)) { // If its a tag, consider it later. // if (ref.getObjectId() != null) { deferredTags.add(ref); } } else if (projectCtl.controlForRef(ref.getLeaf().getName()).isVisible()) { // Use the leaf to lookup the control data. If the reference is // symbolic we want the control around the final target. If its // not symbolic then getLeaf() is a no-op returning ref itself. // result.put(ref.getName(), ref); } } // If we have tags that were deferred, we need to do a revision walk // to identify what tags we can actually reach, and what we cannot. // if (!deferredTags.isEmpty() && (!result.isEmpty() || filterTagsSeparately)) { TagMatcher tags = tagCache.get(projectName).matcher(tagCache, db, filterTagsSeparately ? filter(db.getAllRefs()).values() : result.values()); for (Ref tag : deferredTags) { if (tags.isReachable(tag)) { result.put(tag.getName(), tag); } } } return result; }
From source file:com.google.gerrit.server.git.VisibleRefFilter.java
License:Apache License
private static boolean isTag(Ref ref) { return ref.getLeaf().getName().startsWith(Constants.R_TAGS); }
From source file:com.google.gerrit.server.project.ListProjects.java
License:Apache License
private List<Ref> getBranchRefs(Project.NameKey projectName, ProjectControl projectControl) { Ref[] result = new Ref[showBranch.size()]; try (Repository git = repoManager.openRepository(projectName)) { for (int i = 0; i < showBranch.size(); i++) { Ref ref = git.getRef(showBranch.get(i)); if (ref != null && ref.getObjectId() != null && (projectControl.controlForRef(ref.getLeaf().getName()).isVisible()) || (all && projectControl.isOwner())) { result[i] = ref;//from w ww . j a v a2 s . c om } } } catch (IOException ioe) { // Fall through and return what is available. } return Arrays.asList(result); }
From source file:com.google.gerrit.sshd.commands.ListProjects.java
License:Apache License
private void display() throws Failure { if (showTree && (showBranch != null)) { throw new UnloggedFailure(1, "fatal: --tree and --show-branch options are not compatible."); }//w w w . j av a2 s . co m final PrintWriter stdout = toPrintWriter(out); TreeMap<String, TreeNode> treeMap = null; if (showTree) { treeMap = new TreeMap<String, TreeNode>(); } try { for (final Project.NameKey projectName : projectCache.all()) { final ProjectState e = projectCache.get(projectName); if (e == null) { // If we can't get it from the cache, pretend its not present. // continue; } final ProjectControl pctl = e.controlFor(currentUser); if (!showTree) { if (!pctl.isVisible()) { // Require the project itself to be visible to the user. // continue; } if (showBranch != null) { final List<Ref> refs = getBranchRefs(projectName); if (refs == null) { continue; } boolean hasVisibleRefs = false; for (int i = 0; i < refs.size(); i++) { Ref ref = refs.get(i); if (ref == null || ref.getObjectId() == null || !pctl.controlForRef(ref.getLeaf().getName()).isVisible()) { // No branch, or the user can't see this branch, so remove it. refs.set(i, null); } else { hasVisibleRefs = true; } } if (!hasVisibleRefs) { continue; } for (Ref ref : refs) { if (ref == null) { // Print stub (forty '-' symbols) stdout.print("----------------------------------------"); } else { stdout.print(ref.getObjectId().name()); } stdout.print(' '); } } stdout.print(projectName.get() + "\n"); } else { treeMap.put(projectName.get(), new TreeNode(pctl.getProject(), pctl.isVisible())); } } if (showTree && treeMap.size() > 0) { final List<TreeNode> sortedNodes = new ArrayList<TreeNode>(); // Builds the inheritance tree using a list. // for (final TreeNode key : treeMap.values()) { final String parentName = key.getParentName(); if (parentName != null) { final TreeNode node = treeMap.get(parentName); if (node != null) { node.addChild(key); } else { sortedNodes.add(key); } } else { sortedNodes.add(key); } } // Builds a fake root node, which contains the sorted projects. // final TreeNode fakeRoot = new TreeNode(null, sortedNodes, false); printElement(stdout, fakeRoot, -1, false, sortedNodes.get(sortedNodes.size() - 1)); stdout.flush(); } } finally { stdout.flush(); } }
From source file:com.google.gitiles.RefServlet.java
License:Open Source License
static List<Map<String, Object>> getBranchesSoyData(HttpServletRequest req, int limit) throws IOException { RefDatabase refdb = ServletUtils.getRepository(req).getRefDatabase(); Ref head = refdb.getRef(Constants.HEAD); Ref headLeaf = head != null && head.isSymbolic() ? head.getLeaf() : null; return getRefsSoyData(refdb, ViewFilter.getView(req), Constants.R_HEADS, branchComparator(headLeaf), headLeaf, limit);// ww w .j ava2 s . c o m }
From source file:com.googlesource.gerrit.plugins.replication.Destination.java
License:Apache License
void schedule(Project.NameKey project, String ref, URIish uri, ReplicationState state) { repLog.info("scheduling replication {}:{} => {}", project, ref, uri); if (!shouldReplicate(project, ref, state)) { return;/*from www. j a v a 2s . c o m*/ } if (!config.replicatePermissions()) { PushOne e; synchronized (stateLock) { e = pending.get(uri); } if (e == null) { try (Repository git = gitManager.openRepository(project)) { try { Ref head = git.exactRef(Constants.HEAD); if (head != null && head.isSymbolic() && RefNames.REFS_CONFIG.equals(head.getLeaf().getName())) { return; } } catch (IOException err) { stateLog.error(String.format("cannot check type of project %s", project), err, state); return; } } catch (IOException err) { stateLog.error(String.format("source project %s not available", project), err, state); return; } } } synchronized (stateLock) { PushOne e = pending.get(uri); if (e == null) { e = opFactory.create(project, uri); pool.schedule(e, config.getDelay(), TimeUnit.SECONDS); pending.put(uri, e); } e.addRef(ref); state.increasePushTaskCount(project.get(), ref); e.addState(ref, state); repLog.info("scheduled {}:{} => {} to run after {}s", project, ref, e, config.getDelay()); } }
From source file:com.microsoft.gittf.client.clc.commands.framework.Command.java
License:Open Source License
protected void verifyMasterBranch() throws Exception { final Repository repository = getRepository(); if (!RepositoryUtil.isEmptyRepository(repository)) { Ref master = repository.getRef(Constants.R_HEADS + Constants.MASTER); Ref head = repository.getRef(Constants.HEAD); Ref masterHeadRef = master != null ? master.getLeaf() : null; Ref currentHeadRef = head != null ? head.getLeaf() : null; if (masterHeadRef == null || !masterHeadRef.getName().equals(currentHeadRef.getName())) { throw new Exception(Messages.getString("Command.MasterNotCurrentBranch")); //$NON-NLS-1$ }/* w w w . j a v a 2 s . c o m*/ } }