List of usage examples for org.eclipse.jgit.revwalk RevFlagSet add
@Override public boolean add(RevFlag flag)
From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCache.java
License:Open Source License
/** * Scans given {@code repo} and build list of commits between two given * RevCommit objectId's. Each commit contains list of changed resources * * @param repo// w w w. j a v a2 s . co m * repository that should be scanned * @param srcId * RevCommit id that git history traverse will start from * @param dstId * RevCommit id that git history traverse will end * @param pathFilter * path filter definition or {@code null} when all paths should * be included * @return list of {@link Commit} object's between {@code srcId} and * {@code dstId} * @throws IOException */ public static List<Commit> build(Repository repo, ObjectId srcId, ObjectId dstId, TreeFilter pathFilter) throws IOException { if (dstId.equals(srcId)) return new ArrayList<Commit>(0); final RevWalk rw = new RevWalk(repo); final RevFlag localFlag = rw.newFlag("local"); //$NON-NLS-1$ final RevFlag remoteFlag = rw.newFlag("remote"); //$NON-NLS-1$ final RevFlagSet allFlags = new RevFlagSet(); allFlags.add(localFlag); allFlags.add(remoteFlag); rw.carry(allFlags); RevCommit srcCommit = rw.parseCommit(srcId); srcCommit.add(localFlag); rw.markStart(srcCommit); srcCommit = null; // free not needed resources RevCommit dstCommit = rw.parseCommit(dstId); dstCommit.add(remoteFlag); rw.markStart(dstCommit); dstCommit = null; // free not needed resources if (pathFilter != null) rw.setTreeFilter(pathFilter); List<Commit> result = new ArrayList<Commit>(); for (RevCommit revCommit : rw) { if (revCommit.hasAll(allFlags)) break; Commit commit = new Commit(); commit.shortMessage = revCommit.getShortMessage(); commit.commitId = AbbreviatedObjectId.fromObjectId(revCommit); commit.authorName = revCommit.getAuthorIdent().getName(); commit.committerName = revCommit.getCommitterIdent().getName(); commit.commitDate = revCommit.getAuthorIdent().getWhen(); RevCommit actualCommit, parentCommit; if (revCommit.has(localFlag)) { actualCommit = revCommit; parentCommit = getParentCommit(revCommit); commit.direction = RIGHT; } else if (revCommit.has(remoteFlag)) { actualCommit = getParentCommit(revCommit); parentCommit = revCommit; commit.direction = LEFT; } else throw new GitCommitsModelDirectionException(); commit.children = getChangedObjects(repo, actualCommit, parentCommit, pathFilter, commit.direction); if (commit.children != null) result.add(commit); } rw.dispose(); return result; }
From source file:org.eclipse.egit.ui.internal.synchronize.model.GitModelRepository.java
License:Open Source License
private void getChildrenImpl() { RevWalk rw = new RevWalk(repo); RevFlag localFlag = rw.newFlag("local"); //$NON-NLS-1$ RevFlag remoteFlag = rw.newFlag("remote"); //$NON-NLS-1$ RevFlagSet allFlags = new RevFlagSet(); allFlags.add(localFlag); allFlags.add(remoteFlag);// w ww . j ava2 s. c om rw.carry(allFlags); List<GitModelObjectContainer> result = new ArrayList<GitModelObjectContainer>(); rw.setRetainBody(true); try { RevCommit srcCommit = rw.parseCommit(srcRev); srcCommit.add(localFlag); rw.markStart(srcCommit); RevCommit dstCommit = rw.parseCommit(dstRev); dstCommit.add(remoteFlag); rw.markStart(dstCommit); for (RevCommit nextCommit : rw) { if (nextCommit.hasAll(allFlags)) break; if (nextCommit.has(localFlag)) result.add(new GitModelCommit(this, nextCommit, RIGHT)); else if (nextCommit.has(remoteFlag)) result.add(new GitModelCommit(this, nextCommit, LEFT)); } if (includeLocal) { result.add(new GitModelCache(this, srcCommit)); result.add(new GitModelWorkingTree(this, srcCommit)); } } catch (IOException e) { Activator.logError(e.getMessage(), e); } childrens = result.toArray(new GitModelObjectContainer[result.size()]); }