diff options
Diffstat (limited to 'org.eclipse.jgit/src')
11 files changed, 88 insertions, 79 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java index e0c7bdd396..dda108bc69 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java @@ -66,7 +66,7 @@ abstract class AbstractRevQueue extends Generator { * flag that controls admission to the queue. */ public final void addParents(RevCommit c, RevFlag queueControl) { - final RevCommit[] pList = c.parents; + final RevCommit[] pList = c.getParents(); if (pList == null) { return; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java index 8b78d062b5..bdf63ff10b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java @@ -76,11 +76,12 @@ class BoundaryGenerator extends Generator { IncorrectObjectTypeException, IOException { RevCommit c = source.next(); if (c != null) { - for (int i = 0; i < c.parents.length; i++) { + int n = c.getParentCount(); + for (int i = 0; i < n; i++) { if (firstParent && i > 0) { break; } - RevCommit p = c.parents[i]; + RevCommit p = c.getParent(i); if ((p.flags & UNINTERESTING) != 0) { held.add(p); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java index 3a2cb8b0f9..ec0824cb0b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java @@ -164,11 +164,12 @@ class DepthGenerator extends Generator { int newDepth = c.depth + 1; - for (int i = 0; i < c.parents.length; i++) { + int n = c.getParentCount(); + for (int i = 0; i < n; i++) { if (firstParent && i > 0) { break; } - RevCommit p = c.parents[i]; + RevCommit p = c.getParent(i); DepthWalk.Commit dp = (DepthWalk.Commit) p; // If no depth has been assigned to this commit, assign diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java index c0fea75777..a213dd47c6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java @@ -114,7 +114,7 @@ class MergeBaseGenerator extends Generator { return null; } - for (RevCommit p : c.parents) { + for (RevCommit p : c.getParents()) { if ((p.flags & IN_PENDING) != 0) continue; if ((p.flags & PARSED) == 0) @@ -180,7 +180,7 @@ class MergeBaseGenerator extends Generator { private void carryOntoHistoryInnerLoop(RevCommit c, int carry) { for (;;) { - RevCommit[] parents = c.parents; + RevCommit[] parents = c.getParents(); if (parents == null || parents.length == 0) { break; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java index add387de03..a49f787316 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java @@ -108,8 +108,9 @@ class PendingGenerator extends Generator { produce = filter.include(walker, c); } - for (int i = 0; i < c.parents.length; i++) { - RevCommit p = c.parents[i]; + int parentCount = c.getParentCount(); + for (int i = 0; i < parentCount; i++) { + RevCommit p = c.getParent(i); // If the commit is uninteresting, don't try to prune // parents because we want the maximal uninteresting set. if (firstParent && i > 0 && (c.flags & UNINTERESTING) == 0) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java index 82725f3db9..7a74e314f6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java @@ -102,7 +102,12 @@ public class RevCommit extends RevObject { private RevTree tree; - RevCommit[] parents; + /** + * Avoid accessing this field directly. Use method + * {@link RevCommit#getParents()} instead. RevCommit does not allow parents + * to be overridden and altering parent(s) is not supported. + */ + protected RevCommit[] parents; int commitTime; // An int here for performance, overflows in 2038 @@ -146,7 +151,7 @@ public class RevCommit extends RevObject { tree = walk.lookupTree(idBuffer); int ptr = 46; - if (parents == null) { + if (getParents() == null) { RevCommit[] pList = new RevCommit[1]; int nParents = 0; for (;;) { @@ -210,8 +215,8 @@ public class RevCommit extends RevObject { } private static FIFORevQueue carryFlags1(RevCommit c, int carry, int depth) { - for(;;) { - RevCommit[] pList = c.parents; + for (;;) { + RevCommit[] pList = c.getParents(); if (pList == null || pList.length == 0) return null; if (pList.length != 1) { @@ -259,7 +264,7 @@ public class RevCommit extends RevObject { // Commits in q have non-null parent arrays and have set all // flags in carry. This loop finishes copying over the graph. for (RevCommit c; (c = q.next()) != null;) { - for (RevCommit p : c.parents) + for (RevCommit p : c.getParents()) carryOneStep(q, carry, p); } } @@ -267,7 +272,7 @@ public class RevCommit extends RevObject { private static void carryOneStep(FIFORevQueue q, int carry, RevCommit c) { if ((c.flags & carry) != carry) { c.flags |= carry; - if (c.parents != null) + if (c.getParents() != null) q.add(c); } } @@ -313,8 +318,8 @@ public class RevCommit extends RevObject { * * @return number of parents; always a positive value but can be 0. */ - public final int getParentCount() { - return parents.length; + public int getParentCount() { + return parents == null ? 0 : parents.length; } /** @@ -327,7 +332,7 @@ public class RevCommit extends RevObject { * @throws java.lang.ArrayIndexOutOfBoundsException * an invalid parent index was specified. */ - public final RevCommit getParent(int nth) { + public RevCommit getParent(int nth) { return parents[nth]; } @@ -341,7 +346,7 @@ public class RevCommit extends RevObject { * * @return the array of parents. */ - public final RevCommit[] getParents() { + public RevCommit[] getParents() { return parents; } @@ -353,9 +358,9 @@ public class RevCommit extends RevObject { * this buffer should be very careful to ensure they do not modify its * contents during their use of it. * - * @return the raw unparsed commit body. This is <b>NOT A COPY</b>. - * Altering the contents of this buffer may alter the walker's - * knowledge of this commit, and the results it produces. + * @return the raw unparsed commit body. This is <b>NOT A COPY</b>. Altering + * the contents of this buffer may alter the walker's knowledge of + * this commit, and the results it produces. */ public final byte[] getRawBuffer() { return buffer; @@ -380,7 +385,7 @@ public class RevCommit extends RevObject { */ public final byte[] getRawGpgSignature() { final byte[] raw = buffer; - final byte[] header = {'g', 'p', 'g', 's', 'i', 'g'}; + final byte[] header = { 'g', 'p', 'g', 's', 'i', 'g' }; final int start = RawParseUtils.headerStart(header, raw, 0); if (start < 0) { return null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java index a25948e50b..8da36c5243 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java @@ -154,7 +154,9 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { */ static final int TREE_REV_FILTER_APPLIED = 1 << 7; - /** Number of flag bits we keep internal for our own use. See above flags. */ + /** + * Number of flag bits we keep internal for our own use. See above flags. + */ static final int RESERVED_FLAGS = 8; private static final int APP_FLAGS = -1 & ~((1 << RESERVED_FLAGS) - 1); @@ -196,9 +198,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { boolean shallowCommitsInitialized; private enum GetMergedIntoStrategy { - RETURN_ON_FIRST_FOUND, - RETURN_ON_FIRST_NOT_FOUND, - EVALUATE_ALL + RETURN_ON_FIRST_FOUND, RETURN_ON_FIRST_NOT_FOUND, EVALUATE_ALL } /** @@ -219,8 +219,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * * @param or * the reader the walker will obtain data from. The reader is not - * closed when the walker is closed (but is closed by {@link - * #dispose()}. + * closed when the walker is closed (but is closed by + * {@link #dispose()}. */ public RevWalk(ObjectReader or) { this(or, false); @@ -381,9 +381,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.io.IOException * a pack file or loose object could not be read. */ - public void markUninteresting(RevCommit c) - throws MissingObjectException, IncorrectObjectTypeException, - IOException { + public void markUninteresting(RevCommit c) throws MissingObjectException, + IncorrectObjectTypeException, IOException { c.flags |= UNINTERESTING; carryFlagsImpl(c); markStart(c); @@ -392,8 +391,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { /** * Determine if a commit is reachable from another commit. * <p> - * A commit <code>base</code> is an ancestor of <code>tip</code> if we - * can find a path of commits that leads from <code>tip</code> and ends at + * A commit <code>base</code> is an ancestor of <code>tip</code> if we can + * find a path of commits that leads from <code>tip</code> and ends at * <code>base</code>. * <p> * This utility function resets the walker, inserts the two supplied @@ -462,7 +461,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @since 5.12 */ public List<Ref> getMergedInto(RevCommit commit, Collection<Ref> refs) - throws IOException{ + throws IOException { return getMergedInto(commit, refs, NullProgressMonitor.INSTANCE); } @@ -486,9 +485,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @since 5.12 */ public List<Ref> getMergedInto(RevCommit commit, Collection<Ref> refs, - ProgressMonitor monitor) throws IOException{ - return getMergedInto(commit, refs, - GetMergedIntoStrategy.EVALUATE_ALL, + ProgressMonitor monitor) throws IOException { + return getMergedInto(commit, refs, GetMergedIntoStrategy.EVALUATE_ALL, monitor); } @@ -531,12 +529,11 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { throws IOException { return getMergedInto(commit, refs, GetMergedIntoStrategy.RETURN_ON_FIRST_NOT_FOUND, - NullProgressMonitor.INSTANCE).size() - == refs.size(); + NullProgressMonitor.INSTANCE).size() == refs.size(); } private List<Ref> getMergedInto(RevCommit needle, Collection<Ref> haystacks, - Enum returnStrategy, ProgressMonitor monitor) throws IOException { + Enum returnStrategy, ProgressMonitor monitor) throws IOException { List<Ref> result = new ArrayList<>(); List<RevCommit> uninteresting = new ArrayList<>(); List<RevCommit> marked = new ArrayList<>(); @@ -547,7 +544,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { reset(~freeFlags & APP_FLAGS); filter = RevFilter.ALL; treeFilter = TreeFilter.ALL; - for (Ref r: haystacks) { + for (Ref r : haystacks) { if (monitor.isCancelled()) { return result; } @@ -574,7 +571,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { break; } } - if(!commitFound){ + if (!commitFound) { markUninteresting(c); uninteresting.add(c); if (returnStrategy == GetMergedIntoStrategy.RETURN_ON_FIRST_NOT_FOUND) { @@ -990,9 +987,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * a pack file or loose object could not be read. */ @NonNull - public RevCommit parseCommit(AnyObjectId id) - throws MissingObjectException, IncorrectObjectTypeException, - IOException { + public RevCommit parseCommit(AnyObjectId id) throws MissingObjectException, + IncorrectObjectTypeException, IOException { RevObject c = peel(parseAny(id)); if (!(c instanceof RevCommit)) throw new IncorrectObjectTypeException(id.toObjectId(), @@ -1018,9 +1014,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * a pack file or loose object could not be read. */ @NonNull - public RevTree parseTree(AnyObjectId id) - throws MissingObjectException, IncorrectObjectTypeException, - IOException { + public RevTree parseTree(AnyObjectId id) throws MissingObjectException, + IncorrectObjectTypeException, IOException { RevObject c = peel(parseAny(id)); final RevTree t; @@ -1274,8 +1269,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.io.IOException * a pack file or loose object could not be read. */ - public RevObject peel(RevObject obj) throws MissingObjectException, - IOException { + public RevObject peel(RevObject obj) + throws MissingObjectException, IOException { while (obj instanceof RevTag) { parseHeaders(obj); obj = ((RevTag) obj).getObject(); @@ -1304,9 +1299,9 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { int allocFlag() { if (freeFlags == 0) - throw new IllegalArgumentException(MessageFormat.format( - JGitText.get().flagsAlreadyCreated, - Integer.valueOf(32 - RESERVED_FLAGS))); + throw new IllegalArgumentException( + MessageFormat.format(JGitText.get().flagsAlreadyCreated, + Integer.valueOf(32 - RESERVED_FLAGS))); final int m = Integer.lowestOneBit(freeFlags); freeFlags &= ~m; return m; @@ -1323,9 +1318,11 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { */ public void carry(RevFlag flag) { if ((freeFlags & flag.mask) != 0) - throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name)); + throw new IllegalArgumentException(MessageFormat + .format(JGitText.get().flagIsDisposed, flag.name)); if (flag.walker != this) - throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name)); + throw new IllegalArgumentException(MessageFormat + .format(JGitText.get().flagNotFromThis, flag.name)); carryFlags |= flag.mask; } @@ -1359,9 +1356,11 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { */ public final void retainOnReset(RevFlag flag) { if ((freeFlags & flag.mask) != 0) - throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name)); + throw new IllegalArgumentException(MessageFormat + .format(JGitText.get().flagIsDisposed, flag.name)); if (flag.walker != this) - throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name)); + throw new IllegalArgumentException(MessageFormat + .format(JGitText.get().flagNotFromThis, flag.name)); retainOnReset |= flag.mask; } @@ -1496,9 +1495,9 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { final RevCommit c = q.next(); if (c == null) break; - if (c.parents == null) + if (c.getParents() == null) continue; - for (RevCommit p : c.parents) { + for (RevCommit p : c.getParents()) { if ((p.flags & clearFlags) == 0) continue; p.flags &= retainFlags; @@ -1538,7 +1537,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * Like {@link #next()}, but if a checked exception is thrown during the * walk it is rethrown as a {@link RevWalkException}. * - * @throws RevWalkException if an {@link IOException} was thrown. + * @throws RevWalkException + * if an {@link IOException} was thrown. * @return next most recent commit; null if traversal is over. */ @Nullable @@ -1598,7 +1598,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { protected void assertNotStarted() { if (isNotStarted()) return; - throw new IllegalStateException(JGitText.get().outputHasAlreadyBeenStarted); + throw new IllegalStateException( + JGitText.get().outputHasAlreadyBeenStarted); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java index 1adef07ad9..2c88bb872e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java @@ -72,7 +72,7 @@ class RewriteGenerator extends Generator { applyFilterToParents(c); boolean rewrote = false; - final RevCommit[] pList = c.parents; + final RevCommit[] pList = c.getParents(); final int nParents = pList.length; for (int i = 0; i < nParents; i++) { final RevCommit oldp = pList[i]; @@ -108,7 +108,7 @@ class RewriteGenerator extends Generator { private void applyFilterToParents(RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { - for (RevCommit parent : c.parents) { + for (RevCommit parent : c.getParents()) { while ((parent.flags & RevWalk.TREE_REV_FILTER_APPLIED) == 0) { RevCommit n = source.next(); @@ -130,7 +130,7 @@ class RewriteGenerator extends Generator { IncorrectObjectTypeException, IOException { for (;;) { - if (p.parents.length > 1) { + if (p.getParentCount() > 1) { // This parent is a merge, so keep it. // return p; @@ -150,15 +150,15 @@ class RewriteGenerator extends Generator { return p; } - if (p.parents.length == 0) { + if (p.getParentCount() == 0) { // We can't go back any further, other than to // just delete the parent entirely. // return null; } - applyFilterToParents(p.parents[0]); - p = p.parents[0]; + applyFilterToParents(p.getParent(0)); + p = p.getParent(0); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoNonIntermixSortGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoNonIntermixSortGenerator.java index 4f6d417ed1..452545a04e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoNonIntermixSortGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoNonIntermixSortGenerator.java @@ -48,7 +48,7 @@ class TopoNonIntermixSortGenerator extends Generator { break; } if ((c.flags & TOPO_QUEUED) == 0) { - for (RevCommit p : c.parents) { + for (RevCommit p : c.getParents()) { p.inDegree++; if (firstParent) { @@ -94,7 +94,7 @@ class TopoNonIntermixSortGenerator extends Generator { continue; } - for (RevCommit p : c.parents) { + for (RevCommit p : c.getParents()) { if (--p.inDegree == 0 && (p.flags & TOPO_QUEUED) != 0) { // The parent has no unproduced interesting children. unpop // the parent so it goes right behind this child. This means diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java index 7a5db43a7a..4739f78fc0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java @@ -47,7 +47,7 @@ class TopoSortGenerator extends Generator { if (c == null) { break; } - for (RevCommit p : c.parents) { + for (RevCommit p : c.getParents()) { p.inDegree++; if (firstParent) { break; @@ -86,7 +86,7 @@ class TopoSortGenerator extends Generator { // All of our children have already produced, // so it is OK for us to produce now as well. // - for (RevCommit p : c.parents) { + for (RevCommit p : c.getParents()) { if (--p.inDegree == 0 && (p.flags & TOPO_DELAY) != 0) { // This parent tried to come before us, but we are // his last child. unpop the parent so it goes right diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java index 92d72268d1..f921449ffa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java @@ -44,6 +44,7 @@ public class TreeRevFilter extends RevFilter { private static final int FILTER_APPLIED = RevWalk.TREE_REV_FILTER_APPLIED; private final int rewriteFlag; + private final TreeWalk pathFilter; /** @@ -62,10 +63,9 @@ public class TreeRevFilter extends RevFilter { this(walker, t, 0); } - /** - * Create a filter for the first phase of a parent-rewriting limited revision - * walk. + * Create a filter for the first phase of a parent-rewriting limited + * revision walk. * <p> * This filter is ANDed to evaluate before all other filters and ties the * configured {@link TreeFilter} into the revision walking process. @@ -79,8 +79,8 @@ public class TreeRevFilter extends RevFilter { * @param walker * walker used for reading trees. * @param t - * filter to compare against any changed paths in each commit. If a - * {@link FollowFilter}, will be replaced with a new filter + * filter to compare against any changed paths in each commit. If + * a {@link FollowFilter}, will be replaced with a new filter * following new paths after a rename. * @param rewriteFlag * flag to color commits to be removed from the simplified DAT. @@ -106,12 +106,12 @@ public class TreeRevFilter extends RevFilter { c.flags |= FILTER_APPLIED; // Reset the tree filter to scan this commit and parents. // - RevCommit[] pList = c.parents; + RevCommit[] pList = c.getParents(); int nParents = pList.length; TreeWalk tw = pathFilter; ObjectId[] trees = new ObjectId[nParents + 1]; for (int i = 0; i < nParents; i++) { - RevCommit p = c.parents[i]; + RevCommit p = c.getParent(i); if ((p.flags & PARSED) == 0) { p.parseHeaders(walker); } |