Example usage for org.eclipse.jgit.lib Constants R_TAGS

List of usage examples for org.eclipse.jgit.lib Constants R_TAGS

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants R_TAGS.

Prototype

String R_TAGS

To view the source code for org.eclipse.jgit.lib Constants R_TAGS.

Click Source Link

Document

Prefix for tag refs

Usage

From source file:com.gitblit.client.MessageRenderer.java

License:Apache License

private void showRef(String ref, JLabel label) {
    String name = ref;//  w w  w. j a  va  2s . c  o  m
    Color bg = getBackground();
    Border border = null;
    if (name.startsWith(Constants.R_HEADS)) {
        // local branch
        bg = Color.decode("#CCFFCC");
        name = name.substring(Constants.R_HEADS.length());
        border = new LineBorder(Color.decode("#00CC33"), 1);
    } else if (name.startsWith(Constants.R_REMOTES)) {
        // remote branch
        bg = Color.decode("#CAC2F5");
        name = name.substring(Constants.R_REMOTES.length());
        border = new LineBorder(Color.decode("#6C6CBF"), 1);
    } else if (name.startsWith(Constants.R_TAGS)) {
        // tag
        bg = Color.decode("#FFFFAA");
        name = name.substring(Constants.R_TAGS.length());
        border = new LineBorder(Color.decode("#FFCC00"), 1);
    } else if (name.equals(Constants.HEAD)) {
        // HEAD
        bg = Color.decode("#FFAAFF");
        border = new LineBorder(Color.decode("#FF00EE"), 1);
    } else {
    }
    label.setText(name);
    label.setBackground(bg);
    label.setBorder(border);
    label.setVisible(true);
}

From source file:com.gitblit.client.MessageRenderer.java

License:Apache License

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected)
        setBackground(table.getSelectionBackground());
    else//from  ww w .  ja v a 2s.  c om
        setBackground(table.getBackground());
    messageLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
    if (value == null) {
        return this;
    }
    FeedEntryModel entry = (FeedEntryModel) value;

    if (gitblit == null) {
        // no gitblit client, just display message
        messageLabel.setText(entry.title);
    } else {
        // show message in BOLD if its a new entry
        if (entry.published.after(gitblit.getLastFeedRefresh(entry.repository, entry.branch))) {
            messageLabel.setText("<html><body><b>" + entry.title);
        } else {
            messageLabel.setText(entry.title);
        }
    }

    // reset ref label
    resetRef(headLabel);
    resetRef(branchLabel);
    resetRef(remoteLabel);
    resetRef(tagLabel);

    int parentCount = 0;
    if (entry.tags != null) {
        for (String tag : entry.tags) {
            if (tag.startsWith("ref:")) {
                // strip ref:
                tag = tag.substring("ref:".length());
            } else {
                // count parents
                if (tag.startsWith("parent:")) {
                    parentCount++;
                }
            }
            if (tag.equals(entry.branch)) {
                // skip current branch label
                continue;
            }
            if (tag.startsWith(Constants.R_HEADS)) {
                // local branch
                showRef(tag, branchLabel);
            } else if (tag.startsWith(Constants.R_REMOTES)) {
                // remote branch
                showRef(tag, remoteLabel);
            } else if (tag.startsWith(Constants.R_TAGS)) {
                // tag
                showRef(tag, tagLabel);
            } else if (tag.equals(Constants.HEAD)) {
                // HEAD
                showRef(tag, headLabel);
            }
        }
    }

    if (parentCount > 1) {
        // multiple parents, show merge icon
        messageLabel.setIcon(mergeIcon);
    } else {
        messageLabel.setIcon(blankIcon);
    }
    return this;
}

From source file:com.gitblit.models.PushLogEntry.java

License:Apache License

/**
 * Returns the list of tags changed by the push.
 * //from  ww  w  . j  a va 2s  . c  o m
 * @return a list of tags
 */
public List<String> getChangedTags() {
    return getChangedRefs(Constants.R_TAGS);
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testTags() throws Exception {
    Repository repository = GitBlitSuite.getJGitRepository();
    assertTrue(JGitUtils.getTags(repository, true, 5).size() == 5);
    for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
        if (model.getObjectId().getName().equals("d28091fb2977077471138fe97da1440e0e8ae0da")) {
            assertTrue("Not an annotated tag!", model.isAnnotatedTag());
        }//from   w  ww  .ja  va 2 s  .  com
        assertTrue(model.getName().startsWith(Constants.R_TAGS));
        assertTrue(model.equals(model));
        assertFalse(model.equals(""));
        assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode() + model.getName().hashCode());
    }
    repository.close();

    repository = GitBlitSuite.getGitectiveRepository();
    for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
        if (model.getObjectId().getName().equals("035254295a9bba11f72b1f9d6791a6b957abee7b")) {
            assertFalse(model.isAnnotatedTag());
            assertTrue(model.getAuthorIdent().getEmailAddress().equals("kevinsawicki@gmail.com"));
            assertEquals("Add scm and issue tracker elements to pom.xml\n", model.getFullMessage());
        }
    }
    repository.close();
}

From source file:com.gitblit.utils.JGitUtils.java

License:Apache License

/**
 * Returns the list of tags in the repository. If repository does not exist
 * or is empty, an empty list is returned.
 *
 * @param repository//from   w w w  .  j  a  v  a  2 s  .c  om
 * @param fullName
 *            if true, /refs/tags/yadayadayada is returned. If false,
 *            yadayadayada is returned.
 * @param maxCount
 *            if < 0, all tags are returned
 * @return list of tags
 */
public static List<RefModel> getTags(Repository repository, boolean fullName, int maxCount) {
    return getRefs(repository, Constants.R_TAGS, fullName, maxCount);
}

From source file:com.gitblit.utils.JGitUtils.java

License:Apache License

/**
 * Returns the list of tags in the repository. If repository does not exist
 * or is empty, an empty list is returned.
 *
 * @param repository/*from   w  w  w .  ja  va2  s  .  co  m*/
 * @param fullName
 *            if true, /refs/tags/yadayadayada is returned. If false,
 *            yadayadayada is returned.
 * @param maxCount
 *            if < 0, all tags are returned
 * @param offset
 *            if maxCount provided sets the starting point of the records to return
 * @return list of tags
 */
public static List<RefModel> getTags(Repository repository, boolean fullName, int maxCount, int offset) {
    return getRefs(repository, Constants.R_TAGS, fullName, maxCount, offset);
}

From source file:com.gitblit.wicket.pages.LuceneSearchPage.java

License:Apache License

private void setup(PageParameters params) {
    setupPage("", "");

    // default values
    ArrayList<String> repositories = new ArrayList<String>();
    String query = "";
    boolean allRepos = false;

    int page = 1;
    int pageSize = app().settings().getInteger(Keys.web.itemsPerPage, 50);

    // display user-accessible selections
    UserModel user = GitBlitWebSession.get().getUser();
    List<String> availableRepositories = new ArrayList<String>();
    for (RepositoryModel model : app().repositories().getRepositoryModels(user)) {
        if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {
            availableRepositories.add(model.name);
        }//from  w w w  . j a  v a 2s.  co m
    }

    if (params != null) {
        String repository = WicketUtils.getRepositoryName(params);
        if (!StringUtils.isEmpty(repository)) {
            repositories.add(repository);
        }

        page = WicketUtils.getPage(params);

        if (!params.get("repositories").isEmpty()) {
            String value = params.get("repositories").toString("");
            List<String> list = StringUtils.getStringsFromValue(value);
            repositories.addAll(list);
        }

        allRepos = params.get("allrepos").toBoolean(false);
        if (allRepos) {
            repositories.addAll(availableRepositories);
        }

        if (!params.get("query").isEmpty()) {
            query = params.get("query").toString("");
        } else {
            String value = WicketUtils.getSearchString(params);
            String type = WicketUtils.getSearchType(params);
            com.gitblit.Constants.SearchType searchType = com.gitblit.Constants.SearchType.forName(type);
            if (!StringUtils.isEmpty(value)) {
                if (searchType == SearchType.COMMIT) {
                    query = "type:" + searchType.name().toLowerCase() + " AND \"" + value + "\"";
                } else {
                    query = searchType.name().toLowerCase() + ":\"" + value + "\"";
                }
            }
        }
    }

    boolean luceneEnabled = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
    if (luceneEnabled) {
        if (availableRepositories.size() == 0) {
            info(getString("gb.noIndexedRepositoriesWarning"));
        }
    } else {
        error(getString("gb.luceneDisabled"));
    }

    // enforce user-accessible repository selections
    Set<String> uniqueRepositories = new LinkedHashSet<String>();
    for (String selectedRepository : repositories) {
        if (availableRepositories.contains(selectedRepository)) {
            uniqueRepositories.add(selectedRepository);
        }
    }
    ArrayList<String> searchRepositories = new ArrayList<String>(uniqueRepositories);

    // search form
    final Model<String> queryModel = new Model<String>(query);
    final Model<ArrayList<String>> repositoriesModel = new Model<ArrayList<String>>(searchRepositories);
    final Model<Boolean> allreposModel = new Model<Boolean>(allRepos);
    SessionlessForm<Void> form = new SessionlessForm<Void>("searchForm", getClass()) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            String q = queryModel.getObject();
            if (StringUtils.isEmpty(q)) {
                error(getString("gb.undefinedQueryWarning"));
                return;
            }
            if (repositoriesModel.getObject().size() == 0 && !allreposModel.getObject()) {
                error(getString("gb.noSelectedRepositoriesWarning"));
                return;
            }
            PageParameters params = new PageParameters();
            params.add("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
            params.add("query", queryModel.getObject());
            params.add("allrepos", allreposModel.getObject());
            LuceneSearchPage page = new LuceneSearchPage(params);
            setResponsePage(page);
        }
    };

    ListMultipleChoice<String> selections = new ListMultipleChoice<String>("repositories", repositoriesModel,
            availableRepositories, new StringChoiceRenderer());
    selections.setMaxRows(8);
    form.add(selections.setEnabled(luceneEnabled));
    form.add(new TextField<String>("query", queryModel).setEnabled(luceneEnabled));
    form.add(new CheckBox("allrepos", allreposModel));
    form.add(new ExternalLink("querySyntax", LUCENE_QUERY_SYNTAX_LINK));
    add(form.setEnabled(luceneEnabled));

    // execute search
    final List<SearchResult> results = new ArrayList<SearchResult>();
    if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
        results.addAll(app().repositories().search(query, page, pageSize, searchRepositories));
    }

    // results header
    if (results.size() == 0) {
        if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
            add(new Label("resultsHeader", query).setRenderBodyOnly(true));
            add(new Label("resultsCount", getString("gb.noHits")).setRenderBodyOnly(true));
        } else {
            add(new Label("resultsHeader").setVisible(false));
            add(new Label("resultsCount").setVisible(false));
        }
    } else {
        add(new Label("resultsHeader", query).setRenderBodyOnly(true));
        add(new Label("resultsCount",
                MessageFormat.format(getString("gb.queryResults"), results.get(0).hitId,
                        results.get(results.size() - 1).hitId, results.get(0).totalHits))
                                .setRenderBodyOnly(true));
    }

    // search results view
    ListDataProvider<SearchResult> resultsDp = new ListDataProvider<SearchResult>(results);
    final DataView<SearchResult> resultsView = new DataView<SearchResult>("searchResults", resultsDp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<SearchResult> item) {
            final SearchResult sr = item.getModelObject();
            switch (sr.type) {
            case commit: {
                Label icon = WicketUtils.newIcon("type", "icon-refresh");
                WicketUtils.setHtmlTooltip(icon, "commit");
                item.add(icon);
                item.add(new LinkPanel("summary", null, sr.summary, CommitPage.class,
                        WicketUtils.newObjectParameter(sr.repository, sr.commitId)));
                // show tags
                Fragment fragment = new Fragment("tags", "tagsPanel", LuceneSearchPage.this);
                List<String> tags = sr.tags;
                if (tags == null) {
                    tags = new ArrayList<String>();
                }
                ListDataProvider<String> tagsDp = new ListDataProvider<String>(tags);
                final DataView<String> tagsView = new DataView<String>("tag", tagsDp) {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void populateItem(final Item<String> item) {
                        String tag = item.getModelObject();
                        Component c = new LinkPanel("tagLink", null, tag, TagPage.class,
                                WicketUtils.newObjectParameter(sr.repository, Constants.R_TAGS + tag));
                        WicketUtils.setCssClass(c, "tagRef");
                        item.add(c);
                    }
                };
                fragment.add(tagsView);
                item.add(fragment);
                break;
            }
            case blob: {
                Label icon = WicketUtils.newIcon("type", "icon-file");
                WicketUtils.setHtmlTooltip(icon, "blob");
                item.add(icon);
                item.add(new LinkPanel("summary", null, sr.path, BlobPage.class,
                        WicketUtils.newPathParameter(sr.repository, sr.branch, sr.path)));
                item.add(new Label("tags").setVisible(false));
                break;
            }
            }
            item.add(new Label("fragment", sr.fragment).setEscapeModelStrings(false)
                    .setVisible(!StringUtils.isEmpty(sr.fragment)));
            item.add(new LinkPanel("repository", null, sr.repository, SummaryPage.class,
                    WicketUtils.newRepositoryParameter(sr.repository)));
            if (StringUtils.isEmpty(sr.branch)) {
                item.add(new Label("branch", "null"));
            } else {
                item.add(new LinkPanel("branch", "branch",
                        StringUtils.getRelativePath(Constants.R_HEADS, sr.branch), LogPage.class,
                        WicketUtils.newObjectParameter(sr.repository, sr.branch)));
            }
            item.add(new Label("author", sr.author));
            item.add(WicketUtils.createDatestampLabel("date", sr.date, getTimeZone(), getTimeUtils()));
        }
    };
    add(resultsView.setVisible(results.size() > 0));

    PageParameters pagerParams = new PageParameters();
    pagerParams.add("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
    pagerParams.add("query", queryModel.getObject());

    boolean showPager = false;
    int totalPages = 0;
    if (results.size() > 0) {
        totalPages = (results.get(0).totalHits / pageSize) + (results.get(0).totalHits % pageSize > 0 ? 1 : 0);
        showPager = results.get(0).totalHits > pageSize;
    }

    add(new PagerPanel("topPager", page, totalPages, LuceneSearchPage.class, pagerParams)
            .setVisible(showPager));
    add(new PagerPanel("bottomPager", page, totalPages, LuceneSearchPage.class, pagerParams)
            .setVisible(showPager));
}

From source file:com.google.gerrit.acceptance.rest.project.TagsIT.java

License:Apache License

@Test
public void listTags() throws Exception {
    grant(Permission.SUBMIT, project, "refs/for/refs/heads/master");
    grant(Permission.CREATE, project, "refs/tags/*");
    grant(Permission.PUSH, project, "refs/tags/*");

    PushOneCommit.Tag tag1 = new PushOneCommit.Tag("v1.0");
    PushOneCommit push1 = pushFactory.create(db, admin.getIdent(), testRepo);
    push1.setTag(tag1);//from w  w w. j a v  a 2 s.  co m
    PushOneCommit.Result r1 = push1.to("refs/for/master%submit");
    r1.assertOkStatus();

    PushOneCommit.AnnotatedTag tag2 = new PushOneCommit.AnnotatedTag("v2.0", "annotation", admin.getIdent());
    PushOneCommit push2 = pushFactory.create(db, admin.getIdent(), testRepo);
    push2.setTag(tag2);
    PushOneCommit.Result r2 = push2.to("refs/for/master%submit");
    r2.assertOkStatus();

    String tag3Ref = Constants.R_TAGS + "vLatest";
    PushCommand pushCmd = testRepo.git().push();
    pushCmd.setRefSpecs(new RefSpec(tag2.name + ":" + tag3Ref));
    Iterable<PushResult> r = pushCmd.call();
    assertThat(Iterables.getOnlyElement(r).getRemoteUpdate(tag3Ref).getStatus()).isEqualTo(Status.OK);

    List<TagInfo> result = getTags().get();
    assertThat(result).hasSize(3);

    TagInfo t = result.get(0);
    assertThat(t.ref).isEqualTo(Constants.R_TAGS + tag1.name);
    assertThat(t.revision).isEqualTo(r1.getCommit().getName());

    t = result.get(1);
    assertThat(t.ref).isEqualTo(Constants.R_TAGS + tag2.name);
    assertThat(t.object).isEqualTo(r2.getCommit().getName());
    assertThat(t.message).isEqualTo(tag2.message);
    assertThat(t.tagger.name).isEqualTo(tag2.tagger.getName());
    assertThat(t.tagger.email).isEqualTo(tag2.tagger.getEmailAddress());

    t = result.get(2);
    assertThat(t.ref).isEqualTo(tag3Ref);
    assertThat(t.object).isEqualTo(r2.getCommit().getName());
    assertThat(t.message).isEqualTo(tag2.message);
    assertThat(t.tagger.name).isEqualTo(tag2.tagger.getName());
    assertThat(t.tagger.email).isEqualTo(tag2.tagger.getEmailAddress());
}

From source file:com.google.gerrit.httpd.rpc.changedetail.IncludedInDetailFactory.java

License:Apache License

@Override
public IncludedInDetail call()
        throws OrmException, NoSuchChangeException, IOException, InvalidRevisionException {
    control = changeControlFactory.validateFor(changeId);

    final PatchSet patch = db.patchSets().get(control.getChange().currentPatchSetId());
    final Repository repo = repoManager.openRepository(control.getProject().getNameKey());
    try {/* w w w .  j  a  va 2s  . com*/
        final RevWalk rw = new RevWalk(repo);
        try {
            rw.setRetainBody(false);

            final RevCommit rev;
            try {
                rev = rw.parseCommit(ObjectId.fromString(patch.getRevision().get()));
            } catch (IncorrectObjectTypeException err) {
                throw new InvalidRevisionException();
            } catch (MissingObjectException err) {
                throw new InvalidRevisionException();
            }

            detail = new IncludedInDetail();
            detail.setBranches(includedIn(repo, rw, rev, Constants.R_HEADS));
            detail.setTags(includedIn(repo, rw, rev, Constants.R_TAGS));

            return detail;
        } finally {
            rw.release();
        }
    } finally {
        repo.close();
    }
}

From source file:com.google.gerrit.httpd.rpc.project.AddRefRight.java

License:Apache License

@Override
public ProjectDetail call() throws NoSuchProjectException, OrmException, NoSuchGroupException,
        InvalidNameException, NoSuchRefException {
    final ProjectControl projectControl = projectControlFactory.controlFor(projectName);

    final ApprovalType at = approvalTypes.getApprovalType(categoryId);
    if (at == null || at.getValue(min) == null || at.getValue(max) == null) {
        throw new IllegalArgumentException("Invalid category " + categoryId + " or range " + min + ".." + max);
    }//  w  w w . ja va  2s . c o m

    String refPattern = this.refPattern;
    if (refPattern == null || refPattern.isEmpty()) {
        if (categoryId.equals(ApprovalCategory.SUBMIT) || categoryId.equals(ApprovalCategory.PUSH_HEAD)) {
            // Explicitly related to a branch head.
            refPattern = Constants.R_HEADS + "*";

        } else if (!at.getCategory().isAction()) {
            // Non actions are approval votes on a change, assume these apply
            // to branch heads only.
            refPattern = Constants.R_HEADS + "*";

        } else if (categoryId.equals(ApprovalCategory.PUSH_TAG)) {
            // Explicitly related to the tag namespace.
            refPattern = Constants.R_TAGS + "*";

        } else if (categoryId.equals(ApprovalCategory.READ) || categoryId.equals(ApprovalCategory.OWN)) {
            // Currently these are project-wide rights, so apply that way.
            refPattern = RefRight.ALL;

        } else {
            // Assume project wide for the default.
            refPattern = RefRight.ALL;
        }
    }

    boolean exclusive = refPattern.startsWith("-");
    if (exclusive) {
        refPattern = refPattern.substring(1);
    }

    while (refPattern.startsWith("/")) {
        refPattern = refPattern.substring(1);
    }

    if (refPattern.startsWith(RefRight.REGEX_PREFIX)) {
        String example = RefControl.shortestExample(refPattern);

        if (!example.startsWith(Constants.R_REFS)) {
            refPattern = RefRight.REGEX_PREFIX + Constants.R_HEADS
                    + refPattern.substring(RefRight.REGEX_PREFIX.length());
            example = RefControl.shortestExample(refPattern);
        }

        if (!Repository.isValidRefName(example)) {
            throw new InvalidNameException();
        }

    } else {
        if (!refPattern.startsWith(Constants.R_REFS)) {
            refPattern = Constants.R_HEADS + refPattern;
        }

        if (refPattern.endsWith("/*")) {
            final String prefix = refPattern.substring(0, refPattern.length() - 2);
            if (!"refs".equals(prefix) && !Repository.isValidRefName(prefix)) {
                throw new InvalidNameException();
            }
        } else {
            if (!Repository.isValidRefName(refPattern)) {
                throw new InvalidNameException();
            }
        }
    }

    if (!projectControl.controlForRef(refPattern).isOwner()) {
        throw new NoSuchRefException(refPattern);
    }

    if (exclusive) {
        refPattern = "-" + refPattern;
    }

    final AccountGroup group = groupCache.get(groupName);
    if (group == null) {
        throw new NoSuchGroupException(groupName);
    }
    final RefRight.Key key = new RefRight.Key(projectName, new RefRight.RefPattern(refPattern), categoryId,
            group.getId());
    RefRight rr = db.refRights().get(key);
    if (rr == null) {
        rr = new RefRight(key);
        rr.setMinValue(min);
        rr.setMaxValue(max);
        db.refRights().insert(Collections.singleton(rr));
    } else {
        rr.setMinValue(min);
        rr.setMaxValue(max);
        db.refRights().update(Collections.singleton(rr));
    }
    projectCache.evictAll();
    return projectDetailFactory.create(projectName).call();
}