本文整理了Java中org.eclipse.jgit.lib.Ref
类的一些代码示例,展示了Ref
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ref
类的具体详情如下:
包路径:org.eclipse.jgit.lib.Ref
类名称:Ref
[英]Pairing of a name and the org.eclipse.jgit.lib.ObjectId it currently has.
A ref in Git is (more or less) a variable that holds a single object identifier. The object identifier can be any valid Git object (blob, tree, commit, annotated tag, ...).
The ref name has the attributes of the ref that was asked for as well as the ref it was resolved to for symbolic refs plus the object id it points to and (for tags) the peeled target object id, i.e. the tag resolved recursively until a non-tag object is referenced.
[中]名称和组织的配对。日食jgit。lib。ObjectId目前有。
Git中的ref(或多或少)是一个包含单个对象标识符的变量。对象标识符可以是任何有效的Git对象(blob、tree、commit、带注释的标记等)。
ref name具有请求的ref的属性,以及符号ref解析为的ref加上它指向的对象id和(标记)剥离的目标对象id,即递归解析的标记,直到引用非标记对象。
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private static String getHeadName(Ref head) {
String headName;
if (head.isSymbolic()) {
headName = head.getTarget().getName();
} else {
ObjectId headId = head.getObjectId();
// the callers are checking this already
assert headId != null;
headName = headId.getName();
}
return headName;
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Include a single ref (a name/object pair) in the bundle.
* <p>
* This is a utility function for:
* <code>include(r.getName(), r.getObjectId())</code>.
*
* @param r
* the ref to include.
*/
public void include(Ref r) {
include(r.getName(), r.getObjectId());
if (r.getPeeledObjectId() != null)
tagTargets.add(r.getPeeledObjectId());
else if (r.getObjectId() != null
&& r.getName().startsWith(Constants.R_HEADS))
tagTargets.add(r.getObjectId());
}
代码示例来源:origin: gocd/gocd
public Long commitCountOnMaster() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException {
// not inside a doLocked/synchronized block because we don't want to block the server status service.
// we do a `git branch` because we switch branches as part of normal git operations,
// and we don't care about number of commits on those branches.
List<Ref> branches = git.branchList().call();
for (Ref branch : branches) {
if (branch.getName().equals("refs/heads/master")) {
Iterable<RevCommit> commits = git.log().add(branch.getObjectId()).call();
long count = 0;
for (RevCommit commit : commits) {
count++;
}
return count;
}
}
return Long.valueOf(-1);
}
}
代码示例来源:origin: jphp-group/jphp
public static ArrayMemory valueOf(Ref ref) {
ArrayMemory memory = new ArrayMemory();
memory.refOfIndex("name").assign(ref.getName());
memory.refOfIndex("peeled").assign(ref.isPeeled());
memory.refOfIndex("symbolic").assign(ref.isSymbolic());
memory.refOfIndex("objectId").assign(valueOf(ref.getObjectId()));
memory.refOfIndex("storage").assign(valueOf(ref.getStorage()));
return memory;
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
@Override
int valueType() {
if (ref.isSymbolic()) {
return VALUE_SYMREF;
} else if (ref.getStorage() == NEW && ref.getObjectId() == null) {
return VALUE_NONE;
} else if (ref.getPeeledObjectId() != null) {
return VALUE_2ID;
} else {
return VALUE_1ID;
}
}
代码示例来源:origin: centic9/jgit-cookbook
try (Git git = Git.cloneRepository()
.setURI(REMOTE_URL)
.setDirectory(localPath)
.call()) {
System.out.println("Having repository: " + git.getRepository().getDirectory());
FetchResult result = git.fetch().setCheckFetchedObjects(true).call();
System.out.println("Messages: " + result.getMessages());
List<Ref> call = git.branchList().call();
for (Ref ref : call) {
System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
call = git.branchList().setListMode(ListMode.ALL).call();
for (Ref ref : call) {
System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
checkCallable();
try (RevWalk revWalk = new RevWalk(repo)) {
Ref headRef = repo.exactRef(Constants.HEAD);
if (headRef == null)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());
ObjectId srcObjectId = src.getPeeledObjectId();
if (srcObjectId == null)
srcObjectId = src.getObjectId();
RevCommit srcCommit = revWalk.parseCommit(srcObjectId);
String revertName = srcCommit.getId().abbreviate(7).name()
+ "\""; //$NON-NLS-1$
String newMessage = shortMessage + "\n\n" //$NON-NLS-1$
+ "This reverts commit " + srcCommit.getId().getName() //$NON-NLS-1$
+ ".\n"; //$NON-NLS-1$
if (merger.merge(headCommit, srcParent)) {
.formatWithConflicts(newMessage,
merger.getUnmergedPaths());
repo.writeRevertHead(srcCommit.getId());
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
checkCallable();
try (RevWalk revWalk = new RevWalk(repo)) {
Ref headRef = repo.exactRef(Constants.HEAD);
if (headRef == null)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
newHead = revWalk.parseCommit(headRef.getObjectId());
ObjectId srcObjectId = src.getPeeledObjectId();
if (srcObjectId == null)
srcObjectId = src.getObjectId();
RevCommit srcCommit = revWalk.parseCommit(srcObjectId);
String cherryPickName = srcCommit.getId().abbreviate(7).name()
+ " " + srcCommit.getShortMessage(); //$NON-NLS-1$
merger.setBase(srcParent.getTree());
merger.setCommitNames(new String[] { "BASE", ourName, //$NON-NLS-1$
cherryPickName });
repo.writeCherryPickHead(srcCommit.getId());
repo.writeMergeCommitMsg(message);
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// See e.g. GetRevCommitFromObjectId for how to use a SHA-1 directly
Ref head = repository.findRef("HEAD");
System.out.println("Ref of HEAD: " + head + ": " + head.getName() + " - " + head.getObjectId().getName());
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(head.getObjectId());
System.out.println("Commit: " + commit);
// a commit points to a tree
RevTree tree = walk.parseTree(commit.getTree().getId());
System.out.println("Found Tree: " + tree);
walk.dispose();
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.findRef("HEAD");
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(head.getObjectId());
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now use a TreeWalk to iterate over all files in the Tree
// you can set Filters to narrow down the results if needed
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(tree);
// not walk the tree recursively so we only get the elements in the top-level directory
treeWalk.setRecursive(false);
while (treeWalk.next()) {
System.out.println("found: " + treeWalk.getPathString());
}
}
}
}
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
try (Git git = new Git(repo)) {
CreateBranchCommand command = git.branchCreate();
command.setName(name);
if (startCommit != null)
Ref headRef = repo.exactRef(Constants.HEAD);
if (headRef == null) {
r.name()));
this.status = CheckoutResult.NOT_TRIED_RESULT;
return repo.exactRef(Constants.HEAD);
try (RevWalk revWalk = new RevWalk(repo)) {
AnyObjectId headId = headRef.getObjectId();
headCommit = headId == null ? null
: revWalk.parseCommit(headId);
newCommit = revWalk.parseCommit(branch);
RevTree headTree = headCommit == null ? null : headCommit.getTree();
if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
Result updateResult;
if (ref != null)
updateResult = refUpdate.link(ref.getName());
else if (orphan) {
updateResult = refUpdate.link(getBranchName());
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.exactRef("refs/heads/master");
System.out.println("Found head: " + head);
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(head.getObjectId());
System.out.println("Found Commit: " + commit);
try (Git git = new Git(repository)) {
git.notesAdd().setMessage("some note message").setObjectId(commit).call();
System.out.println("Added Note to commit " + commit);
List<Note> call = git.notesList().call();
System.out.println("Listing " + call.size() + " notes");
for(Note note : call) {
if(!note.getName().equals(head.getObjectId().getName())) {
System.out.println("Note " + note + " did not match commit " + head);
continue;
ObjectLoader loader = repository.open(note.getData());
loader.copyTo(System.out);
walk.dispose();
代码示例来源:origin: FlowCI/flow-platform
/**
* Get latest commit by ref name from local .git
*/
@Override
public GitCommit commit(String refName) throws GitException {
try (Git git = gitOpen()) {
Repository repo = git.getRepository();
Ref head = repo.findRef(refName);
if (head == null) {
return null;
}
try (RevWalk walk = new RevWalk(repo)) {
RevCommit commit = walk.parseCommit(head.getObjectId());
walk.dispose();
String id = commit.getId().getName();
String message = commit.getFullMessage();
String author = commit.getAuthorIdent().getName();
return new GitCommit(id, message, author);
}
} catch (IOException e) {
throw new GitException("Fail to get commit message", e);
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
try (Git git = new Git(repository)) {
List<Ref> call = git.tagList().call();
for (Ref ref : call) {
System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
// fetch all commits for this tag
LogCommand log = git.log();
Ref peeledRef = repository.getRefDatabase().peel(ref);
if(peeledRef.getPeeledObjectId() != null) {
log.add(peeledRef.getPeeledObjectId());
} else {
log.add(ref.getObjectId());
}
Iterable<RevCommit> logs = log.call();
for (RevCommit rev : logs) {
System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
}
}
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, GitAPIException {
try (Git git = new Git(repository)) {
List<Ref> call = git.branchList().call();
for (Ref ref : call) {
System.out.println("Branch-Before: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
List<Ref> refs = git.branchList().call();
for(Ref ref : refs) {
System.out.println("Had branch: " + ref.getName());
if(ref.getName().equals("refs/heads/testbranch")) {
System.out.println("Removing branch before");
git.branchDelete()
.call();
call = git.branchList().call();
for (Ref ref : call) {
System.out.println("Branch-Created: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
call = git.branchList().call();
for (Ref ref : call) {
System.out.println("Branch-After: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
代码示例来源:origin: centic9/jgit-cookbook
private static AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException {
// from the commit we can build the tree which allows us to construct the TreeParser
Ref head = repository.exactRef(ref);
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(head.getObjectId());
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader reader = repository.newObjectReader()) {
treeParser.reset(reader, tree.getId());
}
walk.dispose();
return treeParser;
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
System.out.println("Listing local branches:");
try (Git git = new Git(repository)) {
List<Ref> call = git.branchList().call();
for (Ref ref : call) {
System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
}
System.out.println("Now including remote branches:");
call = git.branchList().setListMode(ListMode.ALL).call();
for (Ref ref : call) {
System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
}
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// the Ref holds an ObjectId for any type of object (tree, commit, blob, tree)
Ref head = repository.exactRef("refs/heads/master");
System.out.println("Ref of refs/heads/master: " + head);
System.out.println("\nPrint contents of head of master branch, i.e. the latest commit information");
ObjectLoader loader = repository.open(head.getObjectId());
loader.copyTo(System.out);
System.out.println("\nPrint contents of tree of head of master branch, i.e. the latest binary tree information");
// a commit points to a tree
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(head.getObjectId());
RevTree tree = walk.parseTree(commit.getTree().getId());
System.out.println("Found Tree: " + tree);
loader = repository.open(tree.getId());
loader.copyTo(System.out);
walk.dispose();
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
try (Git git = new Git(repository)) {
List<Ref> refs = git.branchList().call();
for (Ref ref : refs) {
System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
listReflog(repository, ref);
}
List<Ref> call = git.tagList().call();
for (Ref ref : call) {
System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
listReflog(repository, ref);
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.exactRef("refs/heads/master");
System.out.println("Found head: " + head);
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(head.getObjectId());
System.out.println("Found Commit: " + commit);
// You can also get the commit for an (abbreviated) SHA
walk.reset();
ObjectId id = repository.resolve("38d51408bd");
RevCommit commitAgain = walk.parseCommit(id);
System.out.println("Found Commit again: " + commitAgain);
walk.dispose();
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!