本文整理了Java中org.eclipse.jgit.lib.Repository.peel
方法的一些代码示例,展示了Repository.peel
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.peel
方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:peel
[英]Peel a possibly unpeeled reference to an annotated tag.
If the ref cannot be peeled (as it does not refer to an annotated tag) the peeled id stays null, but org.eclipse.jgit.lib.Ref#isPeeled()will be true.
[中]将可能未剥离的引用剥离到带注释的标记。
如果ref不能被剥离(因为它不引用带注释的标记),那么剥离的id将保持为null,但org。日食jgit。lib。Ref#isPeeled()将为真。
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Get a map with all objects referenced by a peeled ref.
*
* @return a map with all objects referenced by a peeled ref.
*/
@NonNull
public Map<AnyObjectId, Set<Ref>> getAllRefsByPeeledObjectId() {
Map<String, Ref> allRefs = getAllRefs();
Map<AnyObjectId, Set<Ref>> ret = new HashMap<>(allRefs.size());
for (Ref ref : allRefs.values()) {
ref = peel(ref);
AnyObjectId target = ref.getPeeledObjectId();
if (target == null)
target = ref.getObjectId();
// We assume most Sets here are singletons
Set<Ref> oset = ret.put(target, Collections.singleton(ref));
if (oset != null) {
// that was not the case (rare)
if (oset.size() == 1) {
// Was a read-only singleton, we must copy to a new Set
oset = new HashSet<>(oset);
}
ret.put(target, oset);
oset.add(ref);
}
}
return ret;
}
代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control
/**
* Method returns the Ref to the commit witht the published tag.
*
* @return - Ref of the published commit
*/
public Ref getPublished() {
try {
val ref = git.tagList().call().get(0);
return git.getRepository().peel(ref);
} catch (final Exception e) {
LOGGER.trace(e.getMessage(), e);
return null;
}
}
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
/**
* @return a map with all objects referenced by a peeled ref.
*/
@NonNull
public Map<AnyObjectId, Set<Ref>> getAllRefsByPeeledObjectId() {
Map<String, Ref> allRefs = getAllRefs();
Map<AnyObjectId, Set<Ref>> ret = new HashMap<AnyObjectId, Set<Ref>>(allRefs.size());
for (Ref ref : allRefs.values()) {
ref = peel(ref);
AnyObjectId target = ref.getPeeledObjectId();
if (target == null)
target = ref.getObjectId();
// We assume most Sets here are singletons
Set<Ref> oset = ret.put(target, Collections.singleton(ref));
if (oset != null) {
// that was not the case (rare)
if (oset.size() == 1) {
// Was a read-only singleton, we must copy to a new Set
oset = new HashSet<Ref>(oset);
}
ret.put(target, oset);
oset.add(ref);
}
}
return ret;
}
代码示例来源:origin: berlam/github-bucket
/**
* Get a map with all objects referenced by a peeled ref.
*
* @return a map with all objects referenced by a peeled ref.
*/
@NonNull
public Map<AnyObjectId, Set<Ref>> getAllRefsByPeeledObjectId() {
Map<String, Ref> allRefs = getAllRefs();
Map<AnyObjectId, Set<Ref>> ret = new HashMap<>(allRefs.size());
for (Ref ref : allRefs.values()) {
ref = peel(ref);
AnyObjectId target = ref.getPeeledObjectId();
if (target == null)
target = ref.getObjectId();
// We assume most Sets here are singletons
Set<Ref> oset = ret.put(target, Collections.singleton(ref));
if (oset != null) {
// that was not the case (rare)
if (oset.size() == 1) {
// Was a read-only singleton, we must copy to a new Set
oset = new HashSet<>(oset);
}
ret.put(target, oset);
oset.add(ref);
}
}
return ret;
}
代码示例来源:origin: tomasbjerre/git-changelog-lib
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;
}
代码示例来源:origin: org.ajoberstar.reckon/reckon-core
private Set<TaggedVersion> getTaggedVersions(RevWalk walk) throws IOException {
Set<TaggedVersion> versions = new HashSet<>();
for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_TAGS).values()) {
Ref tag = repo.peel(ref);
// only annotated tags return a peeled object id
ObjectId objectId = tag.getPeeledObjectId() == null ? tag.getObjectId() : tag.getPeeledObjectId();
RevCommit commit = walk.parseCommit(objectId);
tagParser.apply(tag).ifPresent(version -> {
versions.add(new TaggedVersion(version, commit));
});
}
return versions;
}
代码示例来源:origin: tomasbjerre/git-changelog-lib
private ObjectId getPeeled(final Ref tag) {
final Ref peeledTag = this.repository.peel(tag);
if (peeledTag.getPeeledObjectId() != null) {
return peeledTag.getPeeledObjectId();
} else {
return tag.getObjectId();
}
}
代码示例来源:origin: mauricioaniche/repodriller
private ObjectId getActualRefObjectId(Ref ref, Repository repo) {
final Ref repoPeeled = repo.peel(ref);
if (repoPeeled.getPeeledObjectId() != null) {
return repoPeeled.getPeeledObjectId();
}
return ref.getObjectId();
}
代码示例来源:origin: checkstyle/contribution
/**
* Returns actual SHA-1 object by commit reference.
* @param repo git repository.
* @param ref string representation of commit reference.
* @return actual SHA-1 object.
* @throws IOException if an I/O error occurs.
*/
private static ObjectId getActualRefObjectId(Repository repo, String ref) throws IOException {
final ObjectId actualObjectId;
final Ref referenceObj = repo.getRef(ref);
if (referenceObj == null) {
actualObjectId = repo.resolve(ref);
}
else {
final Ref repoPeeled = repo.peel(referenceObj);
actualObjectId = Optional.ofNullable(repoPeeled.getPeeledObjectId())
.orElse(referenceObj.getObjectId());
}
return actualObjectId;
}
代码示例来源:origin: jenkinsci/git-client-plugin
/** {@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 (!entry.getValue().isPeeled()) {
Ref peeledRef = repo.peel(tagRef);
if (peeledRef.getPeeledObjectId() != null) {
tagRef = peeledRef; // Use peeled ref instead of annotated ref
}
}
if (tagRef.isPeeled()) {
peeledTags.add(new GitObject(tagName, tagRef.getPeeledObjectId()));
} else if (!tagNames.contains(tagName)) {
peeledTags.add(new GitObject(tagName, tagRef.getObjectId()));
}
tagNames.add(entry.getKey());
}
}
return peeledTags;
}
}
代码示例来源:origin: kiegroup/appformer
private RefTree rebuild(RefDatabase refdb) throws IOException {
RefTree tree = RefTree.newEmptyTree();
List<Command> cmds
= new ArrayList<>();
Ref head = refdb.exactRef(HEAD);
if (head != null) {
cmds.add(new org.eclipse.jgit.internal.storage.reftree.Command(
null,
head));
}
for (Ref r : refdb.getRefs(RefDatabase.ALL).values()) {
if (r.getName().equals(txnCommitted) || r.getName().equals(HEAD)
|| r.getName().startsWith(txnNamespace)) {
continue;
}
cmds.add(new org.eclipse.jgit.internal.storage.reftree.Command(
null,
git.getRepository().peel(r)));
}
tree.apply(cmds);
return tree;
}
}
代码示例来源:origin: openl-tablets/openl-tablets
private Ref getTagRefForCommit(List<Ref> tags, ObjectId commitId) {
Ref tagRefForCommit = null;
for (Ref tagRef : tags) {
ObjectId objectId = git.getRepository().peel(tagRef).getPeeledObjectId();
if (objectId == null) {
objectId = tagRef.getObjectId();
}
if (objectId.equals(commitId)) {
tagRefForCommit = tagRef;
break;
}
}
return tagRefForCommit;
}
代码示例来源:origin: org.eclipse.egit/ui
private List<Ref> loadTags() {
RepositoryCommit repoCommit = getCommit();
RevCommit commit = repoCommit.getRevCommit();
Repository repository = repoCommit.getRepository();
List<Ref> tags = new ArrayList<Ref>();
for (Ref tag : getTags()) {
tag = repository.peel(tag);
ObjectId id = tag.getPeeledObjectId();
if (id == null)
id = tag.getObjectId();
if (!commit.equals(id))
continue;
tags.add(tag);
}
return tags;
}
代码示例来源:origin: jboss-fuse/fabric8
@Override
public Map<String, RevTag> findTagsBetween(Git git, RevCommit c1, RevCommit c2) throws GitAPIException, IOException {
Map<ObjectId, List<RevTag>> reverseReferences = new HashMap<>();
RevWalk walk = new RevWalk(git.getRepository());
for (Ref t : git.tagList().call()) {
Ref peeled = git.getRepository().peel(t);
if (peeled != null && peeled.getPeeledObjectId() != null) {
if (!reverseReferences.containsKey(peeled.getPeeledObjectId())) {
reverseReferences.put(peeled.getPeeledObjectId(), new LinkedList<RevTag>());
}
reverseReferences.get(peeled.getPeeledObjectId()).add(walk.parseTag(t.getObjectId()));
}
}
Map<String, RevTag> result = new HashMap<>();
Iterable<RevCommit> commits = git.log().addRange(c1, c2).call();
for (RevCommit commit : commits) {
if (reverseReferences.containsKey(commit.getId())) {
for (RevTag tag : reverseReferences.get(commit.getId())) {
result.put(tag.getTagName(), tag);
}
}
}
return result;
}
代码示例来源:origin: tomasbjerre/git-changelog-lib
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();
}
}
}
throw new GitChangelogRepositoryException(fromRef + " not found in:\n" + toString());
} catch (final Exception e) {
throw new GitChangelogRepositoryException("", e);
}
}
代码示例来源:origin: io.fabric8.patch/patch-management
@Override
public Map<String, RevTag> findTagsBetween(Git git, RevCommit c1, RevCommit c2) throws GitAPIException, IOException {
Map<ObjectId, List<RevTag>> reverseReferences = new HashMap<>();
RevWalk walk = new RevWalk(git.getRepository());
for (Ref t : git.tagList().call()) {
Ref peeled = git.getRepository().peel(t);
if (peeled != null && peeled.getPeeledObjectId() != null) {
if (!reverseReferences.containsKey(peeled.getPeeledObjectId())) {
reverseReferences.put(peeled.getPeeledObjectId(), new LinkedList<RevTag>());
}
reverseReferences.get(peeled.getPeeledObjectId()).add(walk.parseTag(t.getObjectId()));
}
}
Map<String, RevTag> result = new HashMap<>();
Iterable<RevCommit> commits = git.log().addRange(c1, c2).call();
for (RevCommit commit : commits) {
if (reverseReferences.containsKey(commit.getId())) {
for (RevTag tag : reverseReferences.get(commit.getId())) {
result.put(tag.getTagName(), tag);
}
}
}
return result;
}
代码示例来源:origin: jboss-fuse/fabric8
Map<ObjectId, List<RevTag>> tagMap = new HashMap<>();
for (Ref tag : tags) {
Ref peeled = git.getRepository().peel(tag);
RevTag revTag = walk.parseTag(tag.getObjectId());
if (!BASELINE_TAG_PATTERN.matcher(revTag.getTagName()).matches()) {
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
for (Ref ref : refs.values()) {
if(!ref.isPeeled())
ref = getRepository().peel(ref);
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
/**
* Format an advertisement for the supplied refs.
*
* @param refs
* zero or more refs to format for the client. The collection is
* sorted before display if necessary, and therefore may appear
* in any order.
* @return set of ObjectIds that were advertised to the client.
* @throws IOException
* the underlying output stream failed to write out an
* advertisement record.
*/
public Set<ObjectId> send(Map<String, Ref> refs) throws IOException {
for (Ref ref : getSortedRefs(refs)) {
if (ref.getObjectId() == null)
continue;
advertiseAny(ref.getObjectId(), ref.getName());
if (!derefTags)
continue;
if (!ref.isPeeled()) {
if (repository == null)
continue;
ref = repository.peel(ref);
}
if (ref.getPeeledObjectId() != null)
advertiseAny(ref.getPeeledObjectId(), ref.getName() + "^{}"); //$NON-NLS-1$
}
return sent;
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldGetFirstDozenCommitsInHistoryForTag() throws Exception {
Ref ref = repository.getRef("modeshape-3.0.0.Final");
ref = repository.peel(ref);
RevWalk walker = new RevWalk(repository);
walker.setRetainBody(true);
try {
RevCommit commit = walker.parseCommit(ref.getObjectId());
LogCommand command = git.log();
command.add(commit.getId());
command.setMaxCount(12);
for (RevCommit rev : command.call()) {
commit = walker.parseCommit(rev);
print(commit);
}
} finally {
walker.dispose();
}
}
内容来源于网络,如有侵权,请联系作者删除!