org.eclipse.jgit.revwalk.RevObject Java Examples

The following examples show how to use org.eclipse.jgit.revwalk.RevObject. 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: DefaultCommitInfoManager.java    From onedev with MIT License 6 votes vote down vote up
private void collect(Project project) {
	List<CollectingWork> works = new ArrayList<>();
	try (RevWalk revWalk = new RevWalk(project.getRepository())) {
		Collection<Ref> refs = new ArrayList<>();
		refs.addAll(project.getRepository().getRefDatabase().getRefsByPrefix(Constants.R_HEADS));
		refs.addAll(project.getRepository().getRefDatabase().getRefsByPrefix(Constants.R_TAGS));

		for (Ref ref: refs) {
			RevObject revObj = revWalk.peel(revWalk.parseAny(ref.getObjectId()));
			if (revObj instanceof RevCommit)
				works.add(new CollectingWork(PRIORITY, (RevCommit) revObj, ref.getName()));
		}
	} catch (IOException e) {
		throw new RuntimeException(e);
	}

	Collections.sort(works, new CommitTimeComparator());
	
	for (CollectingWork work: works)
		batchWorkManager.submit(getBatchWorker(project.getId()), work);
}
 
Example #2
Source File: CreateTagCommand.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    try {
        RevObject obj = Utils.findObject(repository, taggedObject);
        TagCommand cmd = new Git(repository).tag();
        cmd.setName(tagName);
        cmd.setForceUpdate(forceUpdate);
        cmd.setObjectId(obj);
        cmd.setAnnotated(message != null && !message.isEmpty() || signed);
        if (cmd.isAnnotated()) {
            cmd.setMessage(message);
            cmd.setSigned(signed);
        }
        cmd.call();
        ListTagCommand tagCmd = new ListTagCommand(repository, getClassFactory(), false, new DelegatingGitProgressMonitor(monitor));
        tagCmd.run();
        Map<String, GitTag> tags = tagCmd.getTags();
        tag = tags.get(tagName);
    } catch (JGitInternalException | GitAPIException ex) {
        throw new GitException(ex);
    }
}
 
Example #3
Source File: GitTag.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private GitObjectType getType (RevObject object) {
    GitObjectType objType = GitObjectType.UNKNOWN;
    if (object != null) {
        switch (object.getType()) {
            case Constants.OBJ_COMMIT:
                objType = GitObjectType.COMMIT;
                break;
            case Constants.OBJ_BLOB:
                objType = GitObjectType.BLOB;
                break;
            case Constants.OBJ_TAG:
                objType = GitObjectType.TAG;
                break;
            case Constants.OBJ_TREE:
                objType = GitObjectType.TREE;
                break;
        }
    }
    return objType;
}
 
Example #4
Source File: Tag.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
private RevCommit parseCommit() {
	if (this.commit == null) {
		RevWalk rw = new RevWalk(db);
		RevObject any;
		try {
			any = rw.parseAny(this.ref.getObjectId());
			if (any instanceof RevTag) {
				this.tag = (RevTag) any;
				RevObject o = rw.peel(any);
				if (o instanceof RevCommit) {
					this.commit = (RevCommit) rw.peel(any);
				}
			} else if (any instanceof RevCommit) {
				this.commit = (RevCommit) any;
			}
		} catch (IOException e) {
		} finally {
			rw.dispose();
		}
	}
	return commit;
}
 
Example #5
Source File: JGitAPIImpl.java    From git-client-plugin with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Deprecated
@Override
public List<IndexEntry> lsTree(String treeIsh, boolean recursive) throws GitException, InterruptedException {
    try (Repository repo = getRepository();
         ObjectReader or = repo.newObjectReader();
         RevWalk w = new RevWalk(or)) {
        TreeWalk tree = new TreeWalk(or);
        tree.addTree(w.parseTree(repo.resolve(treeIsh)));
        tree.setRecursive(recursive);

        List<IndexEntry> r = new ArrayList<>();
        while (tree.next()) {
            RevObject rev = w.parseAny(tree.getObjectId(0));
            r.add(new IndexEntry(
                    String.format("%06o", tree.getRawMode(0)),
                    typeString(rev.getType()),
                    tree.getObjectId(0).name(),
                    tree.getNameString()));
        }
        return r;
    } catch (IOException e) {
        throw new GitException(e);
    }
}
 
Example #6
Source File: GitUtils.java    From jphp with Apache License 2.0 6 votes vote down vote up
public static ArrayMemory valueOf(RevCommit value) {
    ArrayMemory memory = valueOf((RevObject) value);

    memory.refOfIndex("commitTime").assign(value.getCommitTime());
    memory.refOfIndex("encoding").assign(value.getEncodingName());
    memory.refOfIndex("shortMessage").assign(value.getShortMessage());
    memory.refOfIndex("fullMessage").assign(value.getFullMessage());
    
    ArrayMemory parents = new ArrayMemory();
    for (RevCommit revCommit : value.getParents()) {
        parents.add(valueOf((RevObject)revCommit));
    }

    memory.refOfIndex("parents").assign(parents);

    PersonIdent authorIdent = value.getAuthorIdent();
    memory.refOfIndex("author").assign(authorIdent == null ? Memory.NULL : valueOf(authorIdent));

    PersonIdent committerIdent = value.getCommitterIdent();
    memory.refOfIndex("committer").assign(committerIdent == null ? Memory.NULL : valueOf(committerIdent));

    return memory;
}
 
Example #7
Source File: Merger.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Merge together two or more tree-ish objects.
 * <p>
 * Any tree-ish may be supplied as inputs. Commits and/or tags pointing at
 * trees or commits may be passed as input objects.
 *
 * @since 3.5
 * @param flush
 *            whether to flush and close the underlying object inserter when
 *            finished to store any content-merged blobs and virtual merged
 *            bases; if false, callers are responsible for flushing.
 * @param tips
 *            source trees to be combined together. The merge base is not
 *            included in this set.
 * @return true if the merge was completed without conflicts; false if the
 *         merge strategy cannot handle this merge or there were conflicts
 *         preventing it from automatically resolving all paths.
 * @throws IncorrectObjectTypeException
 *             one of the input objects is not a commit, but the strategy
 *             requires it to be a commit.
 * @throws java.io.IOException
 *             one or more sources could not be read, or outputs could not
 *             be written to the Repository.
 */
public boolean merge(boolean flush, AnyObjectId... tips)
		throws IOException {
	sourceObjects = new RevObject[tips.length];
	for (int i = 0; i < tips.length; i++)
		sourceObjects[i] = walk.parseAny(tips[i]);

	sourceCommits = new RevCommit[sourceObjects.length];
	for (int i = 0; i < sourceObjects.length; i++) {
		try {
			sourceCommits[i] = walk.parseCommit(sourceObjects[i]);
		} catch (IncorrectObjectTypeException err) {
			sourceCommits[i] = null;
		}
	}

	sourceTrees = new RevTree[sourceObjects.length];
	for (int i = 0; i < sourceObjects.length; i++)
		sourceTrees[i] = walk.parseTree(sourceObjects[i]);

	try {
		boolean ok = mergeImpl();
		if (ok && flush)
			inserter.flush();
		return ok;
	} finally {
		if (flush)
			inserter.close();
		reader.close();
	}
}
 
Example #8
Source File: GitTag.java    From netbeans with Apache License 2.0 5 votes vote down vote up
GitTag (String tagName, RevObject revObject) {
    this.id = ObjectId.toString(revObject.getId());
    this.name = tagName;
    this.message = null;
    this.taggedObject = id;
    this.tagger = null;
    this.type = getType(revObject);
    this.lightWeight = true;
}
 
Example #9
Source File: LayoutHelper.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Unwrap commit from reference.
 *
 * @param revWalk  Git parser.
 * @param objectId Reference object.
 * @return Wrapped commit or null (ex: tag on tree).
 * @throws IOException .
 */
@Nullable
private static RevCommit unwrapCommit(@NotNull RevWalk revWalk, @NotNull ObjectId objectId) throws IOException {
  RevObject revObject = revWalk.parseAny(objectId);
  while (true) {
    if (revObject instanceof RevCommit) {
      return (RevCommit) revObject;
    }
    if (revObject instanceof RevTag) {
      revObject = ((RevTag) revObject).getObject();
      continue;
    }
    return null;
  }
}
 
Example #10
Source File: RefInfo.java    From onedev with MIT License 4 votes vote down vote up
public RefInfo(Ref ref, RevObject obj, RevObject peeledObj) {
	this.ref = ref;
	this.obj = obj;
	this.peeledObj = peeledObj;
}
 
Example #11
Source File: RefInfo.java    From onedev with MIT License 4 votes vote down vote up
public RevObject getObj() {
	return obj;
}
 
Example #12
Source File: RefInfo.java    From onedev with MIT License 4 votes vote down vote up
public RevObject getPeeledObj() {
	return peeledObj;
}
 
Example #13
Source File: GitClassFactoryImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public GitTag createTag (String tagName, RevObject revObject) {
    return new GitTag(tagName, revObject);
}
 
Example #14
Source File: GitUtils.java    From jphp with Apache License 2.0 4 votes vote down vote up
public static ArrayMemory valueOf(RevObject value) {
    ArrayMemory memory = new ArrayMemory();
    memory.refOfIndex("id").assign(valueOf(value.getId()));
    memory.refOfIndex("type").assign(value.getType());
    return memory;
}
 
Example #15
Source File: GitLogUtil.java    From maven-confluence-plugin with Apache License 2.0 2 votes vote down vote up
protected static RevCommit resolveCommitIdByTagName(Repository repository, String tagName) throws IOException, GitAPIException {
    if (tagName == null || tagName.isEmpty()) return null;
    
    RevCommit revCommit = null;
    
    final Map<String, Ref> tagMap = repository.getTags();
    
    final Ref ref = tagMap.get(tagName);
    
    if (ref != null) {
        
        try(RevWalk walk = new RevWalk(repository)) {
            //some reduce memory effors as described in jgit user guide
            walk.setRetainBody(false);
            
            ObjectId from = repository.resolve("refs/heads/master");
            
            if (from == null) {
                try(Git git = new Git(repository)) {
                    final String lastTagName = git.describe().call();
                    from = repository.resolve("refs/tags/" + lastTagName);
                }
            }

            if (from==null){
                throw new IllegalStateException("cannot determinate start commit");
            }
            
            ObjectId to = repository.resolve("refs/remotes/origin/master");

            walk.markStart(walk.parseCommit(from));
            walk.markUninteresting(walk.parseCommit(to));

            RevObject revObject = walk.parseAny(ref.getObjectId());
            if (revObject != null) {
                revCommit = walk.parseCommit(revObject.getId());

            }

        }

    }

    return revCommit;

}
 
Example #16
Source File: GitClassFactory.java    From netbeans with Apache License 2.0 votes vote down vote up
public abstract GitTag createTag (String tagName, RevObject revObject);