Java Code Examples for org.eclipse.jgit.lib.Ref#getPeeledObjectId()
The following examples show how to use
org.eclipse.jgit.lib.Ref#getPeeledObjectId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Log.java From orion.server with Eclipse Public License 1.0 | 6 votes |
static Map<ObjectId, Map<String, Ref>> getCommitToTagMap(URI cloneLocation, Repository db) throws MissingObjectException, IOException { HashMap<ObjectId, Map<String, Ref>> commitToTag = new HashMap<ObjectId, Map<String, Ref>>(); for (Entry<String, Ref> tag : db.getTags().entrySet()) { Ref ref = db.peel(tag.getValue()); ObjectId commitId = ref.getPeeledObjectId(); if (commitId == null) commitId = ref.getObjectId(); Map<String, Ref> tags = commitToTag.get(commitId); if (tags != null) { tags.put(tag.getKey(), tag.getValue()); } else { tags = new HashMap<String, Ref>(); tags.put(tag.getKey(), tag.getValue()); commitToTag.put(commitId, tags); } } return commitToTag; }
Example 2
Source File: GitRepo.java From git-changelog-lib with Apache License 2.0 | 6 votes |
public ObjectId getRef(final String fromRef) throws GitChangelogRepositoryException { try { for (final Ref foundRef : getAllRefs().values()) { if (foundRef.getName().endsWith(fromRef)) { final Ref ref = getAllRefs().get(foundRef.getName()); final Ref peeledRef = this.repository.peel(ref); if (peeledRef.getPeeledObjectId() != null) { return peeledRef.getPeeledObjectId(); } else { return ref.getObjectId(); } } } } catch (final Exception e) { throw new GitChangelogRepositoryException(fromRef + " not found in:\n" + toString(), e); } throw new GitChangelogRepositoryException(fromRef + " not found in:\n" + toString()); }
Example 3
Source File: GitRepo.java From git-changelog-lib with Apache License 2.0 | 6 votes |
private Map<String, RevTag> getAnnotatedTagPerTagName( final Optional<String> ignoreTagsIfNameMatches, final List<Ref> tagList) { final Map<String, RevTag> tagPerCommit = newHashMap(); for (final Ref tag : tagList) { if (ignoreTagsIfNameMatches.isPresent()) { if (compile(ignoreTagsIfNameMatches.get()).matcher(tag.getName()).matches()) { continue; } } final Ref peeledTag = this.repository.peel(tag); if (peeledTag.getPeeledObjectId() != null) { try { final RevTag revTag = RevTag.parse(this.repository.open(tag.getObjectId()).getBytes()); tagPerCommit.put(tag.getName(), revTag); } catch (final IOException e) { LOG.error(e.getMessage(), e); } } } return tagPerCommit; }
Example 4
Source File: GitUtil.java From apigee-deploy-maven-plugin with Apache License 2.0 | 6 votes |
/** * IMP NOTE: Tag number will be displayed only if git tags are peeled manually using the command "git gc" * @return */ public String getTagNameForWorkspaceHeadRevision() { String headRevision = getWorkspaceHeadRevisionString(); Map<String, Ref> tags = git.getRepository().getAllRefs(); for (Ref tagRef : tags.values()) { String tagName = tagRef.getName(); ObjectId obj = tagRef.getPeeledObjectId(); if (obj == null) obj = tagRef.getObjectId(); // System.out.println(">>>>>>>>>>>>>>>>>" + tagRef.getName() + "," + // obj.getName() +"," + headRevision ); if (headRevision.equals(obj.getName())) { if (tagName.contains("/tags/")) { int lastSlashIndex = tagName.lastIndexOf("/"); if (lastSlashIndex > 0) { tagName = tagName.substring(lastSlashIndex + 1); return tagName; } } } } return null; }
Example 5
Source File: GitSCM.java From repositoryminer with Apache License 2.0 | 6 votes |
private Iterable<RevCommit> getCommitsFromTag(String refName) { try { List<Ref> call = git.tagList().call(); for (Ref ref : call) { if (ref.getName().endsWith(refName)) { LogCommand log = git.log(); Ref peeledRef = git.getRepository().peel(ref); if (peeledRef.getPeeledObjectId() != null) { return log.add(peeledRef.getPeeledObjectId()).call(); } else { return log.add(ref.getObjectId()).call(); } } } return null; } catch (GitAPIException | IncorrectObjectTypeException | MissingObjectException e) { close(); throw new RepositoryMinerException(e); } }
Example 6
Source File: JGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Override @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification = "Java 11 spotbugs error") public ObjectId getHeadRev(String remoteRepoUrl, String branchSpec) throws GitException { try (Repository repo = openDummyRepository(); final Transport tn = Transport.open(repo, new URIish(remoteRepoUrl))) { final String branchName = extractBranchNameFromBranchSpec(branchSpec); String regexBranch = createRefRegexFromGlob(branchName); tn.setCredentialsProvider(getProvider()); try (FetchConnection c = tn.openFetch()) { for (final Ref r : c.getRefs()) { if (r.getName().matches(regexBranch)) { return r.getPeeledObjectId() != null ? r.getPeeledObjectId() : r.getObjectId(); } } } } catch (IOException | URISyntaxException | IllegalStateException e) { throw new GitException(e); } return null; }
Example 7
Source File: GitRepo.java From git-changelog-lib with Apache License 2.0 | 5 votes |
private ObjectId getPeeled(final Ref tag) { final Ref peeledTag = this.repository.peel(tag); if (peeledTag.getPeeledObjectId() != null) { return peeledTag.getPeeledObjectId(); } else { return tag.getObjectId(); } }
Example 8
Source File: JGitAPIImpl.java From git-client-plugin with MIT License | 5 votes |
/** {@inheritDoc} */ @Override public Map<String, ObjectId> getRemoteReferences(String url, String pattern, boolean headsOnly, boolean tagsOnly) throws GitException, InterruptedException { Map<String, ObjectId> references = new HashMap<>(); String regexPattern = null; if (pattern != null) { regexPattern = createRefRegexFromGlob(pattern); } try (Repository repo = openDummyRepository()) { LsRemoteCommand lsRemote = new LsRemoteCommand(repo); if (headsOnly) { lsRemote.setHeads(headsOnly); } if (tagsOnly) { lsRemote.setTags(tagsOnly); } lsRemote.setRemote(url); lsRemote.setCredentialsProvider(getProvider()); Collection<Ref> refs = lsRemote.call(); for (final Ref r : refs) { final String refName = r.getName(); final ObjectId refObjectId = r.getPeeledObjectId() != null ? r.getPeeledObjectId() : r.getObjectId(); if (regexPattern != null) { if (refName.matches(regexPattern)) { references.put(refName, refObjectId); } } else { references.put(refName, refObjectId); } } } catch (JGitInternalException | GitAPIException | IOException e) { throw new GitException(e); } return references; }
Example 9
Source File: JGitAPIImpl.java From git-client-plugin with MIT License | 5 votes |
/** {@inheritDoc} */ @Override public Set<GitObject> getTags() throws GitException, InterruptedException { Set<GitObject> peeledTags = new HashSet<>(); Set<String> tagNames = new HashSet<>(); try (Repository repo = getRepository()) { Map<String, Ref> tagsRead = repo.getTags(); for (Map.Entry<String, Ref> entry : tagsRead.entrySet()) { /* Prefer peeled ref if available (for tag commit), otherwise take first tag reference seen */ String tagName = entry.getKey(); Ref tagRef = entry.getValue(); if (!tagRef.isPeeled()) { Ref peeledRef = repo.peel(tagRef); if (peeledRef.getPeeledObjectId() != null) { tagRef = peeledRef; // Use peeled ref instead of annotated ref } } /* Packed lightweight (non-annotated) tags can wind up peeled with no peeled obj ID */ if (tagRef.isPeeled() && tagRef.getPeeledObjectId() != null) { peeledTags.add(new GitObject(tagName, tagRef.getPeeledObjectId())); } else if (!tagNames.contains(tagName)) { peeledTags.add(new GitObject(tagName, tagRef.getObjectId())); } tagNames.add(tagName); } } return peeledTags; }
Example 10
Source File: Tags.java From gradle-gitsemver with Apache License 2.0 | 5 votes |
private static ObjectId getObjectIdForTag(Repository repo, String tag) { Ref ref = repo.getTags().get(tag); repo.peel(ref); if (ref.getPeeledObjectId() == null) { return ref.getObjectId(); } else { return ref.getPeeledObjectId(); } }
Example 11
Source File: Tags.java From gradle-gitsemver with Apache License 2.0 | 5 votes |
private static ObjectId getIdForTag(Repository repo, Map.Entry<String, Ref> tag) { Ref ref = repo.peel(tag.getValue()); if (ref.getPeeledObjectId() == null) { return ref.getObjectId(); } else { return ref.getPeeledObjectId(); } }
Example 12
Source File: GitUtils.java From jgitver with Apache License 2.0 | 4 votes |
public static boolean isAnnotated(Ref ref) { return ref != null && ref.getPeeledObjectId() != null; }
Example 13
Source File: GitServiceImpl.java From RefactoringMiner with MIT License | 4 votes |
private ObjectId getActualRefObjectId(Ref ref) { if(ref.getPeeledObjectId() != null) { return ref.getPeeledObjectId(); } return ref.getObjectId(); }