本文整理了Java中org.eclipse.jgit.lib.Repository.getAllRefs
方法的一些代码示例,展示了Repository.getAllRefs
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.getAllRefs
方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:getAllRefs
[英]Get mutable map of all known refs, including symrefs like HEAD that may not point to any object yet.
[中]获取所有已知参照物的可变地图,包括可能尚未指向任何对象的类似于头部的符号参照物。
代码示例来源: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: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// get a list of all known heads, tags, remotes, ...
Collection<Ref> allRefs = repository.getAllRefs().values();
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk revWalk = new RevWalk( repository )) {
for( Ref ref : allRefs ) {
revWalk.markStart( revWalk.parseCommit( ref.getObjectId() ));
}
System.out.println("Walking all commits starting with " + allRefs.size() + " refs: " + allRefs);
int count = 0;
for( RevCommit commit : revWalk ) {
System.out.println("Commit: " + commit);
count++;
}
System.out.println("Had " + count + " commits");
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// get a list of all known heads, tags, remotes, ...
Collection<Ref> allRefs = repository.getAllRefs().values();
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk revWalk = new RevWalk( repository )) {
for( Ref ref : allRefs ) {
revWalk.markStart( revWalk.parseCommit( ref.getObjectId() ));
}
System.out.println("Walking all commits starting with " + allRefs.size() + " refs: " + allRefs);
int count = 0;
for( RevCommit commit : revWalk ) {
System.out.println("Commit: " + commit);
count++;
}
System.out.println("Had " + count + " commits");
}
}
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
refs = allRefs != null ? allRefs : db.getAllRefs();
refs = refFilter.filter(refs);
advertisedHaves.clear();
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Set the refs advertised by this UploadPack.
* <p>
* Intended to be called from a
* {@link org.eclipse.jgit.transport.PreUploadHook}.
*
* @param allRefs
* explicit set of references to claim as advertised by this
* UploadPack instance. This overrides any references that may
* exist in the source repository. The map is passed to the
* configured {@link #getRefFilter()}. If null, assumes all refs
* were advertised.
*/
public void setAdvertisedRefs(Map<String, Ref> allRefs) {
if (allRefs != null)
refs = allRefs;
else
refs = db.getAllRefs();
if (refFilter == RefFilter.DEFAULT)
refs = transferConfig.getRefFilter().filter(refs);
else
refs = refFilter.filter(refs);
}
代码示例来源:origin: stackoverflow.com
private static boolean hasAtLeastOneReference(Repository repo) {
for (Ref ref : repo.getAllRefs().values()) {
if (ref.getObjectId() == null)
continue;
return true;
}
return false;
}
代码示例来源:origin: tomasbjerre/git-changelog-lib
private Map<String, Ref> getAllRefs() {
return this.repository.getAllRefs();
}
代码示例来源:origin: ixrjog/opsCloud
/**
* 获取指定仓库的所有分支
*
* @param repository
* @return
*/
public static Set<String> getRefList(Repository repository) {
return repository.getAllRefs().keySet();
}
代码示例来源:origin: alien4cloud/alien4cloud
/**
* Generate the conflict branch name to push to.
*/
private static String generateConflictBranchName(Repository repository, String remoteName) {
Map<String, Ref> allRefs = repository.getAllRefs();
String remoteAlienRefSpecPrefixName = String.format("refs/remotes/%s/%s", remoteName, REMOTE_ALIEN_CONFLICTS_PREFIX_BRANCH_NAME);
long count = allRefs.keySet().stream().filter(key -> key.startsWith(remoteAlienRefSpecPrefixName)).count();
return String.format("%s%d-%d", REMOTE_ALIEN_CONFLICTS_PREFIX_BRANCH_NAME, new Date().getTime(), count + 1);
}
代码示例来源:origin: alien4cloud/alien4cloud
private static String getFullTagReference(Git repository, String branch) {
Map<String, Ref> refs = repository.getRepository().getAllRefs();
for (String refId : refs.keySet()) {
String[] segments = refId.split("/");
if (segments.length > 1 && branch.equals(segments[segments.length - 1]) && "tags".equals(segments[1])) {
return refId;
}
}
return "";
}
代码示例来源:origin: apigee/apigee-deploy-maven-plugin
public Ref getWorkspaceHeadRevision() {
Map<String, Ref> refs = git.getRepository().getAllRefs();
Ref headRef = refs.get("HEAD");
return headRef;
}
代码示例来源:origin: alien4cloud/alien4cloud
private static String getFullBranchReference(Git repository, String branch) {
final String remoteName = "remotes/origin";
Map<String, Ref> refs = repository.getRepository().getAllRefs();
for (String refId : refs.keySet()) {
String[] segments = refId.split("/");
if (segments.length > 1 && branch.equals(segments[segments.length - 1]) && refId.contains(remoteName)) {
return refId;
}
}
return "";
}
代码示例来源:origin: org.arquillian.algeron/arquillian-algeron-git
/**
* Checks if a repo has been cloned correctly.
*
* @param repo
* to check
*
* @return true if has been cloned correctly, false otherwise
*/
public boolean hasAtLeastOneReference(Repository repo) {
for (Ref ref : repo.getAllRefs().values()) {
if (ref.getObjectId() == null)
continue;
return true;
}
return false;
}
}
代码示例来源:origin: jenkinsci/git-client-plugin
private List<Ref> getAllBranchRefs(boolean originBranches) {
List<Ref> branches = new ArrayList<>();
try (Repository repo = getRepository()) {
for (Ref r : repo.getAllRefs().values()) {
final String branchName = r.getName();
if (branchName.startsWith(R_HEADS)
|| (originBranches && branchName.startsWith(R_REMOTES))) {
branches.add(r);
}
}
}
return branches;
}
代码示例来源:origin: stackoverflow.com
Repository repo = new FileRepository(args[0]);
RevWalk walk = new RevWalk(repo);
RevCommit commit = walk.parseCommit(repo.resolve(args[1] + "^0"));
for (Map.Entry<String, Ref> e : repo.getAllRefs().entrySet())
if (e.getKey().startsWith(Constants.R_HEADS))
if (walk.isMergedInto(commit,
walk.parseCommit(e.getValue().getObjectId())))
System.out.println("Ref " + e.getValue().getName()
+ " contains commit " + commit);
代码示例来源:origin: org.openmrs.maven.plugins/openmrs-sdk-maven-plugin
/**
* @inheritDoc
*/
@Override
public Iterable<RevCommit> getCommitDifferential(Git git, String baseRef, String headRef) {
Ref localRef = git.getRepository().getAllRefs().get(headRef);
Ref upstreamRef = git.getRepository().getAllRefs().get(baseRef);
try {
return git.log().addRange(upstreamRef.getObjectId(), localRef.getObjectId()).call();
} catch (GitAPIException|MissingObjectException|IncorrectObjectTypeException e) {
throw new RuntimeException("Failed to get commit differential between"+baseRef+" and "+headRef);
}
}
代码示例来源:origin: jenkinsci/git-client-plugin
/**
* Adds all matching refs as start commits.
*/
private void markRefs(RevWalk walk, Predicate<Ref> filter) throws IOException {
try (Repository repo = getRepository()) {
for (Ref r : repo.getAllRefs().values()) {
if (filter.apply(r)) {
RevCommit c = walk.parseCommit(r.getObjectId());
walk.markStart(c);
}
}
}
}
代码示例来源:origin: io.fabric8/fabric-git
public static boolean hasGitHead(Git git) throws GitAPIException, IOException {
boolean hasHead = true;
try {
git.log().all().call();
hasHead = git.getRepository().getAllRefs().containsKey("HEAD");
} catch (NoHeadException e) {
hasHead = false;
}
return hasHead;
}
代码示例来源:origin: jboss-fuse/fabric8
public static boolean hasGitHead(Git git) throws GitAPIException, IOException {
boolean hasHead = true;
try {
git.log().all().call();
hasHead = git.getRepository().getAllRefs().containsKey("HEAD");
} catch (NoHeadException e) {
hasHead = false;
}
return hasHead;
}
代码示例来源:origin: com.atlassian.labs/speakeasy-plugin
public File operateOn(Repository repo) throws Exception
{
Git git = new Git(repo);
if (repo.getAllRefs().containsKey("refs/heads/master"))
{
git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD").call();
for (String path : git.status().call().getUntracked())
{
new File(repo.getWorkTree(), path).delete();
}
}
return ZipWriter.addDirectoryContentsToJar(repo.getWorkTree(), ".git");
}
});
内容来源于网络,如有侵权,请联系作者删除!