List of usage examples for org.eclipse.jgit.revwalk RevTag getObject
public final RevObject getObject()
From source file:com.google.gerrit.acceptance.git.SubmitOnPushIT.java
License:Apache License
private void assertTag(Project.NameKey project, String branch, PushOneCommit.Tag tag) throws IOException { try (Repository repo = repoManager.openRepository(project)) { Ref tagRef = repo.getRef(tag.name); assertThat(tagRef).isNotNull();/* w ww.ja v a 2 s. c o m*/ ObjectId taggedCommit = null; if (tag instanceof PushOneCommit.AnnotatedTag) { PushOneCommit.AnnotatedTag annotatedTag = (PushOneCommit.AnnotatedTag) tag; try (RevWalk rw = new RevWalk(repo)) { RevObject object = rw.parseAny(tagRef.getObjectId()); assertThat(object).isInstanceOf(RevTag.class); RevTag tagObject = (RevTag) object; assertThat(tagObject.getFullMessage()).isEqualTo(annotatedTag.message); assertThat(tagObject.getTaggerIdent()).isEqualTo(annotatedTag.tagger); taggedCommit = tagObject.getObject(); } } else { taggedCommit = tagRef.getObjectId(); } ObjectId headCommit = repo.getRef(branch).getObjectId(); assertThat(taggedCommit).isNotNull(); assertThat(taggedCommit).isEqualTo(headCommit); } }
From source file:com.google.gerrit.server.project.ListTags.java
License:Apache License
private static TagInfo createTagInfo(Ref ref, RevWalk rw) throws MissingObjectException, IOException { RevObject object = rw.parseAny(ref.getObjectId()); if (object instanceof RevTag) { RevTag tag = (RevTag) object; // Annotated or signed tag return new TagInfo(Constants.R_TAGS + tag.getTagName(), tag.getName(), tag.getObject().getName(), tag.getFullMessage().trim(), CommonConverters.toGitPerson(tag.getTaggerIdent())); } else {/*w w w. ja v a 2 s . c o m*/ // Lightweight tag return new TagInfo(ref.getName(), ref.getObjectId().getName()); } }
From source file:com.google.gitiles.TagSoyData.java
License:Open Source License
public Map<String, Object> toSoyData(RevTag tag) { Map<String, Object> data = Maps.newHashMapWithExpectedSize(4); data.put("sha", ObjectId.toString(tag)); if (tag.getTaggerIdent() != null) { data.put("tagger", CommitSoyData.toSoyData(tag.getTaggerIdent(), dateFormatter)); }/*from w w w. java 2 s . co m*/ data.put("object", ObjectId.toString(tag.getObject())); data.put("message", linkifier.linkify(req, tag.getFullMessage())); return data; }
From source file:com.google.gitiles.TimeCache.java
License:Open Source License
Long getTime(final RevWalk walk, final ObjectId id) throws IOException { try {/*from w w w.j av a2 s .c o m*/ return cache.get(id, new Callable<Long>() { @Override public Long call() throws IOException { RevObject o = walk.parseAny(id); while (o instanceof RevTag) { RevTag tag = (RevTag) o; PersonIdent ident = tag.getTaggerIdent(); if (ident != null) { return ident.getWhen().getTime() / 1000; } o = tag.getObject(); walk.parseHeaders(o); } if (o.getType() == Constants.OBJ_COMMIT) { return Long.valueOf(((RevCommit) o).getCommitTime()); } return Long.MIN_VALUE; } }); } catch (ExecutionException e) { Throwables.propagateIfInstanceOf(e.getCause(), IOException.class); throw new IOException(e); } }
From source file:com.madgag.agit.views.TagSummaryView.java
License:Open Source License
public void setObject(RevTag tag, View view, Repository repo) { ((PersonIdentView) view.findViewById(tagger_ident)).setIdent("Tagger", tag.getTaggerIdent()); ((TextView) view.findViewById(message_text)).setText(tag.getFullMessage()); try {//from w ww.java2s . com RevObject taggedObject = new RevWalk(repo).parseAny(tag.getObject()); ((ObjectSummaryView) view.findViewById(tagged_object)).setObject(taggedObject); Log.d(TAG, "Successfully set taggedObject=" + taggedObject); } catch (IOException e) { Log.e(TAG, "Couldn't set the tagged object...", e); e.printStackTrace(); } }
From source file:com.meltmedia.cadmium.core.git.GitService.java
License:Apache License
public String getBranchName() throws Exception { Repository repository = git.getRepository(); if (ObjectId.isId(repository.getFullBranch()) && repository.getFullBranch().equals(repository.resolve("HEAD").getName())) { RevWalk revs = null;// www . ja v a 2s . com try { log.trace("Trying to resolve tagname: {}", repository.getFullBranch()); ObjectId tagRef = ObjectId.fromString(repository.getFullBranch()); revs = new RevWalk(repository); RevCommit commit = revs.parseCommit(tagRef); Map<String, Ref> allTags = repository.getTags(); for (String key : allTags.keySet()) { Ref ref = allTags.get(key); RevTag tag = revs.parseTag(ref.getObjectId()); log.trace("Checking ref {}, {}", commit.getName(), tag.getObject()); if (tag.getObject().equals(commit)) { return key; } } } catch (Exception e) { log.warn("Invalid id: {}", repository.getFullBranch(), e); } finally { revs.release(); } } return repository.getBranch(); }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java
License:Eclipse Distribution License
private void processTag(final RevObject obj) { final RevTag tag = (RevTag) obj; needs(tag.getObject()); obj.add(COMPLETE);/*from ww w.j a v a 2 s . c om*/ }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.GitLabelingSupportTest.java
License:Apache License
public void testLabels() throws Exception { VcsRoot root = vcsRoot().withFetchUrl(getRemoteRepositoryDir("repo.git")).build(); // ensure that all revisions reachable from master are fetched buildGit().getLabelingSupport().label("test_label", "2276eaf76a658f96b5cf3eb25f3e1fda90f6b653", root, CheckoutRules.DEFAULT);//from w ww .ja v a 2 s . co m Repository r = new RepositoryBuilder().setGitDir(getRemoteRepositoryDir("repo.git")).build(); RevWalk revWalk = new RevWalk(r); try { Ref tagRef = r.getTags().get("test_label"); RevTag t = revWalk.parseTag(tagRef.getObjectId()); assertEquals(t.getObject().name(), "2276eaf76a658f96b5cf3eb25f3e1fda90f6b653"); } finally { r.close(); } }
From source file:org.eclipse.egit.core.RepositoryUtil.java
License:Open Source License
/** * Tries to map a commit to a symbolic reference. * <p>/*from w ww. j a va 2s . com*/ * This value will be cached for the given commit ID unless refresh is * specified. The return value will be the full name, e.g. * "refs/remotes/someBranch", "refs/tags/v.1.0" * <p> * Since this mapping is not unique, the following precedence rules are * used: * <ul> * <li>Tags take precedence over branches</li> * <li>Local branches take preference over remote branches</li> * <li>Newer references take precedence over older ones where time stamps * are available</li> * <li>If there are still ambiguities, the reference name with the highest * lexicographic value will be returned</li> * </ul> * * @param repository * the {@link Repository} * @param commitId * a commit * @param refresh * if true, the cache will be invalidated * @return the symbolic reference, or <code>null</code> if no such reference * can be found */ public String mapCommitToRef(Repository repository, String commitId, boolean refresh) { synchronized (commitMappingCache) { if (!ObjectId.isId(commitId)) { return null; } Map<String, String> cacheEntry = commitMappingCache.get(repository.getDirectory().toString()); if (!refresh && cacheEntry != null && cacheEntry.containsKey(commitId)) { // this may be null in fact return cacheEntry.get(commitId); } if (cacheEntry == null) { cacheEntry = new HashMap<String, String>(); commitMappingCache.put(repository.getDirectory().getPath(), cacheEntry); } else { cacheEntry.clear(); } Map<String, Date> tagMap = new HashMap<String, Date>(); try { RevWalk rw = new RevWalk(repository); Map<String, Ref> tags = repository.getRefDatabase().getRefs(Constants.R_TAGS); for (Ref tagRef : tags.values()) { RevTag tag = rw.parseTag(repository.resolve(tagRef.getName())); if (tag.getObject().name().equals(commitId)) { Date timestamp; if (tag.getTaggerIdent() != null) { timestamp = tag.getTaggerIdent().getWhen(); } else { timestamp = null; } tagMap.put(tagRef.getName(), timestamp); } } } catch (IOException e) { // ignore here } String cacheValue = null; if (!tagMap.isEmpty()) { // we try to obtain the "latest" tag Date compareDate = new Date(0); for (Map.Entry<String, Date> tagEntry : tagMap.entrySet()) { if (tagEntry.getValue() != null && tagEntry.getValue().after(compareDate)) { compareDate = tagEntry.getValue(); cacheValue = tagEntry.getKey(); } } // if we don't have time stamps, we sort if (cacheValue == null) { String compareString = ""; //$NON-NLS-1$ for (String tagName : tagMap.keySet()) { if (tagName.compareTo(compareString) >= 0) { cacheValue = tagName; compareString = tagName; } } } } if (cacheValue == null) { // we didnt't find a tag, so let's look for local branches Set<String> branchNames = new TreeSet<String>(); // put this into a sorted set try { Map<String, Ref> remoteBranches = repository.getRefDatabase().getRefs(Constants.R_HEADS); for (Ref branch : remoteBranches.values()) { if (branch.getObjectId().name().equals(commitId)) { branchNames.add(branch.getName()); } } } catch (IOException e) { // ignore here } if (!branchNames.isEmpty()) { // get the last (sorted) entry cacheValue = branchNames.toArray(new String[branchNames.size()])[branchNames.size() - 1]; } } if (cacheValue == null) { // last try: remote branches Set<String> branchNames = new TreeSet<String>(); // put this into a sorted set try { Map<String, Ref> remoteBranches = repository.getRefDatabase().getRefs(Constants.R_REMOTES); for (Ref branch : remoteBranches.values()) { if (branch.getObjectId().name().equals(commitId)) { branchNames.add(branch.getName()); } } if (!branchNames.isEmpty()) { // get the last (sorted) entry cacheValue = branchNames.toArray(new String[branchNames.size()])[branchNames.size() - 1]; } } catch (IOException e) { // ignore here } } cacheEntry.put(commitId, cacheValue); return cacheValue; } }
From source file:org.eclipse.egit.ui.internal.actions.SynchronizeWithMenu.java
License:Open Source License
private boolean excludeTag(Ref ref, Repository repo) { if (ref instanceof PeeledTag) { RevWalk rw = new RevWalk(repo); try {//from w w w . j a v a2 s . c om RevTag tag = rw.parseTag(ref.getObjectId()); return !(rw.parseAny(tag.getObject()) instanceof RevCommit); } catch (IOException e) { Activator.logError(e.getMessage(), e); } finally { rw.dispose(); } } return false; }