The Unified and Autonomous Development Platform
Implements LastCommitsOfChildren to fetch last commits of all direct children of a git tree.
robin shinede61b884c165
diff --git a/commons.git/src/main/java/com/pmease/commons/git/LastCommitInfo.java b/commons.git/src/main/java/com/pmease/commons/git/LastCommitInfo.javanew file mode 100644index 0000000000..0fd83811ea--- /dev/null+++ b/commons.git/src/main/java/com/pmease/commons/git/LastCommitInfo.java@@ -0,0 +1,36 @@+package com.pmease.commons.git;++import java.io.Serializable;++import org.eclipse.jgit.lib.ObjectId;+import org.eclipse.jgit.revwalk.RevCommit;++public class LastCommitInfo implements Serializable {++ private static final long serialVersionUID = 1L;++ private final ObjectId id;++ private final String summary;++ private final long timestamp;++ public LastCommitInfo(RevCommit commit) {+ this.id = commit.getId();+ this.summary = commit.getShortMessage();+ this.timestamp = commit.getCommitTime();+ }++ public ObjectId getId() {+ return id;+ }++ public String getSummary() {+ return summary;+ }++ public long getTimestamp() {+ return timestamp;+ }++}\ No newline at end of filediff --git a/commons.git/src/main/java/com/pmease/commons/git/LastCommitsOfChildren.java b/commons.git/src/main/java/com/pmease/commons/git/LastCommitsOfChildren.javanew file mode 100644index 0000000000..58a4e6b00c--- /dev/null+++ b/commons.git/src/main/java/com/pmease/commons/git/LastCommitsOfChildren.java@@ -0,0 +1,68 @@+package com.pmease.commons.git;++import java.util.HashMap;+import java.util.HashSet;+import java.util.Set;++import javax.annotation.Nullable;++import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.Repository;+import org.eclipse.jgit.revwalk.AffectedChildrenAwareTreeRevFilter;+import org.eclipse.jgit.revwalk.RevCommit;+import org.eclipse.jgit.revwalk.RevWalk;+import org.eclipse.jgit.treewalk.TreeWalk;++import com.google.common.base.Throwables;++public final class LastCommitsOfChildren extends HashMap<String, LastCommitInfo> {++ private static final long serialVersionUID = 1L;++ public LastCommitsOfChildren(Repository repo, AnyObjectId until, @Nullable String treePath) {+ try {+ treePath = GitUtils.normalizePath(treePath);+ if (treePath == null)+ treePath = "";++ AffectedChildrenAwareTreeRevFilter revFilter = new AffectedChildrenAwareTreeRevFilter(treePath);++ Set<String> children = new HashSet<>();++ RevWalk revWalk = new RevWalk(repo);+ RevCommit untilCommit = revWalk.parseCommit(until);++ if (treePath.length() != 0) {+ TreeWalk treeWalk = TreeWalk.forPath(repo, treePath, untilCommit.getTree());+ treeWalk.enterSubtree();+ treeWalk.setRecursive(false);+ while (treeWalk.next())+ children.add(treeWalk.getPathString().substring(treePath.length()+1));+ } else {+ TreeWalk treeWalk = new TreeWalk(repo);+ treeWalk.addTree(untilCommit.getTree());+ treeWalk.setRecursive(false);+ while (treeWalk.next())+ children.add(treeWalk.getPathString().substring(treePath.length()));+ }++ revWalk.markStart(untilCommit);+ revWalk.setRewriteParents(false);++ revWalk.setRevFilter(revFilter);++ RevCommit next = revWalk.next();+ while (size() < children.size() && next != null) {+ Set<String> affectedChildren = revFilter.getAffectedChildren();+ for (String each: affectedChildren) {+ if (children.contains(each) && !containsKey(each))+ put(each, new LastCommitInfo(next));+ }+ affectedChildren.clear();+ next = revWalk.next();+ }+ } catch (Exception e) {+ throw Throwables.propagate(e);+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/AbstractRevQueue.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/AbstractRevQueue.javanew file mode 100644index 0000000000..843c2afa2f--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/AbstractRevQueue.java@@ -0,0 +1,156 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++abstract class AbstractRevQueue extends Generator {+ static final AbstractRevQueue EMPTY_QUEUE = new AlwaysEmptyQueue();++ /** Current output flags set for this generator instance. */+ int outputType;++ /**+ * Add a commit to the queue.+ * <p>+ * This method always adds the commit, even if it is already in the queue or+ * previously was in the queue but has already been removed. To control+ * queue admission use {@link #add(RevCommit, RevFlag)}.+ *+ * @param c+ * commit to add.+ */+ public abstract void add(RevCommit c);++ /**+ * Add a commit if it does not have a flag set yet, then set the flag.+ * <p>+ * This method permits the application to test if the commit has the given+ * flag; if it does not already have the flag than the commit is added to+ * the queue and the flag is set. This later will prevent the commit from+ * being added twice.+ *+ * @param c+ * commit to add.+ * @param queueControl+ * flag that controls admission to the queue.+ */+ public final void add(final RevCommit c, final RevFlag queueControl) {+ if (!c.has(queueControl)) {+ c.add(queueControl);+ add(c);+ }+ }++ /**+ * Add a commit's parents if one does not have a flag set yet.+ * <p>+ * This method permits the application to test if the commit has the given+ * flag; if it does not already have the flag than the commit is added to+ * the queue and the flag is set. This later will prevent the commit from+ * being added twice.+ *+ * @param c+ * commit whose parents should be added.+ * @param queueControl+ * flag that controls admission to the queue.+ */+ public final void addParents(final RevCommit c, final RevFlag queueControl) {+ final RevCommit[] pList = c.parents;+ if (pList == null)+ return;+ for (RevCommit p : pList)+ add(p, queueControl);+ }++ /**+ * Remove the first commit from the queue.+ *+ * @return the first commit of this queue.+ */+ public abstract RevCommit next();++ /** Remove all entries from this queue. */+ public abstract void clear();++ abstract boolean everbodyHasFlag(int f);++ abstract boolean anybodyHasFlag(int f);++ @Override+ int outputType() {+ return outputType;+ }++ protected static void describe(final StringBuilder s, final RevCommit c) {+ s.append(c.toString());+ s.append('\n');+ }++ private static class AlwaysEmptyQueue extends AbstractRevQueue {+ @Override+ public void add(RevCommit c) {+ throw new UnsupportedOperationException();+ }++ @Override+ public RevCommit next() {+ return null;+ }++ @Override+ boolean anybodyHasFlag(int f) {+ return false;+ }++ @Override+ boolean everbodyHasFlag(int f) {+ return true;+ }++ @Override+ public void clear() {+ // Nothing to clear, we have no state.+ }++ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/AffectedChildrenAwareTreeRevFilter.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/AffectedChildrenAwareTreeRevFilter.javanew file mode 100644index 0000000000..2efc1c645c--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/AffectedChildrenAwareTreeRevFilter.java@@ -0,0 +1,162 @@+package org.eclipse.jgit.revwalk;++import java.io.IOException;+import java.util.HashSet;+import java.util.Set;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.errors.StopWalkException;+import org.eclipse.jgit.lib.Constants;+import org.eclipse.jgit.lib.ObjectId;+import org.eclipse.jgit.revwalk.filter.RevFilter;+import org.eclipse.jgit.treewalk.TreeWalk;+import org.eclipse.jgit.treewalk.filter.TreeFilter;+import org.eclipse.jgit.util.RawParseUtils;++public class AffectedChildrenAwareTreeRevFilter extends RevFilter {++ private static final int PARSED = RevWalk.PARSED;++ private final byte[] treePathRaw;++ private final Set<String> affectedChildren = new HashSet<>();++ public AffectedChildrenAwareTreeRevFilter(String treePath) {+ treePathRaw = Constants.encode(treePath);+ }++ @Override+ public boolean include(RevWalk revWalker, RevCommit commit)+ throws StopWalkException, MissingObjectException,+ IncorrectObjectTypeException, IOException {+ final RevCommit[] pList = commit.getParents();+ final int nParents = pList.length;+ final TreeWalk treeWalker = new TreeWalk(revWalker.reader);+ treeWalker.setFilter(new TreeFilter() {++ @Override+ public boolean include(TreeWalk walker)+ throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (treePathRaw.length == 0 || walker.isPathPrefix(treePathRaw, treePathRaw.length) == 0) {+ int walkPathLen = walker.getPathLength();+ if (walkPathLen <= treePathRaw.length) {+ boolean modified = false;++ final int n = walker.getTreeCount();+ if (n == 1) {+ modified = true;+ } else {+ final int m = walker.getRawMode(n-1);+ for (int i = 0; i < n-1; i++) {+ if (walker.getRawMode(i) != m || !walker.idEqual(i, n-1)) {+ modified = true;+ break;+ }+ }+ }+ if (modified) {+ walker.setRecursive(true);+ return true;+ } else {+ return false;+ }+ } else {+ boolean modified = false;+ boolean same = false;+ final int n = walker.getTreeCount();+ if (n == 1) {+ modified = true;+ } else {+ final int m = walker.getRawMode(n-1);+ for (int i = 0; i < n-1; i++) {+ if (walker.getRawMode(i) != m || !walker.idEqual(i, n-1))+ modified = true;+ if (walker.getRawMode(i) == m && walker.idEqual(i, n-1))+ same = true;+ }+ }+ if (modified) {+ if (!same) {+ String child = RawParseUtils.decode(+ Constants.CHARSET,+ walker.getRawPath(),+ treePathRaw.length!=0?treePathRaw.length+1:0,+ walkPathLen);+ affectedChildren.add(child);+ }+ walker.setRecursive(false);+ return true;+ } else {+ return false;+ }+ }+ } else {+ return false;+ }+ }++ @Override+ public boolean shouldBeRecursive() {+ return true;+ }++ @Override+ public TreeFilter clone() {+ return this;+ }++ });+ treeWalker.setRecursive(true);+ final ObjectId[] trees = new ObjectId[nParents + 1];+ for (int i = 0; i < nParents; i++) {+ final RevCommit p = commit.parents[i];+ if ((p.flags & PARSED) == 0)+ p.parseHeaders(revWalker);+ trees[i] = p.getTree();+ }+ trees[nParents] = commit.getTree();+ treeWalker.reset(trees);++ if (nParents <= 1) {+ boolean chged = false;+ while (treeWalker.next())+ chged = true;++ return chged;+ }++ final int[] chgs = new int[nParents];+ while (treeWalker.next()) {+ final int myMode = treeWalker.getRawMode(nParents);+ for (int i = 0; i < nParents; i++) {+ final int pMode = treeWalker.getRawMode(i);+ if (myMode == pMode && treeWalker.idEqual(i, nParents))+ continue;++ chgs[i]++;+ }+ }++ for (int i = 0; i < nParents; i++) {+ if (chgs[i] == 0) {+ final RevCommit p = pList[i];+ commit.parents = new RevCommit[] {p};+ return false;+ }+ }++ return true;+ }++ @Override+ public RevFilter clone() {+ throw new UnsupportedOperationException();+ }++ public Set<String> getAffectedChildren() {+ return affectedChildren;+ }++}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/AsyncRevObjectQueue.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/AsyncRevObjectQueue.javanew file mode 100644index 0000000000..1c0438a5ed--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/AsyncRevObjectQueue.java@@ -0,0 +1,70 @@+/*+ * Copyright (C) 2010, Google Inc.+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.lib.AsyncOperation;++/**+ * Queue to lookup and parse objects asynchronously.+ *+ * A queue may perform background lookup of objects and supply them (possibly+ * out-of-order) to the application.+ */+public interface AsyncRevObjectQueue extends AsyncOperation {+ /**+ * Obtain the next object.+ *+ * @return the object; null if there are no more objects remaining.+ * @throws MissingObjectException+ * the object does not exist. There may be more objects+ * remaining in the iteration, the application should call+ * {@link #next()} again.+ * @throws IOException+ * the object store cannot be accessed.+ */+ public RevObject next() throws MissingObjectException, IOException;+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/BlockObjQueue.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/BlockObjQueue.javanew file mode 100644index 0000000000..371cd06dda--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/BlockObjQueue.java@@ -0,0 +1,144 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++class BlockObjQueue {+ private BlockFreeList free;++ private Block head;++ private Block tail;++ /** Create an empty queue. */+ BlockObjQueue() {+ free = new BlockFreeList();+ }++ void add(final RevObject c) {+ Block b = tail;+ if (b == null) {+ b = free.newBlock();+ b.add(c);+ head = b;+ tail = b;+ return;+ } else if (b.isFull()) {+ b = free.newBlock();+ tail.next = b;+ tail = b;+ }+ b.add(c);+ }++ RevObject next() {+ final Block b = head;+ if (b == null)+ return null;++ final RevObject c = b.pop();+ if (b.isEmpty()) {+ head = b.next;+ if (head == null)+ tail = null;+ free.freeBlock(b);+ }+ return c;+ }++ static final class BlockFreeList {+ private Block next;++ Block newBlock() {+ Block b = next;+ if (b == null)+ return new Block();+ next = b.next;+ b.clear();+ return b;+ }++ void freeBlock(final Block b) {+ b.next = next;+ next = b;+ }+ }++ static final class Block {+ private static final int BLOCK_SIZE = 256;++ /** Next block in our chain of blocks; null if we are the last. */+ Block next;++ /** Our table of queued objects. */+ final RevObject[] objects = new RevObject[BLOCK_SIZE];++ /** Next valid entry in {@link #objects}. */+ int headIndex;++ /** Next free entry in {@link #objects} for addition at. */+ int tailIndex;++ boolean isFull() {+ return tailIndex == BLOCK_SIZE;+ }++ boolean isEmpty() {+ return headIndex == tailIndex;+ }++ void add(final RevObject c) {+ objects[tailIndex++] = c;+ }++ RevObject pop() {+ return objects[headIndex++];+ }++ void clear() {+ next = null;+ headIndex = 0;+ tailIndex = 0;+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/BlockRevQueue.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/BlockRevQueue.javanew file mode 100644index 0000000000..30d140a748--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/BlockRevQueue.java@@ -0,0 +1,169 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++abstract class BlockRevQueue extends AbstractRevQueue {+ protected BlockFreeList free;++ /** Create an empty revision queue. */+ protected BlockRevQueue() {+ free = new BlockFreeList();+ }++ BlockRevQueue(final Generator s) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ free = new BlockFreeList();+ outputType = s.outputType();+ s.shareFreeList(this);+ for (;;) {+ final RevCommit c = s.next();+ if (c == null)+ break;+ add(c);+ }+ }++ /**+ * Reconfigure this queue to share the same free list as another.+ * <p>+ * Multiple revision queues can be connected to the same free list, making+ * it less expensive for applications to shuttle commits between them. This+ * method arranges for the receiver to take from / return to the same free+ * list as the supplied queue.+ * <p>+ * Free lists are not thread-safe. Applications must ensure that all queues+ * sharing the same free list are doing so from only a single thread.+ *+ * @param q+ * the other queue we will steal entries from.+ */+ public void shareFreeList(final BlockRevQueue q) {+ free = q.free;+ }++ static final class BlockFreeList {+ private Block next;++ Block newBlock() {+ Block b = next;+ if (b == null)+ return new Block();+ next = b.next;+ b.clear();+ return b;+ }++ void freeBlock(final Block b) {+ b.next = next;+ next = b;+ }++ void clear() {+ next = null;+ }+ }++ static final class Block {+ static final int BLOCK_SIZE = 256;++ /** Next block in our chain of blocks; null if we are the last. */+ Block next;++ /** Our table of queued commits. */+ final RevCommit[] commits = new RevCommit[BLOCK_SIZE];++ /** Next valid entry in {@link #commits}. */+ int headIndex;++ /** Next free entry in {@link #commits} for addition at. */+ int tailIndex;++ boolean isFull() {+ return tailIndex == BLOCK_SIZE;+ }++ boolean isEmpty() {+ return headIndex == tailIndex;+ }++ boolean canUnpop() {+ return headIndex > 0;+ }++ void add(final RevCommit c) {+ commits[tailIndex++] = c;+ }++ void unpop(final RevCommit c) {+ commits[--headIndex] = c;+ }++ RevCommit pop() {+ return commits[headIndex++];+ }++ RevCommit peek() {+ return commits[headIndex];+ }++ void clear() {+ next = null;+ headIndex = 0;+ tailIndex = 0;+ }++ void resetToMiddle() {+ headIndex = tailIndex = BLOCK_SIZE / 2;+ }++ void resetToEnd() {+ headIndex = tailIndex = BLOCK_SIZE;+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/BoundaryGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/BoundaryGenerator.javanew file mode 100644index 0000000000..6be0c8584e--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/BoundaryGenerator.java@@ -0,0 +1,134 @@+/*+ * Copyright (C) 2009, Google Inc.+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++class BoundaryGenerator extends Generator {+ static final int UNINTERESTING = RevWalk.UNINTERESTING;++ Generator g;++ BoundaryGenerator(final RevWalk w, final Generator s) {+ g = new InitialGenerator(w, s);+ }++ @Override+ int outputType() {+ return g.outputType() | HAS_UNINTERESTING;+ }++ @Override+ void shareFreeList(final BlockRevQueue q) {+ g.shareFreeList(q);+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ return g.next();+ }++ private class InitialGenerator extends Generator {+ private static final int PARSED = RevWalk.PARSED;++ private static final int DUPLICATE = RevWalk.TEMP_MARK;++ private final RevWalk walk;++ private final FIFORevQueue held;++ private final Generator source;++ InitialGenerator(final RevWalk w, final Generator s) {+ walk = w;+ held = new FIFORevQueue();+ source = s;+ source.shareFreeList(held);+ }++ @Override+ int outputType() {+ return source.outputType();+ }++ @Override+ void shareFreeList(final BlockRevQueue q) {+ q.shareFreeList(held);+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ RevCommit c = source.next();+ if (c != null) {+ for (final RevCommit p : c.parents)+ if ((p.flags & UNINTERESTING) != 0)+ held.add(p);+ return c;+ }++ final FIFORevQueue boundary = new FIFORevQueue();+ boundary.shareFreeList(held);+ for (;;) {+ c = held.next();+ if (c == null)+ break;+ if ((c.flags & DUPLICATE) != 0)+ continue;+ if ((c.flags & PARSED) == 0)+ c.parseHeaders(walk);+ c.flags |= DUPLICATE;+ boundary.add(c);+ }+ boundary.removeFlag(DUPLICATE);+ g = boundary;+ return boundary.next();+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/DateRevQueue.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/DateRevQueue.javanew file mode 100644index 0000000000..0802bfafde--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/DateRevQueue.java@@ -0,0 +1,221 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>,+ * Copyright (C) 2013, Gustaf Lundh <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/** A queue of commits sorted by commit time order. */+public class DateRevQueue extends AbstractRevQueue {+ private static final int REBUILD_INDEX_COUNT = 1000;++ private Entry head;++ private Entry free;++ private int inQueue;++ private int sinceLastIndex;++ private Entry[] index;++ private int first;++ private int last = -1;++ /** Create an empty date queue. */+ public DateRevQueue() {+ super();+ }++ DateRevQueue(final Generator s) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ for (;;) {+ final RevCommit c = s.next();+ if (c == null)+ break;+ add(c);+ }+ }++ public void add(final RevCommit c) {+ sinceLastIndex++;+ if (++inQueue > REBUILD_INDEX_COUNT+ && sinceLastIndex > REBUILD_INDEX_COUNT)+ buildIndex();++ Entry q = head;+ final long when = c.commitTime;++ if (first <= last && index[first].commit.commitTime > when) {+ int low = first, high = last;+ while (low <= high) {+ int mid = (low + high) >>> 1;+ int t = index[mid].commit.commitTime;+ if (t < when)+ high = mid - 1;+ else if (t > when)+ low = mid + 1;+ else {+ low = mid - 1;+ break;+ }+ }+ low = Math.min(low, high);+ while (low > first && when == index[low].commit.commitTime)+ --low;+ q = index[low];+ }++ final Entry n = newEntry(c);+ if (q == null || (q == head && when > q.commit.commitTime)) {+ n.next = q;+ head = n;+ } else {+ Entry p = q.next;+ while (p != null && p.commit.commitTime > when) {+ q = p;+ p = q.next;+ }+ n.next = q.next;+ q.next = n;+ }+ }++ public RevCommit next() {+ final Entry q = head;+ if (q == null)+ return null;++ if (index != null && q == index[first])+ index[first++] = null;+ inQueue--;++ head = q.next;+ freeEntry(q);+ return q.commit;+ }++ private void buildIndex() {+ sinceLastIndex = 0;+ first = 0;+ index = new Entry[inQueue / 100 + 1];+ int qi = 0, ii = 0;+ for (Entry q = head; q != null; q = q.next) {+ if (++qi % 100 == 0)+ index[ii++] = q;+ }+ last = ii - 1;+ }++ /**+ * Peek at the next commit, without removing it.+ *+ * @return the next available commit; null if there are no commits left.+ */+ public RevCommit peek() {+ return head != null ? head.commit : null;+ }++ public void clear() {+ head = null;+ free = null;+ index = null;+ inQueue = 0;+ sinceLastIndex = 0;+ last = -1;+ }++ boolean everbodyHasFlag(final int f) {+ for (Entry q = head; q != null; q = q.next) {+ if ((q.commit.flags & f) == 0)+ return false;+ }+ return true;+ }++ boolean anybodyHasFlag(final int f) {+ for (Entry q = head; q != null; q = q.next) {+ if ((q.commit.flags & f) != 0)+ return true;+ }+ return false;+ }++ @Override+ int outputType() {+ return outputType | SORT_COMMIT_TIME_DESC;+ }++ public String toString() {+ final StringBuilder s = new StringBuilder();+ for (Entry q = head; q != null; q = q.next)+ describe(s, q.commit);+ return s.toString();+ }++ private Entry newEntry(final RevCommit c) {+ Entry r = free;+ if (r == null)+ r = new Entry();+ else+ free = r.next;+ r.commit = c;+ return r;+ }++ private void freeEntry(final Entry e) {+ e.next = free;+ free = e;+ }++ static class Entry {+ Entry next;++ RevCommit commit;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/DelayRevQueue.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/DelayRevQueue.javanew file mode 100644index 0000000000..4a0d19d60d--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/DelayRevQueue.java@@ -0,0 +1,99 @@+/*+ * Copyright (C) 2009, Google Inc.+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/**+ * Delays commits to be at least {@link PendingGenerator#OVER_SCAN} late.+ * <p>+ * This helps to "fix up" weird corner cases resulting from clock skew, by+ * slowing down what we produce to the caller we get a better chance to ensure+ * PendingGenerator reached back far enough in the graph to correctly mark+ * commits {@link RevWalk#UNINTERESTING} if necessary.+ * <p>+ * This generator should appear before {@link FixUninterestingGenerator} if the+ * lower level {@link #pending} isn't already fully buffered.+ */+final class DelayRevQueue extends Generator {+ private static final int OVER_SCAN = PendingGenerator.OVER_SCAN;++ private final Generator pending;++ private final FIFORevQueue delay;++ private int size;++ DelayRevQueue(final Generator g) {+ pending = g;+ delay = new FIFORevQueue();+ }++ @Override+ int outputType() {+ return pending.outputType();+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ while (size < OVER_SCAN) {+ final RevCommit c = pending.next();+ if (c == null)+ break;+ delay.add(c);+ size++;+ }++ final RevCommit c = delay.next();+ if (c == null)+ return null;+ size--;+ return c;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/DepthGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/DepthGenerator.javanew file mode 100644index 0000000000..ad05186354--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/DepthGenerator.java@@ -0,0 +1,176 @@+/*+ * Copyright (C) 2010, Garmin International+ * Copyright (C) 2010, Matt Fischer <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/**+ * Only produce commits which are below a specified depth.+ *+ * @see DepthWalk+ */+class DepthGenerator extends Generator {+ private final FIFORevQueue pending;++ private final int depth;++ private final RevWalk walk;++ /**+ * Commits which used to be shallow in the client, but which are+ * being extended as part of this fetch. These commits should be+ * returned to the caller as UNINTERESTING so that their blobs/trees+ * can be marked appropriately in the pack writer.+ */+ private final RevFlag UNSHALLOW;++ /**+ * Commits which the normal framework has marked as UNINTERESTING,+ * but which we now care about again. This happens if a client is+ * extending a shallow checkout to become deeper--the new commits at+ * the bottom of the graph need to be sent, even though they are+ * below other commits which the client already has.+ */+ private final RevFlag REINTERESTING;++ /**+ * @param w+ * @param s Parent generator+ * @throws MissingObjectException+ * @throws IncorrectObjectTypeException+ * @throws IOException+ */+ DepthGenerator(DepthWalk w, Generator s) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ pending = new FIFORevQueue();+ walk = (RevWalk)w;++ this.depth = w.getDepth();+ this.UNSHALLOW = w.getUnshallowFlag();+ this.REINTERESTING = w.getReinterestingFlag();++ s.shareFreeList(pending);++ // Begin by sucking out all of the source's commits, and+ // adding them to the pending queue+ for (;;) {+ RevCommit c = s.next();+ if (c == null)+ break;+ if (((DepthWalk.Commit) c).getDepth() == 0)+ pending.add(c);+ }+ }++ @Override+ int outputType() {+ return pending.outputType() | HAS_UNINTERESTING;+ }++ @Override+ void shareFreeList(final BlockRevQueue q) {+ pending.shareFreeList(q);+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ // Perform a breadth-first descent into the commit graph,+ // marking depths as we go. This means that if a commit is+ // reachable by more than one route, we are guaranteed to+ // arrive by the shortest route first.+ for (;;) {+ final DepthWalk.Commit c = (DepthWalk.Commit) pending.next();+ if (c == null)+ return null;++ if ((c.flags & RevWalk.PARSED) == 0)+ c.parseHeaders(walk);++ int newDepth = c.depth + 1;++ for (final RevCommit p : c.parents) {+ DepthWalk.Commit dp = (DepthWalk.Commit) p;++ // If no depth has been assigned to this commit, assign+ // it now. Since we arrive by the shortest route first,+ // this depth is guaranteed to be the smallest value that+ // any path could produce.+ if (dp.depth == -1) {+ dp.depth = newDepth;++ // If the parent is not too deep, add it to the queue+ // so that we can produce it later+ if (newDepth <= depth)+ pending.add(p);+ }++ // If the current commit has become unshallowed, everything+ // below us is new to the client. Mark its parent as+ // re-interesting, and carry that flag downward to all+ // of its ancestors.+ if(c.has(UNSHALLOW) || c.has(REINTERESTING)) {+ p.add(REINTERESTING);+ p.flags &= ~RevWalk.UNINTERESTING;+ }+ }++ // Produce all commits less than the depth cutoff+ boolean produce = c.depth <= depth;++ // Unshallow commits are uninteresting, but still need to be sent+ // up to the PackWriter so that it will exclude objects correctly.+ // All other uninteresting commits should be omitted.+ if ((c.flags & RevWalk.UNINTERESTING) != 0 && !c.has(UNSHALLOW))+ produce = false;++ if (produce)+ return c;+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/DepthWalk.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/DepthWalk.javanew file mode 100644index 0000000000..89d05dba59--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/DepthWalk.java@@ -0,0 +1,243 @@+/*+ * Copyright (C) 2010, Garmin International+ * Copyright (C) 2010, Matt Fischer <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.ObjectReader;+import org.eclipse.jgit.lib.Repository;++/** Interface for revision walkers that perform depth filtering. */+public interface DepthWalk {+ /** @return Depth to filter to. */+ public int getDepth();++ /** @return flag marking commits that should become unshallow. */+ public RevFlag getUnshallowFlag();++ /** @return flag marking commits that are interesting again. */+ public RevFlag getReinterestingFlag();++ /** RevCommit with a depth (in commits) from a root. */+ public static class Commit extends RevCommit {+ /** Depth of this commit in the graph, via shortest path. */+ int depth;++ /** @return depth of this commit, as found by the shortest path. */+ public int getDepth() {+ return depth;+ }++ /**+ * Initialize a new commit.+ *+ * @param id+ * object name for the commit.+ */+ protected Commit(AnyObjectId id) {+ super(id);+ depth = -1;+ }+ }++ /** Subclass of RevWalk that performs depth filtering. */+ public class RevWalk extends org.eclipse.jgit.revwalk.RevWalk implements DepthWalk {+ private final int depth;++ private final RevFlag UNSHALLOW;++ private final RevFlag REINTERESTING;++ /**+ * @param repo Repository to walk+ * @param depth Maximum depth to return+ */+ public RevWalk(Repository repo, int depth) {+ super(repo);++ this.depth = depth;+ this.UNSHALLOW = newFlag("UNSHALLOW"); //$NON-NLS-1$+ this.REINTERESTING = newFlag("REINTERESTING"); //$NON-NLS-1$+ }++ /**+ * @param or ObjectReader to use+ * @param depth Maximum depth to return+ */+ public RevWalk(ObjectReader or, int depth) {+ super(or);++ this.depth = depth;+ this.UNSHALLOW = newFlag("UNSHALLOW"); //$NON-NLS-1$+ this.REINTERESTING = newFlag("REINTERESTING"); //$NON-NLS-1$+ }++ /**+ * Mark a root commit (i.e., one whose depth should be considered 0.)+ *+ * @param c+ * Commit to mark+ * @throws IOException+ * @throws IncorrectObjectTypeException+ * @throws MissingObjectException+ */+ public void markRoot(RevCommit c) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (c instanceof Commit)+ ((Commit) c).depth = 0;+ super.markStart(c);+ }++ @Override+ protected RevCommit createCommit(AnyObjectId id) {+ return new Commit(id);+ }++ public int getDepth() {+ return depth;+ }++ public RevFlag getUnshallowFlag() {+ return UNSHALLOW;+ }++ public RevFlag getReinterestingFlag() {+ return REINTERESTING;+ }+ }++ /** Subclass of ObjectWalk that performs depth filtering. */+ public class ObjectWalk extends org.eclipse.jgit.revwalk.ObjectWalk implements DepthWalk {+ private final int depth;++ private final RevFlag UNSHALLOW;++ private final RevFlag REINTERESTING;++ /**+ * @param repo Repository to walk+ * @param depth Maximum depth to return+ */+ public ObjectWalk(Repository repo, int depth) {+ super(repo);++ this.depth = depth;+ this.UNSHALLOW = newFlag("UNSHALLOW"); //$NON-NLS-1$+ this.REINTERESTING = newFlag("REINTERESTING"); //$NON-NLS-1$+ }++ /**+ * @param or Object Reader+ * @param depth Maximum depth to return+ */+ public ObjectWalk(ObjectReader or, int depth) {+ super(or);++ this.depth = depth;+ this.UNSHALLOW = newFlag("UNSHALLOW"); //$NON-NLS-1$+ this.REINTERESTING = newFlag("REINTERESTING"); //$NON-NLS-1$+ }++ /**+ * Mark a root commit (i.e., one whose depth should be considered 0.)+ *+ * @param o+ * Commit to mark+ * @throws IOException+ * @throws IncorrectObjectTypeException+ * @throws MissingObjectException+ */+ public void markRoot(RevObject o) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ RevObject c = o;+ while (c instanceof RevTag) {+ c = ((RevTag) c).getObject();+ parseHeaders(c);+ }+ if (c instanceof Commit)+ ((Commit) c).depth = 0;+ super.markStart(o);+ }++ /**+ * Mark an element which used to be shallow in the client, but which+ * should now be considered a full commit. Any ancestors of this commit+ * should be included in the walk, even if they are the ancestor of an+ * uninteresting commit.+ *+ * @param c+ * Commit to mark+ * @throws MissingObjectException+ * @throws IncorrectObjectTypeException+ * @throws IOException+ */+ public void markUnshallow(RevObject c) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (c instanceof RevCommit)+ c.add(UNSHALLOW);+ super.markStart(c);+ }++ @Override+ protected RevCommit createCommit(AnyObjectId id) {+ return new Commit(id);+ }++ public int getDepth() {+ return depth;+ }++ public RevFlag getUnshallowFlag() {+ return UNSHALLOW;+ }++ public RevFlag getReinterestingFlag() {+ return REINTERESTING;+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/EndGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/EndGenerator.javanew file mode 100644index 0000000000..627e1c7a51--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/EndGenerator.java@@ -0,0 +1,62 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++class EndGenerator extends Generator {+ static final EndGenerator INSTANCE = new EndGenerator();++ private EndGenerator() {+ // We have nothing to initialize.+ }++ @Override+ RevCommit next() {+ return null;+ }++ @Override+ int outputType() {+ return 0;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/FIFORevQueue.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FIFORevQueue.javanew file mode 100644index 0000000000..b8f63aaa58--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FIFORevQueue.java@@ -0,0 +1,165 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/** A queue of commits in FIFO order. */+public class FIFORevQueue extends BlockRevQueue {+ private Block head;++ private Block tail;++ /** Create an empty FIFO queue. */+ public FIFORevQueue() {+ super();+ }++ FIFORevQueue(final Generator s) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ super(s);+ }++ public void add(final RevCommit c) {+ Block b = tail;+ if (b == null) {+ b = free.newBlock();+ b.add(c);+ head = b;+ tail = b;+ return;+ } else if (b.isFull()) {+ b = free.newBlock();+ tail.next = b;+ tail = b;+ }+ b.add(c);+ }++ /**+ * Insert the commit pointer at the front of the queue.+ *+ * @param c+ * the commit to insert into the queue.+ */+ public void unpop(final RevCommit c) {+ Block b = head;+ if (b == null) {+ b = free.newBlock();+ b.resetToMiddle();+ b.add(c);+ head = b;+ tail = b;+ return;+ } else if (b.canUnpop()) {+ b.unpop(c);+ return;+ }++ b = free.newBlock();+ b.resetToEnd();+ b.unpop(c);+ b.next = head;+ head = b;+ }++ public RevCommit next() {+ final Block b = head;+ if (b == null)+ return null;++ final RevCommit c = b.pop();+ if (b.isEmpty()) {+ head = b.next;+ if (head == null)+ tail = null;+ free.freeBlock(b);+ }+ return c;+ }++ public void clear() {+ head = null;+ tail = null;+ free.clear();+ }++ boolean everbodyHasFlag(final int f) {+ for (Block b = head; b != null; b = b.next) {+ for (int i = b.headIndex; i < b.tailIndex; i++)+ if ((b.commits[i].flags & f) == 0)+ return false;+ }+ return true;+ }++ boolean anybodyHasFlag(final int f) {+ for (Block b = head; b != null; b = b.next) {+ for (int i = b.headIndex; i < b.tailIndex; i++)+ if ((b.commits[i].flags & f) != 0)+ return true;+ }+ return false;+ }++ void removeFlag(final int f) {+ final int not_f = ~f;+ for (Block b = head; b != null; b = b.next) {+ for (int i = b.headIndex; i < b.tailIndex; i++)+ b.commits[i].flags &= not_f;+ }+ }++ public String toString() {+ final StringBuilder s = new StringBuilder();+ for (Block q = head; q != null; q = q.next) {+ for (int i = q.headIndex; i < q.tailIndex; i++)+ describe(s, q.commits[i]);+ }+ return s.toString();+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/FixUninterestingGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FixUninterestingGenerator.javanew file mode 100644index 0000000000..9d734a7296--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FixUninterestingGenerator.java@@ -0,0 +1,84 @@+/*+ * Copyright (C) 2009, Google Inc.+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/**+ * Filters out commits marked {@link RevWalk#UNINTERESTING}.+ * <p>+ * This generator is only in front of another generator that has fully buffered+ * commits, such that we are called only after the {@link PendingGenerator} has+ * exhausted its input queue and given up. It skips over any uninteresting+ * commits that may have leaked out of the PendingGenerator due to clock skew+ * being detected in the commit objects.+ */+final class FixUninterestingGenerator extends Generator {+ private final Generator pending;++ FixUninterestingGenerator(final Generator g) {+ pending = g;+ }++ @Override+ int outputType() {+ return pending.outputType();+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ for (;;) {+ final RevCommit c = pending.next();+ if (c == null)+ return null;+ if ((c.flags & RevWalk.UNINTERESTING) == 0)+ return c;+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/FollowFilter.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FollowFilter.javanew file mode 100644index 0000000000..9928286dcd--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FollowFilter.java@@ -0,0 +1,149 @@+/*+ * Copyright (C) 2010, Google Inc.+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.diff.DiffConfig;+import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.treewalk.TreeWalk;+import org.eclipse.jgit.treewalk.filter.PathFilter;+import org.eclipse.jgit.treewalk.filter.TreeFilter;++/**+ * Updates the internal path filter to follow copy/renames.+ * <p>+ * This is a special filter that performs {@code AND(path, ANY_DIFF)}, but also+ * triggers rename detection so that the path node is updated to include a prior+ * file name as the RevWalk traverses history.+ *+ * The renames found will be reported to a {@link RenameCallback} if one is set.+ * <p>+ * Results with this filter are unpredictable if the path being followed is a+ * subdirectory.+ */+public class FollowFilter extends TreeFilter {+ /**+ * Create a new tree filter for a user supplied path.+ * <p>+ * Path strings are relative to the root of the repository. If the user's+ * input should be assumed relative to a subdirectory of the repository the+ * caller must prepend the subdirectory's path prior to creating the filter.+ * <p>+ * Path strings use '/' to delimit directories on all platforms.+ *+ * @param path+ * the path to filter on. Must not be the empty string. All+ * trailing '/' characters will be trimmed before string's length+ * is checked or is used as part of the constructed filter.+ * @param cfg+ * diff config specifying rename detection options.+ * @return a new filter for the requested path.+ * @throws IllegalArgumentException+ * the path supplied was the empty string.+ * @since 3.0+ */+ public static FollowFilter create(String path, DiffConfig cfg) {+ return new FollowFilter(PathFilter.create(path), cfg);+ }++ private final PathFilter path;+ final DiffConfig cfg;++ private RenameCallback renameCallback;++ FollowFilter(final PathFilter path, final DiffConfig cfg) {+ this.path = path;+ this.cfg = cfg;+ }++ /** @return the path this filter matches. */+ public String getPath() {+ return path.getPath();+ }++ @Override+ public boolean include(final TreeWalk walker)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ return path.include(walker) && ANY_DIFF.include(walker);+ }++ @Override+ public boolean shouldBeRecursive() {+ return path.shouldBeRecursive() || ANY_DIFF.shouldBeRecursive();+ }++ @Override+ public TreeFilter clone() {+ return new FollowFilter(path.clone(), cfg);+ }++ @SuppressWarnings("nls")+ @Override+ public String toString() {+ return "(FOLLOW(" + path.toString() + ")" //+ + " AND " //+ + ANY_DIFF.toString() + ")";+ }++ /**+ * @return the callback to which renames are reported, or <code>null</code>+ * if none+ */+ public RenameCallback getRenameCallback() {+ return renameCallback;+ }++ /**+ * Sets the callback to which renames shall be reported.+ *+ * @param callback+ * the callback to use+ */+ public void setRenameCallback(RenameCallback callback) {+ renameCallback = callback;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/FooterKey.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FooterKey.javanew file mode 100644index 0000000000..319b819a79--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FooterKey.java@@ -0,0 +1,84 @@+/*+ * Copyright (C) 2009, Google Inc.+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import org.eclipse.jgit.lib.Constants;++/** Case insensitive key for a {@link FooterLine}. */+public final class FooterKey {+ /** Standard {@code Signed-off-by} */+ public static final FooterKey SIGNED_OFF_BY = new FooterKey("Signed-off-by"); //$NON-NLS-1$++ /** Standard {@code Acked-by} */+ public static final FooterKey ACKED_BY = new FooterKey("Acked-by"); //$NON-NLS-1$++ /** Standard {@code CC} */+ public static final FooterKey CC = new FooterKey("CC"); //$NON-NLS-1$++ private final String name;++ final byte[] raw;++ /**+ * Create a key for a specific footer line.+ *+ * @param keyName+ * name of the footer line.+ */+ public FooterKey(final String keyName) {+ name = keyName;+ raw = Constants.encode(keyName.toLowerCase());+ }++ /** @return name of this footer line. */+ public String getName() {+ return name;+ }++ @SuppressWarnings("nls")+ @Override+ public String toString() {+ return "FooterKey[" + name + "]";+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/FooterLine.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FooterLine.javanew file mode 100644index 0000000000..b061d6ae13--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/FooterLine.java@@ -0,0 +1,151 @@+/*+ * Copyright (C) 2009, Google Inc.+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.nio.charset.Charset;++import org.eclipse.jgit.util.RawParseUtils;++/**+ * Single line at the end of a message, such as a "Signed-off-by: someone".+ * <p>+ * These footer lines tend to be used to represent additional information about+ * a commit, like the path it followed through reviewers before finally being+ * accepted into the project's main repository as an immutable commit.+ *+ * @see RevCommit#getFooterLines()+ */+public final class FooterLine {+ private final byte[] buffer;++ private final Charset enc;++ private final int keyStart;++ private final int keyEnd;++ private final int valStart;++ private final int valEnd;++ FooterLine(final byte[] b, final Charset e, final int ks, final int ke,+ final int vs, final int ve) {+ buffer = b;+ enc = e;+ keyStart = ks;+ keyEnd = ke;+ valStart = vs;+ valEnd = ve;+ }++ /**+ * @param key+ * key to test this line's key name against.+ * @return true if {@code key.getName().equalsIgnorecase(getKey())}.+ */+ public boolean matches(final FooterKey key) {+ final byte[] kRaw = key.raw;+ final int len = kRaw.length;+ int bPtr = keyStart;+ if (keyEnd - bPtr != len)+ return false;+ for (int kPtr = 0; kPtr < len;) {+ byte b = buffer[bPtr++];+ if ('A' <= b && b <= 'Z')+ b += 'a' - 'A';+ if (b != kRaw[kPtr++])+ return false;+ }+ return true;+ }++ /**+ * @return key name of this footer; that is the text before the ":" on the+ * line footer's line. The text is decoded according to the commit's+ * specified (or assumed) character encoding.+ */+ public String getKey() {+ return RawParseUtils.decode(enc, buffer, keyStart, keyEnd);+ }++ /**+ * @return value of this footer; that is the text after the ":" and any+ * leading whitespace has been skipped. May be the empty string if+ * the footer has no value (line ended with ":"). The text is+ * decoded according to the commit's specified (or assumed)+ * character encoding.+ */+ public String getValue() {+ return RawParseUtils.decode(enc, buffer, valStart, valEnd);+ }++ /**+ * Extract the email address (if present) from the footer.+ * <p>+ * If there is an email address looking string inside of angle brackets+ * (e.g. "<a@b>"), the return value is the part extracted from inside the+ * brackets. If no brackets are found, then {@link #getValue()} is returned+ * if the value contains an '@' sign. Otherwise, null.+ *+ * @return email address appearing in the value of this footer, or null.+ */+ public String getEmailAddress() {+ final int lt = RawParseUtils.nextLF(buffer, valStart, '<');+ if (valEnd <= lt) {+ final int at = RawParseUtils.nextLF(buffer, valStart, '@');+ if (valStart < at && at < valEnd)+ return getValue();+ return null;+ }+ final int gt = RawParseUtils.nextLF(buffer, lt, '>');+ if (valEnd < gt)+ return null;+ return RawParseUtils.decode(enc, buffer, lt, gt - 1);+ }++ @Override+ public String toString() {+ return getKey() + ": " + getValue(); //$NON-NLS-1$+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/Generator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/Generator.javanew file mode 100644index 0000000000..a95303b641--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/Generator.java@@ -0,0 +1,106 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/**+ * Produces commits for RevWalk to return to applications.+ * <p>+ * Implementations of this basic class provide the real work behind RevWalk.+ * Conceptually a Generator is an iterator or a queue, it returns commits until+ * there are no more relevant. Generators may be piped/stacked together to+ * create a more complex set of operations.+ *+ * @see PendingGenerator+ * @see StartGenerator+ */+abstract class Generator {+ /** Commits are sorted by commit date and time, descending. */+ static final int SORT_COMMIT_TIME_DESC = 1 << 0;++ /** Output may have {@link RevWalk#REWRITE} marked on it. */+ static final int HAS_REWRITE = 1 << 1;++ /** Output needs {@link RewriteGenerator}. */+ static final int NEEDS_REWRITE = 1 << 2;++ /** Topological ordering is enforced (all children before parents). */+ static final int SORT_TOPO = 1 << 3;++ /** Output may have {@link RevWalk#UNINTERESTING} marked on it. */+ static final int HAS_UNINTERESTING = 1 << 4;++ /**+ * Connect the supplied queue to this generator's own free list (if any).+ *+ * @param q+ * another FIFO queue that wants to share our queue's free list.+ */+ void shareFreeList(final BlockRevQueue q) {+ // Do nothing by default.+ }++ /**+ * Obtain flags describing the output behavior of this generator.+ *+ * @return one or more of the constants declared in this class, describing+ * how this generator produces its results.+ */+ abstract int outputType();++ /**+ * Return the next commit to the application, or the next generator.+ *+ * @return next available commit; null if no more are to be returned.+ * @throws MissingObjectException+ * @throws IncorrectObjectTypeException+ * @throws IOException+ */+ abstract RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException;+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/LIFORevQueue.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/LIFORevQueue.javanew file mode 100644index 0000000000..9abaf8dccf--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/LIFORevQueue.java@@ -0,0 +1,121 @@+/*+ * Copyright (C) 2009, Google Inc.+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/** A queue of commits in LIFO order. */+public class LIFORevQueue extends BlockRevQueue {+ private Block head;++ /** Create an empty LIFO queue. */+ public LIFORevQueue() {+ super();+ }++ LIFORevQueue(final Generator s) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ super(s);+ }++ public void add(final RevCommit c) {+ Block b = head;+ if (b == null || !b.canUnpop()) {+ b = free.newBlock();+ b.resetToEnd();+ b.next = head;+ head = b;+ }+ b.unpop(c);+ }++ public RevCommit next() {+ final Block b = head;+ if (b == null)+ return null;++ final RevCommit c = b.pop();+ if (b.isEmpty()) {+ head = b.next;+ free.freeBlock(b);+ }+ return c;+ }++ public void clear() {+ head = null;+ free.clear();+ }++ boolean everbodyHasFlag(final int f) {+ for (Block b = head; b != null; b = b.next) {+ for (int i = b.headIndex; i < b.tailIndex; i++)+ if ((b.commits[i].flags & f) == 0)+ return false;+ }+ return true;+ }++ boolean anybodyHasFlag(final int f) {+ for (Block b = head; b != null; b = b.next) {+ for (int i = b.headIndex; i < b.tailIndex; i++)+ if ((b.commits[i].flags & f) != 0)+ return true;+ }+ return false;+ }++ public String toString() {+ final StringBuilder s = new StringBuilder();+ for (Block q = head; q != null; q = q.next) {+ for (int i = q.headIndex; i < q.tailIndex; i++)+ describe(s, q.commits[i]);+ }+ return s.toString();+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/MergeBaseGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/MergeBaseGenerator.javanew file mode 100644index 0000000000..7822947c92--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/MergeBaseGenerator.java@@ -0,0 +1,226 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;+import java.text.MessageFormat;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.internal.JGitText;++/**+ * Computes the merge base(s) of the starting commits.+ * <p>+ * This generator is selected if the RevFilter is only+ * {@link org.eclipse.jgit.revwalk.filter.RevFilter#MERGE_BASE}.+ * <p>+ * To compute the merge base we assign a temporary flag to each of the starting+ * commits. The maximum number of starting commits is bounded by the number of+ * free flags available in the RevWalk when the generator is initialized. These+ * flags will be automatically released on the next reset of the RevWalk, but+ * not until then, as they are assigned to commits throughout the history.+ * <p>+ * Several internal flags are reused here for a different purpose, but this+ * should not have any impact as this generator should be run alone, and without+ * any other generators wrapped around it.+ */+class MergeBaseGenerator extends Generator {+ private static final int PARSED = RevWalk.PARSED;++ private static final int IN_PENDING = RevWalk.SEEN;++ private static final int POPPED = RevWalk.TEMP_MARK;++ private static final int MERGE_BASE = RevWalk.REWRITE;++ private final RevWalk walker;++ private final DateRevQueue pending;++ private int branchMask;++ private int recarryTest;++ private int recarryMask;++ MergeBaseGenerator(final RevWalk w) {+ walker = w;+ pending = new DateRevQueue();+ }++ void init(final AbstractRevQueue p) {+ try {+ for (;;) {+ final RevCommit c = p.next();+ if (c == null)+ break;+ add(c);+ }+ } finally {+ // Always free the flags immediately. This ensures the flags+ // will be available for reuse when the walk resets.+ //+ walker.freeFlag(branchMask);++ // Setup the condition used by carryOntoOne to detect a late+ // merge base and produce it on the next round.+ //+ recarryTest = branchMask | POPPED;+ recarryMask = branchMask | POPPED | MERGE_BASE;+ }+ }++ private void add(final RevCommit c) {+ final int flag = walker.allocFlag();+ branchMask |= flag;+ if ((c.flags & branchMask) != 0) {+ // This should never happen. RevWalk ensures we get a+ // commit admitted to the initial queue only once. If+ // we see this marks aren't correctly erased.+ //+ throw new IllegalStateException(MessageFormat.format(JGitText.get().staleRevFlagsOn, c.name()));+ }+ c.flags |= flag;+ pending.add(c);+ }++ @Override+ int outputType() {+ return 0;+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ for (;;) {+ final RevCommit c = pending.next();+ if (c == null) {+ walker.reader.walkAdviceEnd();+ return null;+ }++ for (final RevCommit p : c.parents) {+ if ((p.flags & IN_PENDING) != 0)+ continue;+ if ((p.flags & PARSED) == 0)+ p.parseHeaders(walker);+ p.flags |= IN_PENDING;+ pending.add(p);+ }++ int carry = c.flags & branchMask;+ boolean mb = carry == branchMask;+ if (mb) {+ // If we are a merge base make sure our ancestors are+ // also flagged as being popped, so that they do not+ // generate to the caller.+ //+ carry |= MERGE_BASE;+ }+ carryOntoHistory(c, carry);++ if ((c.flags & MERGE_BASE) != 0) {+ // This commit is an ancestor of a merge base we already+ // popped back to the caller. If everyone in pending is+ // that way we are done traversing; if not we just need+ // to move to the next available commit and try again.+ //+ if (pending.everbodyHasFlag(MERGE_BASE))+ return null;+ continue;+ }+ c.flags |= POPPED;++ if (mb) {+ c.flags |= MERGE_BASE;+ return c;+ }+ }+ }++ private void carryOntoHistory(RevCommit c, final int carry) {+ for (;;) {+ final RevCommit[] pList = c.parents;+ if (pList == null)+ return;+ final int n = pList.length;+ if (n == 0)+ return;++ for (int i = 1; i < n; i++) {+ final RevCommit p = pList[i];+ if (!carryOntoOne(p, carry))+ carryOntoHistory(p, carry);+ }++ c = pList[0];+ if (carryOntoOne(c, carry))+ break;+ }+ }++ private boolean carryOntoOne(final RevCommit p, final int carry) {+ final boolean haveAll = (p.flags & carry) == carry;+ p.flags |= carry;++ if ((p.flags & recarryMask) == recarryTest) {+ // We were popped without being a merge base, but we just got+ // voted to be one. Inject ourselves back at the front of the+ // pending queue and tell all of our ancestors they are within+ // the merge base now.+ //+ p.flags &= ~POPPED;+ pending.add(p);+ carryOntoHistory(p, branchMask | MERGE_BASE);+ return true;+ }++ // If we already had all carried flags, our parents do too.+ // Return true to stop the caller from running down this leg+ // of the revision graph any further.+ //+ return haveAll;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/ObjectWalk.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/ObjectWalk.javanew file mode 100644index 0000000000..b73ccb1974--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/ObjectWalk.java@@ -0,0 +1,771 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;+import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT;+import static org.eclipse.jgit.lib.Constants.OBJ_TREE;++import java.io.IOException;+import java.text.MessageFormat;+import java.util.ArrayList;+import java.util.List;++import org.eclipse.jgit.errors.CorruptObjectException;+import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.LargeObjectException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.internal.JGitText;+import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.ObjectReader;+import org.eclipse.jgit.lib.Repository;+import org.eclipse.jgit.util.RawParseUtils;++/**+ * Specialized subclass of RevWalk to include trees, blobs and tags.+ * <p>+ * Unlike RevWalk this subclass is able to remember starting roots that include+ * annotated tags, or arbitrary trees or blobs. Once commit generation is+ * complete and all commits have been popped by the application, individual+ * annotated tag, tree and blob objects can be popped through the additional+ * method {@link #nextObject()}.+ * <p>+ * Tree and blob objects reachable from interesting commits are automatically+ * scheduled for inclusion in the results of {@link #nextObject()}, returning+ * each object exactly once. Objects are sorted and returned according to the+ * the commits that reference them and the order they appear within a tree.+ * Ordering can be affected by changing the {@link RevSort} used to order the+ * commits that are returned first.+ */+public class ObjectWalk extends RevWalk {+ private static final int ID_SZ = 20;+ private static final int TYPE_SHIFT = 12;+ private static final int TYPE_TREE = 0040000 >>> TYPE_SHIFT;+ private static final int TYPE_SYMLINK = 0120000 >>> TYPE_SHIFT;+ private static final int TYPE_FILE = 0100000 >>> TYPE_SHIFT;+ private static final int TYPE_GITLINK = 0160000 >>> TYPE_SHIFT;++ /**+ * Indicates a non-RevCommit is in {@link #pendingObjects}.+ * <p>+ * We can safely reuse {@link RevWalk#REWRITE} here for the same value as it+ * is only set on RevCommit and {@link #pendingObjects} never has RevCommit+ * instances inserted into it.+ */+ private static final int IN_PENDING = RevWalk.REWRITE;++ private List<RevObject> rootObjects;++ private BlockObjQueue pendingObjects;++ private RevCommit firstCommit;++ private RevCommit lastCommit;++ private TreeVisit freeVisit;++ private TreeVisit currVisit;++ private byte[] pathBuf;++ private int pathLen;++ private boolean boundary;++ /**+ * Create a new revision and object walker for a given repository.+ *+ * @param repo+ * the repository the walker will obtain data from.+ */+ public ObjectWalk(final Repository repo) {+ this(repo.newObjectReader());+ }++ /**+ * Create a new revision and object walker for a given repository.+ *+ * @param or+ * the reader the walker will obtain data from. The reader should+ * be released by the caller when the walker is no longer+ * required.+ */+ public ObjectWalk(ObjectReader or) {+ super(or);+ rootObjects = new ArrayList<RevObject>();+ pendingObjects = new BlockObjQueue();+ pathBuf = new byte[256];+ }++ /**+ * Mark an object or commit to start graph traversal from.+ * <p>+ * Callers are encouraged to use {@link RevWalk#parseAny(AnyObjectId)}+ * instead of {@link RevWalk#lookupAny(AnyObjectId, int)}, as this method+ * requires the object to be parsed before it can be added as a root for the+ * traversal.+ * <p>+ * The method will automatically parse an unparsed object, but error+ * handling may be more difficult for the application to explain why a+ * RevObject is not actually valid. The object pool of this walker would+ * also be 'poisoned' by the invalid RevObject.+ * <p>+ * This method will automatically call {@link RevWalk#markStart(RevCommit)}+ * if passed RevCommit instance, or a RevTag that directly (or indirectly)+ * references a RevCommit.+ *+ * @param o+ * the object to start traversing from. The object passed must be+ * from this same revision walker.+ * @throws MissingObjectException+ * the object supplied is not available from the object+ * database. This usually indicates the supplied object is+ * invalid, but the reference was constructed during an earlier+ * invocation to {@link RevWalk#lookupAny(AnyObjectId, int)}.+ * @throws IncorrectObjectTypeException+ * the object was not parsed yet and it was discovered during+ * parsing that it is not actually the type of the instance+ * passed in. This usually indicates the caller used the wrong+ * type in a {@link RevWalk#lookupAny(AnyObjectId, int)} call.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public void markStart(RevObject o) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ while (o instanceof RevTag) {+ addObject(o);+ o = ((RevTag) o).getObject();+ parseHeaders(o);+ }++ if (o instanceof RevCommit)+ super.markStart((RevCommit) o);+ else+ addObject(o);+ }++ /**+ * Mark an object to not produce in the output.+ * <p>+ * Uninteresting objects denote not just themselves but also their entire+ * reachable chain, back until the merge base of an uninteresting commit and+ * an otherwise interesting commit.+ * <p>+ * Callers are encouraged to use {@link RevWalk#parseAny(AnyObjectId)}+ * instead of {@link RevWalk#lookupAny(AnyObjectId, int)}, as this method+ * requires the object to be parsed before it can be added as a root for the+ * traversal.+ * <p>+ * The method will automatically parse an unparsed object, but error+ * handling may be more difficult for the application to explain why a+ * RevObject is not actually valid. The object pool of this walker would+ * also be 'poisoned' by the invalid RevObject.+ * <p>+ * This method will automatically call {@link RevWalk#markStart(RevCommit)}+ * if passed RevCommit instance, or a RevTag that directly (or indirectly)+ * references a RevCommit.+ *+ * @param o+ * the object to start traversing from. The object passed must be+ * @throws MissingObjectException+ * the object supplied is not available from the object+ * database. This usually indicates the supplied object is+ * invalid, but the reference was constructed during an earlier+ * invocation to {@link RevWalk#lookupAny(AnyObjectId, int)}.+ * @throws IncorrectObjectTypeException+ * the object was not parsed yet and it was discovered during+ * parsing that it is not actually the type of the instance+ * passed in. This usually indicates the caller used the wrong+ * type in a {@link RevWalk#lookupAny(AnyObjectId, int)} call.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public void markUninteresting(RevObject o) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ while (o instanceof RevTag) {+ o.flags |= UNINTERESTING;+ if (boundary)+ addObject(o);+ o = ((RevTag) o).getObject();+ parseHeaders(o);+ }++ if (o instanceof RevCommit)+ markUninteresting((RevCommit) o);+ else if (o instanceof RevTree)+ markTreeUninteresting((RevTree) o);+ else+ o.flags |= UNINTERESTING;++ if (o.getType() != OBJ_COMMIT && boundary)+ addObject(o);+ }++ @Override+ public void markUninteresting(RevCommit c) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ super.markUninteresting(c);+ try {+ markTreeUninteresting(c.getTree());+ } catch (MissingObjectException e) {+ // we don't care if the tree of the commit does not exist locally+ }+ }++ @Override+ public void sort(RevSort s) {+ super.sort(s);+ boundary = hasRevSort(RevSort.BOUNDARY);+ }++ @Override+ public void sort(RevSort s, boolean use) {+ super.sort(s, use);+ boundary = hasRevSort(RevSort.BOUNDARY);+ }++ @Override+ public RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ for (;;) {+ final RevCommit r = super.next();+ if (r == null) {+ if (firstCommit != null)+ reader.walkAdviceBeginTrees(this, firstCommit, lastCommit);+ return null;+ }+ if ((r.flags & UNINTERESTING) != 0) {+ markTreeUninteresting(r.getTree());+ if (boundary)+ return r;+ continue;+ }+ if (firstCommit == null)+ firstCommit = r;+ lastCommit = r;+ pendingObjects.add(r.getTree());+ return r;+ }+ }++ /**+ * Pop the next most recent object.+ *+ * @return next most recent object; null if traversal is over.+ * @throws MissingObjectException+ * one or or more of the next objects are not available from the+ * object database, but were thought to be candidates for+ * traversal. This usually indicates a broken link.+ * @throws IncorrectObjectTypeException+ * one or or more of the objects in a tree do not match the type+ * indicated.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public RevObject nextObject() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ pathLen = 0;++ TreeVisit tv = currVisit;+ while (tv != null) {+ byte[] buf = tv.buf;+ for (int ptr = tv.ptr; ptr < buf.length;) {+ int startPtr = ptr;+ ptr = findObjectId(buf, ptr);+ idBuffer.fromRaw(buf, ptr);+ ptr += ID_SZ;++ RevObject obj = objects.get(idBuffer);+ if (obj != null && (obj.flags & SEEN) != 0)+ continue;++ int mode = parseMode(buf, startPtr, ptr, tv);+ int flags;+ switch (mode >>> TYPE_SHIFT) {+ case TYPE_FILE:+ case TYPE_SYMLINK:+ if (obj == null) {+ obj = new RevBlob(idBuffer);+ obj.flags = SEEN;+ objects.add(obj);+ return obj;+ }+ if (!(obj instanceof RevBlob))+ throw new IncorrectObjectTypeException(obj, OBJ_BLOB);+ obj.flags = flags = obj.flags | SEEN;+ if ((flags & UNINTERESTING) == 0)+ return obj;+ if (boundary)+ return obj;+ continue;++ case TYPE_TREE:+ if (obj == null) {+ obj = new RevTree(idBuffer);+ obj.flags = SEEN;+ objects.add(obj);+ return enterTree(obj);+ }+ if (!(obj instanceof RevTree))+ throw new IncorrectObjectTypeException(obj, OBJ_TREE);+ obj.flags = flags = obj.flags | SEEN;+ if ((flags & UNINTERESTING) == 0)+ return enterTree(obj);+ if (boundary)+ return enterTree(obj);+ continue;++ case TYPE_GITLINK:+ continue;++ default:+ throw new CorruptObjectException(MessageFormat.format(+ JGitText.get().corruptObjectInvalidMode3,+ String.format("%o", Integer.valueOf(mode)), //$NON-NLS-1$+ idBuffer.name(),+ RawParseUtils.decode(buf, tv.namePtr, tv.nameEnd),+ tv.obj));+ }+ }++ currVisit = tv.parent;+ releaseTreeVisit(tv);+ tv = currVisit;+ }++ for (;;) {+ RevObject o = pendingObjects.next();+ if (o == null) {+ reader.walkAdviceEnd();+ return null;+ }+ int flags = o.flags;+ if ((flags & SEEN) != 0)+ continue;+ flags |= SEEN;+ o.flags = flags;+ if ((flags & UNINTERESTING) == 0 | boundary) {+ if (o instanceof RevTree) {+ tv = newTreeVisit(o);+ tv.parent = null;+ currVisit = tv;+ }+ return o;+ }+ }+ }++ private RevObject enterTree(RevObject obj) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ TreeVisit tv = newTreeVisit(obj);+ tv.parent = currVisit;+ currVisit = tv;+ return obj;+ }++ private static int findObjectId(byte[] buf, int ptr) {+ // Skip over the mode and name until the NUL before the ObjectId+ // can be located. Skip the NUL as the function returns.+ for (;;) {+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;++ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;++ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;++ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ if (buf[++ptr] == 0) return ++ptr;+ }+ }++ private static int parseMode(byte[] buf, int startPtr, int recEndPtr, TreeVisit tv) {+ int mode = buf[startPtr] - '0';+ for (;;) {+ byte c = buf[++startPtr];+ if (' ' == c)+ break;+ mode <<= 3;+ mode += c - '0';++ c = buf[++startPtr];+ if (' ' == c)+ break;+ mode <<= 3;+ mode += c - '0';++ c = buf[++startPtr];+ if (' ' == c)+ break;+ mode <<= 3;+ mode += c - '0';++ c = buf[++startPtr];+ if (' ' == c)+ break;+ mode <<= 3;+ mode += c - '0';++ c = buf[++startPtr];+ if (' ' == c)+ break;+ mode <<= 3;+ mode += c - '0';++ c = buf[++startPtr];+ if (' ' == c)+ break;+ mode <<= 3;+ mode += c - '0';++ c = buf[++startPtr];+ if (' ' == c)+ break;+ mode <<= 3;+ mode += c - '0';+ }++ tv.ptr = recEndPtr;+ tv.namePtr = startPtr + 1;+ tv.nameEnd = recEndPtr - (ID_SZ + 1);+ return mode;+ }++ /**+ * Verify all interesting objects are available, and reachable.+ * <p>+ * Callers should populate starting points and ending points with+ * {@link #markStart(RevObject)} and {@link #markUninteresting(RevObject)}+ * and then use this method to verify all objects between those two points+ * exist in the repository and are readable.+ * <p>+ * This method returns successfully if everything is connected; it throws an+ * exception if there is a connectivity problem. The exception message+ * provides some detail about the connectivity failure.+ *+ * @throws MissingObjectException+ * one or or more of the next objects are not available from the+ * object database, but were thought to be candidates for+ * traversal. This usually indicates a broken link.+ * @throws IncorrectObjectTypeException+ * one or or more of the objects in a tree do not match the type+ * indicated.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public void checkConnectivity() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ for (;;) {+ final RevCommit c = next();+ if (c == null)+ break;+ }+ for (;;) {+ final RevObject o = nextObject();+ if (o == null)+ break;+ if (o instanceof RevBlob && !reader.has(o))+ throw new MissingObjectException(o, OBJ_BLOB);+ }+ }++ /**+ * Get the current object's complete path.+ * <p>+ * This method is not very efficient and is primarily meant for debugging+ * and final output generation. Applications should try to avoid calling it,+ * and if invoked do so only once per interesting entry, where the name is+ * absolutely required for correct function.+ *+ * @return complete path of the current entry, from the root of the+ * repository. If the current entry is in a subtree there will be at+ * least one '/' in the returned string. Null if the current entry+ * has no path, such as for annotated tags or root level trees.+ */+ public String getPathString() {+ if (pathLen == 0) {+ pathLen = updatePathBuf(currVisit);+ if (pathLen == 0)+ return null;+ }+ return RawParseUtils.decode(pathBuf, 0, pathLen);+ }++ /**+ * Get the current object's path hash code.+ * <p>+ * This method computes a hash code on the fly for this path, the hash is+ * suitable to cluster objects that may have similar paths together.+ *+ * @return path hash code; any integer may be returned.+ */+ public int getPathHashCode() {+ TreeVisit tv = currVisit;+ if (tv == null)+ return 0;++ int nameEnd = tv.nameEnd;+ if (nameEnd == 0) {+ // When nameEnd == 0 the subtree is itself the current path+ // being visited. The name hash must be obtained from its+ // parent tree. If there is no parent, this is a root tree with+ // a hash code of 0.+ tv = tv.parent;+ if (tv == null)+ return 0;+ nameEnd = tv.nameEnd;+ }++ byte[] buf;+ int ptr;++ if (16 <= (nameEnd - tv.namePtr)) {+ buf = tv.buf;+ ptr = nameEnd - 16;+ } else {+ nameEnd = pathLen;+ if (nameEnd == 0) {+ nameEnd = updatePathBuf(currVisit);+ pathLen = nameEnd;+ }+ buf = pathBuf;+ ptr = Math.max(0, nameEnd - 16);+ }++ int hash = 0;+ for (; ptr < nameEnd; ptr++) {+ byte c = buf[ptr];+ if (c != ' ')+ hash = (hash >>> 2) + (c << 24);+ }+ return hash;+ }++ /** @return the internal buffer holding the current path. */+ public byte[] getPathBuffer() {+ if (pathLen == 0)+ pathLen = updatePathBuf(currVisit);+ return pathBuf;+ }++ /** @return length of the path in {@link #getPathBuffer()}. */+ public int getPathLength() {+ if (pathLen == 0)+ pathLen = updatePathBuf(currVisit);+ return pathLen;+ }++ private int updatePathBuf(TreeVisit tv) {+ if (tv == null)+ return 0;++ // If nameEnd == 0 this tree has not yet contributed an entry.+ // Update only for the parent, which if null will be empty.+ int nameEnd = tv.nameEnd;+ if (nameEnd == 0)+ return updatePathBuf(tv.parent);++ int ptr = tv.pathLen;+ if (ptr == 0) {+ ptr = updatePathBuf(tv.parent);+ if (ptr == pathBuf.length)+ growPathBuf(ptr);+ if (ptr != 0)+ pathBuf[ptr++] = '/';+ tv.pathLen = ptr;+ }++ int namePtr = tv.namePtr;+ int nameLen = nameEnd - namePtr;+ int end = ptr + nameLen;+ while (pathBuf.length < end)+ growPathBuf(ptr);+ System.arraycopy(tv.buf, namePtr, pathBuf, ptr, nameLen);+ return end;+ }++ private void growPathBuf(int ptr) {+ byte[] newBuf = new byte[pathBuf.length << 1];+ System.arraycopy(pathBuf, 0, newBuf, 0, ptr);+ pathBuf = newBuf;+ }++ @Override+ public void dispose() {+ super.dispose();+ pendingObjects = new BlockObjQueue();+ firstCommit = null;+ lastCommit = null;+ currVisit = null;+ freeVisit = null;+ }++ @Override+ protected void reset(final int retainFlags) {+ super.reset(retainFlags);++ for (RevObject obj : rootObjects)+ obj.flags &= ~IN_PENDING;++ rootObjects = new ArrayList<RevObject>();+ pendingObjects = new BlockObjQueue();+ firstCommit = null;+ lastCommit = null;+ currVisit = null;+ freeVisit = null;+ }++ private void addObject(final RevObject o) {+ if ((o.flags & IN_PENDING) == 0) {+ o.flags |= IN_PENDING;+ rootObjects.add(o);+ pendingObjects.add(o);+ }+ }++ private void markTreeUninteresting(final RevTree tree)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ if ((tree.flags & UNINTERESTING) != 0)+ return;+ tree.flags |= UNINTERESTING;++ byte[] raw = reader.open(tree, OBJ_TREE).getCachedBytes();+ for (int ptr = 0; ptr < raw.length;) {+ byte c = raw[ptr];+ int mode = c - '0';+ for (;;) {+ c = raw[++ptr];+ if (' ' == c)+ break;+ mode <<= 3;+ mode += c - '0';+ }+ while (raw[++ptr] != 0) {+ // Skip entry name.+ }+ ptr++; // Skip NUL after entry name.++ switch (mode >>> TYPE_SHIFT) {+ case TYPE_FILE:+ case TYPE_SYMLINK:+ idBuffer.fromRaw(raw, ptr);+ lookupBlob(idBuffer).flags |= UNINTERESTING;+ break;++ case TYPE_TREE:+ idBuffer.fromRaw(raw, ptr);+ markTreeUninteresting(lookupTree(idBuffer));+ break;++ case TYPE_GITLINK:+ break;++ default:+ idBuffer.fromRaw(raw, ptr);+ throw new CorruptObjectException(MessageFormat.format(+ JGitText.get().corruptObjectInvalidMode3,+ String.format("%o", Integer.valueOf(mode)), //$NON-NLS-1$+ idBuffer.name(), "", tree)); //$NON-NLS-1$+ }+ ptr += ID_SZ;+ }+ }++ private TreeVisit newTreeVisit(RevObject obj) throws LargeObjectException,+ MissingObjectException, IncorrectObjectTypeException, IOException {+ TreeVisit tv = freeVisit;+ if (tv != null) {+ freeVisit = tv.parent;+ tv.ptr = 0;+ tv.namePtr = 0;+ tv.nameEnd = 0;+ tv.pathLen = 0;+ } else {+ tv = new TreeVisit();+ }+ tv.obj = obj;+ tv.buf = reader.open(obj, OBJ_TREE).getCachedBytes();+ return tv;+ }++ private void releaseTreeVisit(TreeVisit tv) {+ tv.buf = null;+ tv.parent = freeVisit;+ freeVisit = tv;+ }++ private static class TreeVisit {+ /** Parent tree visit that entered this tree, null if root tree. */+ TreeVisit parent;++ /** The RevTree currently being iterated through. */+ RevObject obj;++ /** Canonical encoding of the tree named by {@link #obj}. */+ byte[] buf;++ /** Index of next entry to parse in {@link #buf}. */+ int ptr;++ /** Start of the current name entry in {@link #buf}. */+ int namePtr;++ /** One past end of name, {@code nameEnd - namePtr} is the length. */+ int nameEnd;++ /** Number of bytes in the path leading up to this tree. */+ int pathLen;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/PendingGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/PendingGenerator.javanew file mode 100644index 0000000000..f24c27873f--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/PendingGenerator.java@@ -0,0 +1,185 @@+/*+ * Copyright (C) 2009, Google Inc.+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.errors.StopWalkException;+import org.eclipse.jgit.lib.ObjectId;+import org.eclipse.jgit.revwalk.filter.RevFilter;++/**+ * Default (and first pass) RevCommit Generator implementation for RevWalk.+ * <p>+ * This generator starts from a set of one or more commits and process them in+ * descending (newest to oldest) commit time order. Commits automatically cause+ * their parents to be enqueued for further processing, allowing the entire+ * commit graph to be walked. A {@link RevFilter} may be used to select a subset+ * of the commits and return them to the caller.+ */+class PendingGenerator extends Generator {+ private static final int PARSED = RevWalk.PARSED;++ private static final int SEEN = RevWalk.SEEN;++ private static final int UNINTERESTING = RevWalk.UNINTERESTING;++ /**+ * Number of additional commits to scan after we think we are done.+ * <p>+ * This small buffer of commits is scanned to ensure we didn't miss anything+ * as a result of clock skew when the commits were made. We need to set our+ * constant to 1 additional commit due to the use of a pre-increment+ * operator when accessing the value.+ */+ static final int OVER_SCAN = 5 + 1;++ /** A commit near the end of time, to initialize {@link #last} with. */+ private static final RevCommit INIT_LAST;++ static {+ INIT_LAST = new RevCommit(ObjectId.zeroId());+ INIT_LAST.commitTime = Integer.MAX_VALUE;+ }++ private final RevWalk walker;++ private final DateRevQueue pending;++ private final RevFilter filter;++ private final int output;++ /** Last commit produced to the caller from {@link #next()}. */+ private RevCommit last = INIT_LAST;++ /**+ * Number of commits we have remaining in our over-scan allotment.+ * <p>+ * Only relevant if there are {@link #UNINTERESTING} commits in the+ * {@link #pending} queue.+ */+ private int overScan = OVER_SCAN;++ boolean canDispose;++ PendingGenerator(final RevWalk w, final DateRevQueue p,+ final RevFilter f, final int out) {+ walker = w;+ pending = p;+ filter = f;+ output = out;+ canDispose = true;+ }++ @Override+ int outputType() {+ return output | SORT_COMMIT_TIME_DESC;+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ try {+ for (;;) {+ final RevCommit c = pending.next();+ if (c == null) {+ walker.reader.walkAdviceEnd();+ return null;+ }++ final boolean produce;+ if ((c.flags & UNINTERESTING) != 0)+ produce = false;+ else {+ if (filter.requiresCommitBody())+ c.parseBody(walker);+ produce = filter.include(walker, c);+ }++ for (final RevCommit p : c.parents) {+ if ((p.flags & SEEN) != 0)+ continue;+ if ((p.flags & PARSED) == 0)+ p.parseHeaders(walker);+ p.flags |= SEEN;+ pending.add(p);+ }+ walker.carryFlagsImpl(c);++ if ((c.flags & UNINTERESTING) != 0) {+ if (pending.everbodyHasFlag(UNINTERESTING)) {+ final RevCommit n = pending.peek();+ if (n != null && n.commitTime >= last.commitTime) {+ // This is too close to call. The next commit we+ // would pop is dated after the last one produced.+ // We have to keep going to ensure that we carry+ // flags as much as necessary.+ //+ overScan = OVER_SCAN;+ } else if (--overScan == 0)+ throw StopWalkException.INSTANCE;+ } else {+ overScan = OVER_SCAN;+ }+ if (canDispose)+ c.disposeBody();+ continue;+ }++ if (produce)+ return last = c;+ else if (canDispose)+ c.disposeBody();+ }+ } catch (StopWalkException swe) {+ walker.reader.walkAdviceEnd();+ pending.clear();+ return null;+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RenameCallback.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RenameCallback.javanew file mode 100644index 0000000000..377835534e--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RenameCallback.java@@ -0,0 +1,62 @@+/*+ * Copyright (C) 2011, GEBIT Solutions+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */+package org.eclipse.jgit.revwalk;++import org.eclipse.jgit.diff.DiffEntry;++/**+ * An instance of this class can be used in conjunction with a+ * {@link FollowFilter}. Whenever a rename has been detected during a revision+ * walk, it will be reported here.+ * @see FollowFilter#setRenameCallback(RenameCallback)+ */+public abstract class RenameCallback {+ /**+ * Called whenever a diff was found that is actually a rename or copy of a+ * file.+ *+ * @param entry+ * the entry representing the rename/copy+ */+ public abstract void renamed(DiffEntry entry);+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevBlob.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevBlob.javanew file mode 100644index 0000000000..4245fcab94--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevBlob.java@@ -0,0 +1,87 @@+/*+ * Copyright (C) 2009, Google Inc.+ * Copyright (C) 2008, Marek Zawirski <[email protected]>+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.Constants;++/** A binary file, or a symbolic link. */+public class RevBlob extends RevObject {+ /**+ * Create a new blob reference.+ *+ * @param id+ * object name for the blob.+ */+ protected RevBlob(final AnyObjectId id) {+ super(id);+ }++ @Override+ public final int getType() {+ return Constants.OBJ_BLOB;+ }++ @Override+ void parseHeaders(RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (walk.reader.has(this))+ flags |= PARSED;+ else+ throw new MissingObjectException(this, getType());+ }++ @Override+ void parseBody(RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if ((flags & PARSED) == 0)+ parseHeaders(walk);+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevCommit.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevCommit.javanew file mode 100644index 0000000000..fac4f809f2--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevCommit.java@@ -0,0 +1,623 @@+/*+ * Copyright (C) 2008-2009, Google Inc.+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;+import java.nio.charset.Charset;+import java.util.ArrayList;+import java.util.Collections;+import java.util.List;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.Constants;+import org.eclipse.jgit.lib.MutableObjectId;+import org.eclipse.jgit.lib.ObjectInserter;+import org.eclipse.jgit.lib.ObjectReader;+import org.eclipse.jgit.lib.PersonIdent;+import org.eclipse.jgit.util.RawParseUtils;+import org.eclipse.jgit.util.StringUtils;++/** A commit reference to a commit in the DAG. */+public class RevCommit extends RevObject {+ private static final int STACK_DEPTH = 500;++ /**+ * Parse a commit from its canonical format.+ *+ * This method constructs a temporary revision pool, parses the commit as+ * supplied, and returns it to the caller. Since the commit was built inside+ * of a private revision pool its parent pointers will be initialized, but+ * will not have their headers loaded.+ *+ * Applications are discouraged from using this API. Callers usually need+ * more than one commit. Use {@link RevWalk#parseCommit(AnyObjectId)} to+ * obtain a RevCommit from an existing repository.+ *+ * @param raw+ * the canonical formatted commit to be parsed.+ * @return the parsed commit, in an isolated revision pool that is not+ * available to the caller.+ */+ public static RevCommit parse(byte[] raw) {+ try {+ return parse(new RevWalk((ObjectReader) null), raw);+ } catch (IOException ex) {+ throw new RuntimeException(ex);+ }+ }++ /**+ * Parse a commit from its canonical format.+ *+ * This method inserts the commit directly into the caller supplied revision+ * pool, making it appear as though the commit exists in the repository,+ * even if it doesn't. The repository under the pool is not affected.+ *+ * @param rw+ * the revision pool to allocate the commit within. The commit's+ * tree and parent pointers will be obtained from this pool.+ * @param raw+ * the canonical formatted commit to be parsed.+ * @return the parsed commit, in an isolated revision pool that is not+ * available to the caller.+ * @throws IOException+ * in case of RevWalk initialization fails+ */+ public static RevCommit parse(RevWalk rw, byte[] raw) throws IOException {+ ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();+ boolean retain = rw.isRetainBody();+ rw.setRetainBody(true);+ RevCommit r = rw.lookupCommit(fmt.idFor(Constants.OBJ_COMMIT, raw));+ r.parseCanonical(rw, raw);+ rw.setRetainBody(retain);+ return r;+ }++ static final RevCommit[] NO_PARENTS = {};++ private RevTree tree;++ RevCommit[] parents;++ int commitTime; // An int here for performance, overflows in 2038++ int inDegree;++ private byte[] buffer;++ /**+ * Create a new commit reference.+ *+ * @param id+ * object name for the commit.+ */+ protected RevCommit(final AnyObjectId id) {+ super(id);+ }++ @Override+ void parseHeaders(final RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ parseCanonical(walk, walk.getCachedBytes(this));+ }++ @Override+ void parseBody(final RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (buffer == null) {+ buffer = walk.getCachedBytes(this);+ if ((flags & PARSED) == 0)+ parseCanonical(walk, buffer);+ }+ }++ void parseCanonical(final RevWalk walk, final byte[] raw)+ throws IOException {+ if (!walk.shallowCommitsInitialized)+ walk.initializeShallowCommits();++ final MutableObjectId idBuffer = walk.idBuffer;+ idBuffer.fromString(raw, 5);+ tree = walk.lookupTree(idBuffer);++ int ptr = 46;+ if (parents == null) {+ RevCommit[] pList = new RevCommit[1];+ int nParents = 0;+ for (;;) {+ if (raw[ptr] != 'p')+ break;+ idBuffer.fromString(raw, ptr + 7);+ final RevCommit p = walk.lookupCommit(idBuffer);+ if (nParents == 0)+ pList[nParents++] = p;+ else if (nParents == 1) {+ pList = new RevCommit[] { pList[0], p };+ nParents = 2;+ } else {+ if (pList.length <= nParents) {+ RevCommit[] old = pList;+ pList = new RevCommit[pList.length + 32];+ System.arraycopy(old, 0, pList, 0, nParents);+ }+ pList[nParents++] = p;+ }+ ptr += 48;+ }+ if (nParents != pList.length) {+ RevCommit[] old = pList;+ pList = new RevCommit[nParents];+ System.arraycopy(old, 0, pList, 0, nParents);+ }+ parents = pList;+ }++ // extract time from "committer "+ ptr = RawParseUtils.committer(raw, ptr);+ if (ptr > 0) {+ ptr = RawParseUtils.nextLF(raw, ptr, '>');++ // In 2038 commitTime will overflow unless it is changed to long.+ commitTime = RawParseUtils.parseBase10(raw, ptr, null);+ }++ if (walk.isRetainBody())+ buffer = raw;+ flags |= PARSED;+ }++ @Override+ public final int getType() {+ return Constants.OBJ_COMMIT;+ }++ static void carryFlags(RevCommit c, int carry) {+ FIFORevQueue q = carryFlags1(c, carry, 0);+ if (q != null)+ slowCarryFlags(q, carry);+ }++ private static FIFORevQueue carryFlags1(RevCommit c, int carry, int depth) {+ for(;;) {+ RevCommit[] pList = c.parents;+ if (pList == null || pList.length == 0)+ return null;+ if (pList.length != 1) {+ if (depth == STACK_DEPTH)+ return defer(c);+ for (int i = 1; i < pList.length; i++) {+ RevCommit p = pList[i];+ if ((p.flags & carry) == carry)+ continue;+ p.flags |= carry;+ FIFORevQueue q = carryFlags1(c, carry, depth + 1);+ if (q != null)+ return defer(q, carry, pList, i + 1);+ }+ }++ c = pList[0];+ if ((c.flags & carry) == carry)+ return null;+ c.flags |= carry;+ }+ }++ private static FIFORevQueue defer(RevCommit c) {+ FIFORevQueue q = new FIFORevQueue();+ q.add(c);+ return q;+ }++ private static FIFORevQueue defer(FIFORevQueue q, int carry,+ RevCommit[] pList, int i) {+ // In normal case the caller will run pList[0] in a tail recursive+ // fashion by updating the variable. However the caller is unwinding+ // the stack and will skip that pList[0] execution step.+ carryOneStep(q, carry, pList[0]);++ // Remaining parents (if any) need to have flags checked and be+ // enqueued if they have ancestors.+ for (; i < pList.length; i++)+ carryOneStep(q, carry, pList[i]);+ return q;+ }++ private static void slowCarryFlags(FIFORevQueue q, int carry) {+ // 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)+ carryOneStep(q, carry, p);+ }+ }++ private static void carryOneStep(FIFORevQueue q, int carry, RevCommit c) {+ if ((c.flags & carry) != carry) {+ c.flags |= carry;+ if (c.parents != null)+ q.add(c);+ }+ }++ /**+ * Carry a RevFlag set on this commit to its parents.+ * <p>+ * If this commit is parsed, has parents, and has the supplied flag set on+ * it we automatically add it to the parents, grand-parents, and so on until+ * an unparsed commit or a commit with no parents is discovered. This+ * permits applications to force a flag through the history chain when+ * necessary.+ *+ * @param flag+ * the single flag value to carry back onto parents.+ */+ public void carry(final RevFlag flag) {+ final int carry = flags & flag.mask;+ if (carry != 0)+ carryFlags(this, carry);+ }++ /**+ * Time from the "committer " line of the buffer.+ *+ * @return time, expressed as seconds since the epoch.+ */+ public final int getCommitTime() {+ return commitTime;+ }++ /**+ * Get a reference to this commit's tree.+ *+ * @return tree of this commit.+ */+ public final RevTree getTree() {+ return tree;+ }++ /**+ * Get the number of parent commits listed in this commit.+ *+ * @return number of parents; always a positive value but can be 0.+ */+ public final int getParentCount() {+ return parents.length;+ }++ /**+ * Get the nth parent from this commit's parent list.+ *+ * @param nth+ * parent index to obtain. Must be in the range 0 through+ * {@link #getParentCount()}-1.+ * @return the specified parent.+ * @throws ArrayIndexOutOfBoundsException+ * an invalid parent index was specified.+ */+ public final RevCommit getParent(final int nth) {+ return parents[nth];+ }++ /**+ * Obtain an array of all parents (<b>NOTE - THIS IS NOT A COPY</b>).+ * <p>+ * This method is exposed only to provide very fast, efficient access to+ * this commit's parent list. Applications relying on this list should be+ * very careful to ensure they do not modify its contents during their use+ * of it.+ *+ * @return the array of parents.+ */+ public final RevCommit[] getParents() {+ return parents;+ }++ /**+ * Obtain the raw unparsed commit body (<b>NOTE - THIS IS NOT A COPY</b>).+ * <p>+ * This method is exposed only to provide very fast, efficient access to+ * this commit's message buffer within a RevFilter. Applications relying on+ * 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.+ */+ public final byte[] getRawBuffer() {+ return buffer;+ }++ /**+ * Parse the author identity from the raw buffer.+ * <p>+ * This method parses and returns the content of the author line, after+ * taking the commit's character set into account and decoding the author+ * name and email address. This method is fairly expensive and produces a+ * new PersonIdent instance on each invocation. Callers should invoke this+ * method only if they are certain they will be outputting the result, and+ * should cache the return value for as long as necessary to use all+ * information from it.+ * <p>+ * RevFilter implementations should try to use {@link RawParseUtils} to scan+ * the {@link #getRawBuffer()} instead, as this will allow faster evaluation+ * of commits.+ *+ * @return identity of the author (name, email) and the time the commit was+ * made by the author; null if no author line was found.+ */+ public final PersonIdent getAuthorIdent() {+ final byte[] raw = buffer;+ final int nameB = RawParseUtils.author(raw, 0);+ if (nameB < 0)+ return null;+ return RawParseUtils.parsePersonIdent(raw, nameB);+ }++ /**+ * Parse the committer identity from the raw buffer.+ * <p>+ * This method parses and returns the content of the committer line, after+ * taking the commit's character set into account and decoding the committer+ * name and email address. This method is fairly expensive and produces a+ * new PersonIdent instance on each invocation. Callers should invoke this+ * method only if they are certain they will be outputting the result, and+ * should cache the return value for as long as necessary to use all+ * information from it.+ * <p>+ * RevFilter implementations should try to use {@link RawParseUtils} to scan+ * the {@link #getRawBuffer()} instead, as this will allow faster evaluation+ * of commits.+ *+ * @return identity of the committer (name, email) and the time the commit+ * was made by the committer; null if no committer line was found.+ */+ public final PersonIdent getCommitterIdent() {+ final byte[] raw = buffer;+ final int nameB = RawParseUtils.committer(raw, 0);+ if (nameB < 0)+ return null;+ return RawParseUtils.parsePersonIdent(raw, nameB);+ }++ /**+ * Parse the complete commit message and decode it to a string.+ * <p>+ * This method parses and returns the message portion of the commit buffer,+ * after taking the commit's character set into account and decoding the+ * buffer using that character set. This method is a fairly expensive+ * operation and produces a new string on each invocation.+ *+ * @return decoded commit message as a string. Never null.+ */+ public final String getFullMessage() {+ final byte[] raw = buffer;+ final int msgB = RawParseUtils.commitMessage(raw, 0);+ if (msgB < 0)+ return ""; //$NON-NLS-1$+ final Charset enc = RawParseUtils.parseEncoding(raw);+ return RawParseUtils.decode(enc, raw, msgB, raw.length);+ }++ /**+ * Parse the commit message and return the first "line" of it.+ * <p>+ * The first line is everything up to the first pair of LFs. This is the+ * "oneline" format, suitable for output in a single line display.+ * <p>+ * This method parses and returns the message portion of the commit buffer,+ * after taking the commit's character set into account and decoding the+ * buffer using that character set. This method is a fairly expensive+ * operation and produces a new string on each invocation.+ *+ * @return decoded commit message as a string. Never null. The returned+ * string does not contain any LFs, even if the first paragraph+ * spanned multiple lines. Embedded LFs are converted to spaces.+ */+ public final String getShortMessage() {+ final byte[] raw = buffer;+ final int msgB = RawParseUtils.commitMessage(raw, 0);+ if (msgB < 0)+ return ""; //$NON-NLS-1$++ final Charset enc = RawParseUtils.parseEncoding(raw);+ final int msgE = RawParseUtils.endOfParagraph(raw, msgB);+ String str = RawParseUtils.decode(enc, raw, msgB, msgE);+ if (hasLF(raw, msgB, msgE))+ str = StringUtils.replaceLineBreaksWithSpace(str);+ return str;+ }++ static boolean hasLF(final byte[] r, int b, final int e) {+ while (b < e)+ if (r[b++] == '\n')+ return true;+ return false;+ }++ /**+ * Determine the encoding of the commit message buffer.+ * <p>+ * Locates the "encoding" header (if present) and then returns the proper+ * character set to apply to this buffer to evaluate its contents as+ * character data.+ * <p>+ * If no encoding header is present, {@link Constants#CHARSET} is assumed.+ *+ * @return the preferred encoding of {@link #getRawBuffer()}.+ */+ public final Charset getEncoding() {+ return RawParseUtils.parseEncoding(buffer);+ }++ /**+ * Parse the footer lines (e.g. "Signed-off-by") for machine processing.+ * <p>+ * This method splits all of the footer lines out of the last paragraph of+ * the commit message, providing each line as a key-value pair, ordered by+ * the order of the line's appearance in the commit message itself.+ * <p>+ * A footer line's key must match the pattern {@code ^[A-Za-z0-9-]+:}, while+ * the value is free-form, but must not contain an LF. Very common keys seen+ * in the wild are:+ * <ul>+ * <li>{@code Signed-off-by} (agrees to Developer Certificate of Origin)+ * <li>{@code Acked-by} (thinks change looks sane in context)+ * <li>{@code Reported-by} (originally found the issue this change fixes)+ * <li>{@code Tested-by} (validated change fixes the issue for them)+ * <li>{@code CC}, {@code Cc} (copy on all email related to this change)+ * <li>{@code Bug} (link to project's bug tracking system)+ * </ul>+ *+ * @return ordered list of footer lines; empty list if no footers found.+ */+ public final List<FooterLine> getFooterLines() {+ final byte[] raw = buffer;+ int ptr = raw.length - 1;+ while (raw[ptr] == '\n') // trim any trailing LFs, not interesting+ ptr--;++ final int msgB = RawParseUtils.commitMessage(raw, 0);+ final ArrayList<FooterLine> r = new ArrayList<FooterLine>(4);+ final Charset enc = getEncoding();+ for (;;) {+ ptr = RawParseUtils.prevLF(raw, ptr);+ if (ptr <= msgB)+ break; // Don't parse commit headers as footer lines.++ final int keyStart = ptr + 2;+ if (raw[keyStart] == '\n')+ break; // Stop at first paragraph break, no footers above it.++ final int keyEnd = RawParseUtils.endOfFooterLineKey(raw, keyStart);+ if (keyEnd < 0)+ continue; // Not a well formed footer line, skip it.++ // Skip over the ': *' at the end of the key before the value.+ //+ int valStart = keyEnd + 1;+ while (valStart < raw.length && raw[valStart] == ' ')+ valStart++;++ // Value ends at the LF, and does not include it.+ //+ int valEnd = RawParseUtils.nextLF(raw, valStart);+ if (raw[valEnd - 1] == '\n')+ valEnd--;++ r.add(new FooterLine(raw, enc, keyStart, keyEnd, valStart, valEnd));+ }+ Collections.reverse(r);+ return r;+ }++ /**+ * Get the values of all footer lines with the given key.+ *+ * @param keyName+ * footer key to find values of, case insensitive.+ * @return values of footers with key of {@code keyName}, ordered by their+ * order of appearance. Duplicates may be returned if the same+ * footer appeared more than once. Empty list if no footers appear+ * with the specified key, or there are no footers at all.+ * @see #getFooterLines()+ */+ public final List<String> getFooterLines(final String keyName) {+ return getFooterLines(new FooterKey(keyName));+ }++ /**+ * Get the values of all footer lines with the given key.+ *+ * @param keyName+ * footer key to find values of, case insensitive.+ * @return values of footers with key of {@code keyName}, ordered by their+ * order of appearance. Duplicates may be returned if the same+ * footer appeared more than once. Empty list if no footers appear+ * with the specified key, or there are no footers at all.+ * @see #getFooterLines()+ */+ public final List<String> getFooterLines(final FooterKey keyName) {+ final List<FooterLine> src = getFooterLines();+ if (src.isEmpty())+ return Collections.emptyList();+ final ArrayList<String> r = new ArrayList<String>(src.size());+ for (final FooterLine f : src) {+ if (f.matches(keyName))+ r.add(f.getValue());+ }+ return r;+ }++ /**+ * Reset this commit to allow another RevWalk with the same instances.+ * <p>+ * Subclasses <b>must</b> call <code>super.reset()</code> to ensure the+ * basic information can be correctly cleared out.+ */+ public void reset() {+ inDegree = 0;+ }++ final void disposeBody() {+ buffer = null;+ }++ @Override+ public String toString() {+ final StringBuilder s = new StringBuilder();+ s.append(Constants.typeString(getType()));+ s.append(' ');+ s.append(name());+ s.append(' ');+ s.append(commitTime);+ s.append(' ');+ appendCoreFlags(s);+ return s.toString();+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevCommitList.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevCommitList.javanew file mode 100644index 0000000000..64f99bbd28--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevCommitList.java@@ -0,0 +1,424 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.revwalk.filter.RevFilter;++/**+ * An ordered list of {@link RevCommit} subclasses.+ *+ * @param <E>+ * type of subclass of RevCommit the list is storing.+ */+public class RevCommitList<E extends RevCommit> extends RevObjectList<E> {+ private RevWalk walker;++ @Override+ public void clear() {+ super.clear();+ walker = null;+ }++ /**+ * Apply a flag to all commits matching the specified filter.+ * <p>+ * Same as <code>applyFlag(matching, flag, 0, size())</code>, but without+ * the incremental behavior.+ *+ * @param matching+ * the filter to test commits with. If the filter includes a+ * commit it will have the flag set; if the filter does not+ * include the commit the flag will be unset.+ * @param flag+ * the flag to apply (or remove). Applications are responsible+ * for allocating this flag from the source RevWalk.+ * @throws IOException+ * revision filter needed to read additional objects, but an+ * error occurred while reading the pack files or loose objects+ * of the repository.+ * @throws IncorrectObjectTypeException+ * revision filter needed to read additional objects, but an+ * object was not of the correct type. Repository corruption may+ * have occurred.+ * @throws MissingObjectException+ * revision filter needed to read additional objects, but an+ * object that should be present was not found. Repository+ * corruption may have occurred.+ */+ public void applyFlag(final RevFilter matching, final RevFlag flag)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ applyFlag(matching, flag, 0, size());+ }++ /**+ * Apply a flag to all commits matching the specified filter.+ * <p>+ * This version allows incremental testing and application, such as from a+ * background thread that needs to periodically halt processing and send+ * updates to the UI.+ *+ * @param matching+ * the filter to test commits with. If the filter includes a+ * commit it will have the flag set; if the filter does not+ * include the commit the flag will be unset.+ * @param flag+ * the flag to apply (or remove). Applications are responsible+ * for allocating this flag from the source RevWalk.+ * @param rangeBegin+ * first commit within the list to begin testing at, inclusive.+ * Must not be negative, but may be beyond the end of the list.+ * @param rangeEnd+ * last commit within the list to end testing at, exclusive. If+ * smaller than or equal to <code>rangeBegin</code> then no+ * commits will be tested.+ * @throws IOException+ * revision filter needed to read additional objects, but an+ * error occurred while reading the pack files or loose objects+ * of the repository.+ * @throws IncorrectObjectTypeException+ * revision filter needed to read additional objects, but an+ * object was not of the correct type. Repository corruption may+ * have occurred.+ * @throws MissingObjectException+ * revision filter needed to read additional objects, but an+ * object that should be present was not found. Repository+ * corruption may have occurred.+ */+ public void applyFlag(final RevFilter matching, final RevFlag flag,+ int rangeBegin, int rangeEnd) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ final RevWalk w = flag.getRevWalk();+ rangeEnd = Math.min(rangeEnd, size());+ while (rangeBegin < rangeEnd) {+ int index = rangeBegin;+ Block s = contents;+ while (s.shift > 0) {+ final int i = index >> s.shift;+ index -= i << s.shift;+ s = (Block) s.contents[i];+ }++ while (rangeBegin++ < rangeEnd && index < BLOCK_SIZE) {+ final RevCommit c = (RevCommit) s.contents[index++];+ if (matching.include(w, c))+ c.add(flag);+ else+ c.remove(flag);+ }+ }+ }++ /**+ * Remove the given flag from all commits.+ * <p>+ * Same as <code>clearFlag(flag, 0, size())</code>, but without the+ * incremental behavior.+ *+ * @param flag+ * the flag to remove. Applications are responsible for+ * allocating this flag from the source RevWalk.+ */+ public void clearFlag(final RevFlag flag) {+ clearFlag(flag, 0, size());+ }++ /**+ * Remove the given flag from all commits.+ * <p>+ * This method is actually implemented in terms of:+ * <code>applyFlag(RevFilter.NONE, flag, rangeBegin, rangeEnd)</code>.+ *+ * @param flag+ * the flag to remove. Applications are responsible for+ * allocating this flag from the source RevWalk.+ * @param rangeBegin+ * first commit within the list to begin testing at, inclusive.+ * Must not be negative, but may be beyond the end of the list.+ * @param rangeEnd+ * last commit within the list to end testing at, exclusive. If+ * smaller than or equal to <code>rangeBegin</code> then no+ * commits will be tested.+ */+ public void clearFlag(final RevFlag flag, final int rangeBegin,+ final int rangeEnd) {+ try {+ applyFlag(RevFilter.NONE, flag, rangeBegin, rangeEnd);+ } catch (IOException e) {+ // Never happen. The filter we use does not throw any+ // exceptions, for any reason.+ }+ }++ /**+ * Find the next commit that has the given flag set.+ *+ * @param flag+ * the flag to test commits against.+ * @param begin+ * first commit index to test at. Applications may wish to begin+ * at 0, to test the first commit in the list.+ * @return index of the first commit at or after index <code>begin</code>+ * that has the specified flag set on it; -1 if no match is found.+ */+ public int indexOf(final RevFlag flag, int begin) {+ while (begin < size()) {+ int index = begin;+ Block s = contents;+ while (s.shift > 0) {+ final int i = index >> s.shift;+ index -= i << s.shift;+ s = (Block) s.contents[i];+ }++ while (begin++ < size() && index < BLOCK_SIZE) {+ final RevCommit c = (RevCommit) s.contents[index++];+ if (c.has(flag))+ return begin;+ }+ }+ return -1;+ }++ /**+ * Find the next commit that has the given flag set.+ *+ * @param flag+ * the flag to test commits against.+ * @param begin+ * first commit index to test at. Applications may wish to begin+ * at <code>size()-1</code>, to test the last commit in the+ * list.+ * @return index of the first commit at or before index <code>begin</code>+ * that has the specified flag set on it; -1 if no match is found.+ */+ public int lastIndexOf(final RevFlag flag, int begin) {+ begin = Math.min(begin, size() - 1);+ while (begin >= 0) {+ int index = begin;+ Block s = contents;+ while (s.shift > 0) {+ final int i = index >> s.shift;+ index -= i << s.shift;+ s = (Block) s.contents[i];+ }++ while (begin-- >= 0 && index >= 0) {+ final RevCommit c = (RevCommit) s.contents[index--];+ if (c.has(flag))+ return begin;+ }+ }+ return -1;+ }++ /**+ * Set the revision walker this list populates itself from.+ *+ * @param w+ * the walker to populate from.+ * @see #fillTo(int)+ */+ public void source(final RevWalk w) {+ walker = w;+ }++ /**+ * Is this list still pending more items?+ *+ * @return true if {@link #fillTo(int)} might be able to extend the list+ * size when called.+ */+ public boolean isPending() {+ return walker != null;+ }++ /**+ * Ensure this list contains at least a specified number of commits.+ * <p>+ * The revision walker specified by {@link #source(RevWalk)} is pumped until+ * the given number of commits are contained in this list. If there are+ * fewer total commits available from the walk then the method will return+ * early. Callers can test the final size of the list by {@link #size()} to+ * determine if the high water mark specified was met.+ *+ * @param highMark+ * number of commits the caller wants this list to contain when+ * the fill operation is complete.+ * @throws IOException+ * see {@link RevWalk#next()}+ * @throws IncorrectObjectTypeException+ * see {@link RevWalk#next()}+ * @throws MissingObjectException+ * see {@link RevWalk#next()}+ */+ @SuppressWarnings("unchecked")+ public void fillTo(final int highMark) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (walker == null || size > highMark)+ return;++ RevCommit c = walker.next();+ if (c == null) {+ walker = null;+ return;+ }+ enter(size, (E) c);+ add((E) c);++ while (size <= highMark) {+ int index = size;+ Block s = contents;+ while (index >> s.shift >= BLOCK_SIZE) {+ s = new Block(s.shift + BLOCK_SHIFT);+ s.contents[0] = contents;+ contents = s;+ }+ while (s.shift > 0) {+ final int i = index >> s.shift;+ index -= i << s.shift;+ if (s.contents[i] == null)+ s.contents[i] = new Block(s.shift - BLOCK_SHIFT);+ s = (Block) s.contents[i];+ }++ final Object[] dst = s.contents;+ while (size <= highMark && index < BLOCK_SIZE) {+ c = walker.next();+ if (c == null) {+ walker = null;+ return;+ }+ enter(size++, (E) c);+ dst[index++] = c;+ }+ }+ }++ /**+ * Ensures all commits until the given commit are loaded. The revision+ * walker specified by {@link #source(RevWalk)} is pumped until the+ * specified commit is loaded. Callers can test the final size of the list+ * by {@link #size()} to determine if the high water mark specified was met.+ * <p>+ *+ * @param commitToLoad+ * commit the caller wants this list to contain when the fill+ * operation is complete.+ * @param highMark+ * maximum number of commits the caller wants this list to+ * contain when the fill operation is complete. If highMark is 0+ * the walk is pumped until the specified commit or the end of+ * the walk is reached.+ * @throws IOException+ * see {@link RevWalk#next()}+ * @throws IncorrectObjectTypeException+ * see {@link RevWalk#next()}+ * @throws MissingObjectException+ * see {@link RevWalk#next()}+ */+ @SuppressWarnings("unchecked")+ public void fillTo(final RevCommit commitToLoad, int highMark)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ if (walker == null || commitToLoad == null+ || (highMark > 0 && size > highMark))+ return;++ RevCommit c = walker.next();+ if (c == null) {+ walker = null;+ return;+ }+ enter(size, (E) c);+ add((E) c);++ while ((highMark == 0 || size <= highMark) && !c.equals(commitToLoad)) {+ int index = size;+ Block s = contents;+ while (index >> s.shift >= BLOCK_SIZE) {+ s = new Block(s.shift + BLOCK_SHIFT);+ s.contents[0] = contents;+ contents = s;+ }+ while (s.shift > 0) {+ final int i = index >> s.shift;+ index -= i << s.shift;+ if (s.contents[i] == null)+ s.contents[i] = new Block(s.shift - BLOCK_SHIFT);+ s = (Block) s.contents[i];+ }++ final Object[] dst = s.contents;+ while ((highMark == 0 || size <= highMark) && index < BLOCK_SIZE+ && !c.equals(commitToLoad)) {+ c = walker.next();+ if (c == null) {+ walker = null;+ return;+ }+ enter(size++, (E) c);+ dst[index++] = c;+ }+ }+ }++ /**+ * Optional callback invoked when commits enter the list by fillTo.+ * <p>+ * This method is only called during {@link #fillTo(int)}.+ *+ * @param index+ * the list position this object will appear at.+ * @param e+ * the object being added (or set) into the list.+ */+ protected void enter(final int index, final E e) {+ // Do nothing by default.+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevFlag.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevFlag.javanew file mode 100644index 0000000000..0998a3a221--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevFlag.java@@ -0,0 +1,117 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.text.MessageFormat;++import org.eclipse.jgit.internal.JGitText;++/**+ * Application level mark bit for {@link RevObject}s.+ * <p>+ * To create a flag use {@link RevWalk#newFlag(String)}.+ */+public class RevFlag {+ /**+ * Uninteresting by {@link RevWalk#markUninteresting(RevCommit)}.+ * <p>+ * We flag commits as uninteresting if the caller does not want commits+ * reachable from a commit to {@link RevWalk#markUninteresting(RevCommit)}.+ * This flag is always carried into the commit's parents and is a key part+ * of the "rev-list B --not A" feature; A is marked UNINTERESTING.+ * <p>+ * This is a static flag. Its RevWalk is not available.+ */+ public static final RevFlag UNINTERESTING = new StaticRevFlag(+ "UNINTERESTING", RevWalk.UNINTERESTING); //$NON-NLS-1$++ /**+ * Set on RevCommit instances added to {@link RevWalk#pending} queue.+ * <p>+ * We use this flag to avoid adding the same commit instance twice to our+ * queue, especially if we reached it by more than one path.+ * <p>+ * This is a static flag. Its RevWalk is not available.+ *+ * @since 3.0+ */+ public static final RevFlag SEEN = new StaticRevFlag("SEEN", RevWalk.SEEN); //$NON-NLS-1$++ final RevWalk walker;++ final String name;++ final int mask;++ RevFlag(final RevWalk w, final String n, final int m) {+ walker = w;+ name = n;+ mask = m;+ }++ /**+ * Get the revision walk instance this flag was created from.+ *+ * @return the walker this flag was allocated out of, and belongs to.+ */+ public RevWalk getRevWalk() {+ return walker;+ }++ public String toString() {+ return name;+ }++ static class StaticRevFlag extends RevFlag {+ StaticRevFlag(final String n, final int m) {+ super(null, n, m);+ }++ @Override+ public RevWalk getRevWalk() {+ throw new UnsupportedOperationException(MessageFormat.format(+ JGitText.get().isAStaticFlagAndHasNorevWalkInstance, toString()));+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevFlagSet.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevFlagSet.javanew file mode 100644index 0000000000..ca30fd98d1--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevFlagSet.java@@ -0,0 +1,154 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.util.AbstractSet;+import java.util.ArrayList;+import java.util.Collection;+import java.util.Iterator;+import java.util.List;++/**+ * Multiple application level mark bits for {@link RevObject}s.+ *+ * @see RevFlag+ */+public class RevFlagSet extends AbstractSet<RevFlag> {+ int mask;++ private final List<RevFlag> active;++ /** Create an empty set of flags. */+ public RevFlagSet() {+ active = new ArrayList<RevFlag>();+ }++ /**+ * Create a set of flags, copied from an existing set.+ *+ * @param s+ * the set to copy flags from.+ */+ public RevFlagSet(final RevFlagSet s) {+ mask = s.mask;+ active = new ArrayList<RevFlag>(s.active);+ }++ /**+ * Create a set of flags, copied from an existing collection.+ *+ * @param s+ * the collection to copy flags from.+ */+ public RevFlagSet(final Collection<RevFlag> s) {+ this();+ addAll(s);+ }++ @Override+ public boolean contains(final Object o) {+ if (o instanceof RevFlag)+ return (mask & ((RevFlag) o).mask) != 0;+ return false;+ }++ @Override+ public boolean containsAll(final Collection<?> c) {+ if (c instanceof RevFlagSet) {+ final int cMask = ((RevFlagSet) c).mask;+ return (mask & cMask) == cMask;+ }+ return super.containsAll(c);+ }++ @Override+ public boolean add(final RevFlag flag) {+ if ((mask & flag.mask) != 0)+ return false;+ mask |= flag.mask;+ int p = 0;+ while (p < active.size() && active.get(p).mask < flag.mask)+ p++;+ active.add(p, flag);+ return true;+ }++ @Override+ public boolean remove(final Object o) {+ final RevFlag flag = (RevFlag) o;+ if ((mask & flag.mask) == 0)+ return false;+ mask &= ~flag.mask;+ for (int i = 0; i < active.size(); i++)+ if (active.get(i).mask == flag.mask)+ active.remove(i);+ return true;+ }++ @Override+ public Iterator<RevFlag> iterator() {+ final Iterator<RevFlag> i = active.iterator();+ return new Iterator<RevFlag>() {+ private RevFlag current;++ public boolean hasNext() {+ return i.hasNext();+ }++ public RevFlag next() {+ return current = i.next();+ }++ public void remove() {+ mask &= ~current.mask;+ i.remove();+ }+ };+ }++ @Override+ public int size() {+ return active.size();+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevObject.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevObject.javanew file mode 100644index 0000000000..7561927dff--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevObject.java@@ -0,0 +1,189 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.Constants;+import org.eclipse.jgit.lib.ObjectId;+import org.eclipse.jgit.lib.ObjectIdOwnerMap;++/** Base object type accessed during revision walking. */+public abstract class RevObject extends ObjectIdOwnerMap.Entry {+ static final int PARSED = 1;++ int flags;++ RevObject(final AnyObjectId name) {+ super(name);+ }++ abstract void parseHeaders(RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException;++ abstract void parseBody(RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException;++ /**+ * Get Git object type. See {@link Constants}.+ *+ * @return object type+ */+ public abstract int getType();++ /**+ * Get the name of this object.+ *+ * @return unique hash of this object.+ */+ public final ObjectId getId() {+ return this;+ }++ /**+ * Test to see if the flag has been set on this object.+ *+ * @param flag+ * the flag to test.+ * @return true if the flag has been added to this object; false if not.+ */+ public final boolean has(final RevFlag flag) {+ return (flags & flag.mask) != 0;+ }++ /**+ * Test to see if any flag in the set has been set on this object.+ *+ * @param set+ * the flags to test.+ * @return true if any flag in the set has been added to this object; false+ * if not.+ */+ public final boolean hasAny(final RevFlagSet set) {+ return (flags & set.mask) != 0;+ }++ /**+ * Test to see if all flags in the set have been set on this object.+ *+ * @param set+ * the flags to test.+ * @return true if all flags of the set have been added to this object;+ * false if some or none have been added.+ */+ public final boolean hasAll(final RevFlagSet set) {+ return (flags & set.mask) == set.mask;+ }++ /**+ * Add a flag to this object.+ * <p>+ * If the flag is already set on this object then the method has no effect.+ *+ * @param flag+ * the flag to mark on this object, for later testing.+ */+ public final void add(final RevFlag flag) {+ flags |= flag.mask;+ }++ /**+ * Add a set of flags to this object.+ *+ * @param set+ * the set of flags to mark on this object, for later testing.+ */+ public final void add(final RevFlagSet set) {+ flags |= set.mask;+ }++ /**+ * Remove a flag from this object.+ * <p>+ * If the flag is not set on this object then the method has no effect.+ *+ * @param flag+ * the flag to remove from this object.+ */+ public final void remove(final RevFlag flag) {+ flags &= ~flag.mask;+ }++ /**+ * Remove a set of flags from this object.+ *+ * @param set+ * the flag to remove from this object.+ */+ public final void remove(final RevFlagSet set) {+ flags &= ~set.mask;+ }++ @Override+ public String toString() {+ final StringBuilder s = new StringBuilder();+ s.append(Constants.typeString(getType()));+ s.append(' ');+ s.append(name());+ s.append(' ');+ appendCoreFlags(s);+ return s.toString();+ }++ /**+ * @param s+ * buffer to append a debug description of core RevFlags onto.+ */+ protected void appendCoreFlags(final StringBuilder s) {+ s.append((flags & RevWalk.TOPO_DELAY) != 0 ? 'o' : '-');+ s.append((flags & RevWalk.TEMP_MARK) != 0 ? 't' : '-');+ s.append((flags & RevWalk.REWRITE) != 0 ? 'r' : '-');+ s.append((flags & RevWalk.UNINTERESTING) != 0 ? 'u' : '-');+ s.append((flags & RevWalk.SEEN) != 0 ? 's' : '-');+ s.append((flags & RevWalk.PARSED) != 0 ? 'p' : '-');+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevObjectList.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevObjectList.javanew file mode 100644index 0000000000..5052a4dea5--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevObjectList.java@@ -0,0 +1,143 @@+/*+ * Copyright (C) 2009, Google Inc.+ * Copyright (C) 2009, Jonas Fonseca <[email protected]>+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.text.MessageFormat;+import java.util.AbstractList;++import org.eclipse.jgit.internal.JGitText;++/**+ * An ordered list of {@link RevObject} subclasses.+ *+ * @param <E>+ * type of subclass of RevObject the list is storing.+ */+public class RevObjectList<E extends RevObject> extends AbstractList<E> {+ static final int BLOCK_SHIFT = 8;++ static final int BLOCK_SIZE = 1 << BLOCK_SHIFT;++ /**+ * Items stored in this list.+ * <p>+ * If {@link Block#shift} = 0 this block holds the list elements; otherwise+ * it holds pointers to other {@link Block} instances which use a shift that+ * is {@link #BLOCK_SHIFT} smaller.+ */+ protected Block contents = new Block(0);++ /** Current number of elements in the list. */+ protected int size = 0;++ /** Create an empty object list. */+ public RevObjectList() {+ // Initialized above.+ }++ public void add(final int index, final E element) {+ if (index != size)+ throw new UnsupportedOperationException(MessageFormat.format(+ JGitText.get().unsupportedOperationNotAddAtEnd,+ Integer.valueOf(index)));+ set(index, element);+ size++;+ }++ @SuppressWarnings("unchecked")+ public E set(int index, E element) {+ Block s = contents;+ while (index >> s.shift >= BLOCK_SIZE) {+ s = new Block(s.shift + BLOCK_SHIFT);+ s.contents[0] = contents;+ contents = s;+ }+ while (s.shift > 0) {+ final int i = index >> s.shift;+ index -= i << s.shift;+ if (s.contents[i] == null)+ s.contents[i] = new Block(s.shift - BLOCK_SHIFT);+ s = (Block) s.contents[i];+ }+ final Object old = s.contents[index];+ s.contents[index] = element;+ return (E) old;+ }++ @SuppressWarnings("unchecked")+ public E get(int index) {+ Block s = contents;+ if (index >> s.shift >= 1024)+ return null;+ while (s != null && s.shift > 0) {+ final int i = index >> s.shift;+ index -= i << s.shift;+ s = (Block) s.contents[i];+ }+ return s != null ? (E) s.contents[index] : null;+ }++ public int size() {+ return size;+ }++ @Override+ public void clear() {+ contents = new Block(0);+ size = 0;+ }++ /** One level of contents, either an intermediate level or a leaf level. */+ protected static class Block {+ final Object[] contents = new Object[BLOCK_SIZE];++ final int shift;++ Block(final int s) {+ shift = s;+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevSort.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevSort.javanew file mode 100644index 0000000000..238af12fdb--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevSort.java@@ -0,0 +1,90 @@+/*+ * Copyright (C) 2008, Marek Zawirski <[email protected]>+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++/** Sorting strategies supported by {@link RevWalk} and {@link ObjectWalk}. */+public enum RevSort {+ /**+ * No specific sorting is requested.+ * <p>+ * Applications should not rely upon the ordering produced by this strategy.+ * Any ordering in the output is caused by low level implementation details+ * and may change without notice.+ */+ NONE,++ /**+ * Sort by commit time, descending (newest first, oldest last).+ * <p>+ * This strategy can be combined with {@link #TOPO}.+ */+ COMMIT_TIME_DESC,++ /**+ * Topological sorting (all children before parents).+ * <p>+ * This strategy can be combined with {@link #COMMIT_TIME_DESC}.+ */+ TOPO,++ /**+ * Flip the output into the reverse ordering.+ * <p>+ * This strategy can be combined with the others described by this type as+ * it is usually performed at the very end.+ */+ REVERSE,++ /**+ * Include {@link RevFlag#UNINTERESTING} boundary commits after all others.+ * In {@link ObjectWalk}, objects associated with such commits (trees,+ * blobs), and all other objects marked explicitly as UNINTERESTING are also+ * included.+ * <p>+ * A boundary commit is a UNINTERESTING parent of an interesting commit that+ * was previously output.+ */+ BOUNDARY;+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevTag.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevTag.javanew file mode 100644index 0000000000..1a59b440c3--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevTag.java@@ -0,0 +1,271 @@+/*+ * Copyright (C) 2008-2009, Google Inc.+ * Copyright (C) 2008, Marek Zawirski <[email protected]>+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;+import java.nio.charset.Charset;++import org.eclipse.jgit.errors.CorruptObjectException;+import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.Constants;+import org.eclipse.jgit.lib.ObjectInserter;+import org.eclipse.jgit.lib.ObjectReader;+import org.eclipse.jgit.lib.PersonIdent;+import org.eclipse.jgit.util.MutableInteger;+import org.eclipse.jgit.util.RawParseUtils;+import org.eclipse.jgit.util.StringUtils;++/** An annotated tag. */+public class RevTag extends RevObject {+ /**+ * Parse an annotated tag from its canonical format.+ *+ * This method constructs a temporary revision pool, parses the tag as+ * supplied, and returns it to the caller. Since the tag was built inside of+ * a private revision pool its object pointer will be initialized, but will+ * not have its headers loaded.+ *+ * Applications are discouraged from using this API. Callers usually need+ * more than one object. Use {@link RevWalk#parseTag(AnyObjectId)} to obtain+ * a RevTag from an existing repository.+ *+ * @param raw+ * the canonical formatted tag to be parsed.+ * @return the parsed tag, in an isolated revision pool that is not+ * available to the caller.+ * @throws CorruptObjectException+ * the tag contains a malformed header that cannot be handled.+ */+ public static RevTag parse(byte[] raw) throws CorruptObjectException {+ return parse(new RevWalk((ObjectReader) null), raw);+ }++ /**+ * Parse an annotated tag from its canonical format.+ *+ * This method inserts the tag directly into the caller supplied revision+ * pool, making it appear as though the tag exists in the repository, even+ * if it doesn't. The repository under the pool is not affected.+ *+ * @param rw+ * the revision pool to allocate the tag within. The tag's object+ * pointer will be obtained from this pool.+ * @param raw+ * the canonical formatted tag to be parsed.+ * @return the parsed tag, in an isolated revision pool that is not+ * available to the caller.+ * @throws CorruptObjectException+ * the tag contains a malformed header that cannot be handled.+ */+ public static RevTag parse(RevWalk rw, byte[] raw)+ throws CorruptObjectException {+ ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();+ boolean retain = rw.isRetainBody();+ rw.setRetainBody(true);+ RevTag r = rw.lookupTag(fmt.idFor(Constants.OBJ_TAG, raw));+ r.parseCanonical(rw, raw);+ rw.setRetainBody(retain);+ return r;+ }++ private RevObject object;++ private byte[] buffer;++ private String tagName;++ /**+ * Create a new tag reference.+ *+ * @param id+ * object name for the tag.+ */+ protected RevTag(final AnyObjectId id) {+ super(id);+ }++ @Override+ void parseHeaders(final RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ parseCanonical(walk, walk.getCachedBytes(this));+ }++ @Override+ void parseBody(final RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (buffer == null) {+ buffer = walk.getCachedBytes(this);+ if ((flags & PARSED) == 0)+ parseCanonical(walk, buffer);+ }+ }++ void parseCanonical(final RevWalk walk, final byte[] rawTag)+ throws CorruptObjectException {+ final MutableInteger pos = new MutableInteger();+ final int oType;++ pos.value = 53; // "object $sha1\ntype "+ oType = Constants.decodeTypeString(this, rawTag, (byte) '\n', pos);+ walk.idBuffer.fromString(rawTag, 7);+ object = walk.lookupAny(walk.idBuffer, oType);++ int p = pos.value += 4; // "tag "+ final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1;+ tagName = RawParseUtils.decode(Constants.CHARSET, rawTag, p, nameEnd);++ if (walk.isRetainBody())+ buffer = rawTag;+ flags |= PARSED;+ }++ @Override+ public final int getType() {+ return Constants.OBJ_TAG;+ }++ /**+ * Parse the tagger identity from the raw buffer.+ * <p>+ * This method parses and returns the content of the tagger line, after+ * taking the tag's character set into account and decoding the tagger+ * name and email address. This method is fairly expensive and produces a+ * new PersonIdent instance on each invocation. Callers should invoke this+ * method only if they are certain they will be outputting the result, and+ * should cache the return value for as long as necessary to use all+ * information from it.+ *+ * @return identity of the tagger (name, email) and the time the tag+ * was made by the tagger; null if no tagger line was found.+ */+ public final PersonIdent getTaggerIdent() {+ final byte[] raw = buffer;+ final int nameB = RawParseUtils.tagger(raw, 0);+ if (nameB < 0)+ return null;+ return RawParseUtils.parsePersonIdent(raw, nameB);+ }++ /**+ * Parse the complete tag message and decode it to a string.+ * <p>+ * This method parses and returns the message portion of the tag buffer,+ * after taking the tag's character set into account and decoding the buffer+ * using that character set. This method is a fairly expensive operation and+ * produces a new string on each invocation.+ *+ * @return decoded tag message as a string. Never null.+ */+ public final String getFullMessage() {+ final byte[] raw = buffer;+ final int msgB = RawParseUtils.tagMessage(raw, 0);+ if (msgB < 0)+ return ""; //$NON-NLS-1$+ final Charset enc = RawParseUtils.parseEncoding(raw);+ return RawParseUtils.decode(enc, raw, msgB, raw.length);+ }++ /**+ * Parse the tag message and return the first "line" of it.+ * <p>+ * The first line is everything up to the first pair of LFs. This is the+ * "oneline" format, suitable for output in a single line display.+ * <p>+ * This method parses and returns the message portion of the tag buffer,+ * after taking the tag's character set into account and decoding the buffer+ * using that character set. This method is a fairly expensive operation and+ * produces a new string on each invocation.+ *+ * @return decoded tag message as a string. Never null. The returned string+ * does not contain any LFs, even if the first paragraph spanned+ * multiple lines. Embedded LFs are converted to spaces.+ */+ public final String getShortMessage() {+ final byte[] raw = buffer;+ final int msgB = RawParseUtils.tagMessage(raw, 0);+ if (msgB < 0)+ return ""; //$NON-NLS-1$++ final Charset enc = RawParseUtils.parseEncoding(raw);+ final int msgE = RawParseUtils.endOfParagraph(raw, msgB);+ String str = RawParseUtils.decode(enc, raw, msgB, msgE);+ if (RevCommit.hasLF(raw, msgB, msgE))+ str = StringUtils.replaceLineBreaksWithSpace(str);+ return str;+ }++ /**+ * Get a reference to the object this tag was placed on.+ * <p>+ * Note that the returned object has only been looked up (see+ * {@link RevWalk#lookupAny(AnyObjectId, int)}. To access the contents it+ * needs to be parsed, see {@link RevWalk#parseHeaders(RevObject)} and+ * {@link RevWalk#parseBody(RevObject)}.+ * <p>+ * As an alternative, use {@link RevWalk#peel(RevObject)} and pass this+ * {@link RevTag} to peel it until the first non-tag object.+ *+ * @return object this tag refers to (only looked up, not parsed)+ */+ public final RevObject getObject() {+ return object;+ }++ /**+ * Get the name of this tag, from the tag header.+ *+ * @return name of the tag, according to the tag header.+ */+ public final String getTagName() {+ return tagName;+ }++ final void disposeBody() {+ buffer = null;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevTree.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevTree.javanew file mode 100644index 0000000000..d37040903e--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevTree.java@@ -0,0 +1,87 @@+/*+ * Copyright (C) 2009, Google Inc.+ * Copyright (C) 2008, Marek Zawirski <[email protected]>+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.Constants;++/** A reference to a tree of subtrees/files. */+public class RevTree extends RevObject {+ /**+ * Create a new tree reference.+ *+ * @param id+ * object name for the tree.+ */+ protected RevTree(final AnyObjectId id) {+ super(id);+ }++ @Override+ public final int getType() {+ return Constants.OBJ_TREE;+ }++ @Override+ void parseHeaders(RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (walk.reader.has(this))+ flags |= PARSED;+ else+ throw new MissingObjectException(this, getType());+ }++ @Override+ void parseBody(RevWalk walk) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if ((flags & PARSED) == 0)+ parseHeaders(walk);+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevWalk.javanew file mode 100644index 0000000000..d19e467c1d--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java@@ -0,0 +1,1414 @@+/*+ * Copyright (C) 2007, Robin Rosenberg <[email protected]>+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * Copyright (C) 2014, Gustaf Lundh <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;+import java.text.MessageFormat;+import java.util.ArrayList;+import java.util.Collection;+import java.util.EnumSet;+import java.util.Iterator;+import java.util.List;++import org.eclipse.jgit.errors.CorruptObjectException;+import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.LargeObjectException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.errors.RevWalkException;+import org.eclipse.jgit.internal.JGitText;+import org.eclipse.jgit.lib.AnyObjectId;+import org.eclipse.jgit.lib.AsyncObjectLoaderQueue;+import org.eclipse.jgit.lib.Constants;+import org.eclipse.jgit.lib.MutableObjectId;+import org.eclipse.jgit.lib.ObjectId;+import org.eclipse.jgit.lib.ObjectIdOwnerMap;+import org.eclipse.jgit.lib.ObjectLoader;+import org.eclipse.jgit.lib.ObjectReader;+import org.eclipse.jgit.lib.Repository;+import org.eclipse.jgit.revwalk.filter.RevFilter;+import org.eclipse.jgit.treewalk.filter.TreeFilter;++/**+ * Walks a commit graph and produces the matching commits in order.+ * <p>+ * A RevWalk instance can only be used once to generate results. Running a+ * second time requires creating a new RevWalk instance, or invoking+ * {@link #reset()} before starting again. Resetting an existing instance may be+ * faster for some applications as commit body parsing can be avoided on the+ * later invocations.+ * <p>+ * RevWalk instances are not thread-safe. Applications must either restrict+ * usage of a RevWalk instance to a single thread, or implement their own+ * synchronization at a higher level.+ * <p>+ * Multiple simultaneous RevWalk instances per {@link Repository} are permitted,+ * even from concurrent threads. Equality of {@link RevCommit}s from two+ * different RevWalk instances is never true, even if their {@link ObjectId}s+ * are equal (and thus they describe the same commit).+ * <p>+ * The offered iterator is over the list of RevCommits described by the+ * configuration of this instance. Applications should restrict themselves to+ * using either the provided Iterator or {@link #next()}, but never use both on+ * the same RevWalk at the same time. The Iterator may buffer RevCommits, while+ * {@link #next()} does not.+ */+public class RevWalk implements Iterable<RevCommit> {+ private static final int MB = 1 << 20;++ /**+ * Set on objects whose important header data has been loaded.+ * <p>+ * For a RevCommit this indicates we have pulled apart the tree and parent+ * references from the raw bytes available in the repository and translated+ * those to our own local RevTree and RevCommit instances. The raw buffer is+ * also available for message and other header filtering.+ * <p>+ * For a RevTag this indicates we have pulled part the tag references to+ * find out who the tag refers to, and what that object's type is.+ */+ static final int PARSED = 1 << 0;++ /**+ * Set on RevCommit instances added to our {@link #pending} queue.+ * <p>+ * We use this flag to avoid adding the same commit instance twice to our+ * queue, especially if we reached it by more than one path.+ */+ static final int SEEN = 1 << 1;++ /**+ * Set on RevCommit instances the caller does not want output.+ * <p>+ * We flag commits as uninteresting if the caller does not want commits+ * reachable from a commit given to {@link #markUninteresting(RevCommit)}.+ * This flag is always carried into the commit's parents and is a key part+ * of the "rev-list B --not A" feature; A is marked UNINTERESTING.+ */+ static final int UNINTERESTING = 1 << 2;++ /**+ * Set on a RevCommit that can collapse out of the history.+ * <p>+ * If the {@link #treeFilter} concluded that this commit matches his+ * parents' for all of the paths that the filter is interested in then we+ * mark the commit REWRITE. Later we can rewrite the parents of a REWRITE+ * child to remove chains of REWRITE commits before we produce the child to+ * the application.+ *+ * @see RewriteGenerator+ */+ static final int REWRITE = 1 << 3;++ /**+ * Temporary mark for use within generators or filters.+ * <p>+ * This mark is only for local use within a single scope. If someone sets+ * the mark they must unset it before any other code can see the mark.+ */+ static final int TEMP_MARK = 1 << 4;++ /**+ * Temporary mark for use within {@link TopoSortGenerator}.+ * <p>+ * This mark indicates the commit could not produce when it wanted to, as at+ * least one child was behind it. Commits with this flag are delayed until+ * all children have been output first.+ */+ static final int TOPO_DELAY = 1 << 5;++ /** Number of flag bits we keep internal for our own use. See above flags. */+ static final int RESERVED_FLAGS = 6;++ private static final int APP_FLAGS = -1 & ~((1 << RESERVED_FLAGS) - 1);++ final ObjectReader reader;++ final MutableObjectId idBuffer;++ ObjectIdOwnerMap<RevObject> objects;++ private int freeFlags = APP_FLAGS;++ private int delayFreeFlags;++ private int retainOnReset;+ int carryFlags = UNINTERESTING;++ final ArrayList<RevCommit> roots;++ AbstractRevQueue queue;++ Generator pending;++ private final EnumSet<RevSort> sorting;++ private RevFilter filter;++ private TreeFilter treeFilter;++ private boolean retainBody;++ private boolean rewriteParents = true;++ boolean shallowCommitsInitialized;++ /**+ * Create a new revision walker for a given repository.+ *+ * @param repo+ * the repository the walker will obtain data from. An+ * ObjectReader will be created by the walker, and must be+ * released by the caller.+ */+ public RevWalk(final Repository repo) {+ this(repo.newObjectReader());+ }++ /**+ * Create a new revision walker for a given repository.+ *+ * @param or+ * the reader the walker will obtain data from. The reader should+ * be released by the caller when the walker is no longer+ * required.+ */+ public RevWalk(ObjectReader or) {+ reader = or;+ idBuffer = new MutableObjectId();+ objects = new ObjectIdOwnerMap<RevObject>();+ roots = new ArrayList<RevCommit>();+ queue = new DateRevQueue();+ pending = new StartGenerator(this);+ sorting = EnumSet.of(RevSort.NONE);+ filter = RevFilter.ALL;+ treeFilter = TreeFilter.ALL;+ retainBody = true;+ }++ /** @return the reader this walker is using to load objects. */+ public ObjectReader getObjectReader() {+ return reader;+ }++ /**+ * Release any resources used by this walker's reader.+ * <p>+ * A walker that has been released can be used again, but may need to be+ * released after the subsequent usage.+ */+ public void release() {+ reader.release();+ }++ /**+ * Mark a commit to start graph traversal from.+ * <p>+ * Callers are encouraged to use {@link #parseCommit(AnyObjectId)} to obtain+ * the commit reference, rather than {@link #lookupCommit(AnyObjectId)}, as+ * this method requires the commit to be parsed before it can be added as a+ * root for the traversal.+ * <p>+ * The method will automatically parse an unparsed commit, but error+ * handling may be more difficult for the application to explain why a+ * RevCommit is not actually a commit. The object pool of this walker would+ * also be 'poisoned' by the non-commit RevCommit.+ *+ * @param c+ * the commit to start traversing from. The commit passed must be+ * from this same revision walker.+ * @throws MissingObjectException+ * the commit supplied is not available from the object+ * database. This usually indicates the supplied commit is+ * invalid, but the reference was constructed during an earlier+ * invocation to {@link #lookupCommit(AnyObjectId)}.+ * @throws IncorrectObjectTypeException+ * the object was not parsed yet and it was discovered during+ * parsing that it is not actually a commit. This usually+ * indicates the caller supplied a non-commit SHA-1 to+ * {@link #lookupCommit(AnyObjectId)}.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public void markStart(final RevCommit c) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if ((c.flags & SEEN) != 0)+ return;+ if ((c.flags & PARSED) == 0)+ c.parseHeaders(this);+ c.flags |= SEEN;+ roots.add(c);+ queue.add(c);+ }++ /**+ * Mark commits to start graph traversal from.+ *+ * @param list+ * commits to start traversing from. The commits passed must be+ * from this same revision walker.+ * @throws MissingObjectException+ * one of the commits supplied is not available from the object+ * database. This usually indicates the supplied commit is+ * invalid, but the reference was constructed during an earlier+ * invocation to {@link #lookupCommit(AnyObjectId)}.+ * @throws IncorrectObjectTypeException+ * the object was not parsed yet and it was discovered during+ * parsing that it is not actually a commit. This usually+ * indicates the caller supplied a non-commit SHA-1 to+ * {@link #lookupCommit(AnyObjectId)}.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public void markStart(final Collection<RevCommit> list)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ for (final RevCommit c : list)+ markStart(c);+ }++ /**+ * Mark a commit to not produce in the output.+ * <p>+ * Uninteresting commits denote not just themselves but also their entire+ * ancestry chain, back until the merge base of an uninteresting commit and+ * an otherwise interesting commit.+ * <p>+ * Callers are encouraged to use {@link #parseCommit(AnyObjectId)} to obtain+ * the commit reference, rather than {@link #lookupCommit(AnyObjectId)}, as+ * this method requires the commit to be parsed before it can be added as a+ * root for the traversal.+ * <p>+ * The method will automatically parse an unparsed commit, but error+ * handling may be more difficult for the application to explain why a+ * RevCommit is not actually a commit. The object pool of this walker would+ * also be 'poisoned' by the non-commit RevCommit.+ *+ * @param c+ * the commit to start traversing from. The commit passed must be+ * from this same revision walker.+ * @throws MissingObjectException+ * the commit supplied is not available from the object+ * database. This usually indicates the supplied commit is+ * invalid, but the reference was constructed during an earlier+ * invocation to {@link #lookupCommit(AnyObjectId)}.+ * @throws IncorrectObjectTypeException+ * the object was not parsed yet and it was discovered during+ * parsing that it is not actually a commit. This usually+ * indicates the caller supplied a non-commit SHA-1 to+ * {@link #lookupCommit(AnyObjectId)}.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public void markUninteresting(final RevCommit c)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ c.flags |= UNINTERESTING;+ carryFlagsImpl(c);+ markStart(c);+ }++ /**+ * 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+ * <code>base</code>.+ * <p>+ * This utility function resets the walker, inserts the two supplied+ * commits, and then executes a walk until an answer can be obtained.+ * Currently allocated RevFlags that have been added to RevCommit instances+ * will be retained through the reset.+ *+ * @param base+ * commit the caller thinks is reachable from <code>tip</code>.+ * @param tip+ * commit to start iteration from, and which is most likely a+ * descendant (child) of <code>base</code>.+ * @return true if there is a path directly from <code>tip</code> to+ * <code>base</code> (and thus <code>base</code> is fully merged+ * into <code>tip</code>); false otherwise.+ * @throws MissingObjectException+ * one or or more of the next commit's parents are not available+ * from the object database, but were thought to be candidates+ * for traversal. This usually indicates a broken link.+ * @throws IncorrectObjectTypeException+ * one or or more of the next commit's parents are not actually+ * commit objects.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public boolean isMergedInto(final RevCommit base, final RevCommit tip)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ final RevFilter oldRF = filter;+ final TreeFilter oldTF = treeFilter;+ try {+ finishDelayedFreeFlags();+ reset(~freeFlags & APP_FLAGS);+ filter = RevFilter.MERGE_BASE;+ treeFilter = TreeFilter.ALL;+ markStart(tip);+ markStart(base);+ RevCommit mergeBase;+ while ((mergeBase = next()) != null)+ if (mergeBase == base)+ return true;+ return false;+ } finally {+ filter = oldRF;+ treeFilter = oldTF;+ }+ }++ /**+ * Pop the next most recent commit.+ *+ * @return next most recent commit; null if traversal is over.+ * @throws MissingObjectException+ * one or or more of the next commit's parents are not available+ * from the object database, but were thought to be candidates+ * for traversal. This usually indicates a broken link.+ * @throws IncorrectObjectTypeException+ * one or or more of the next commit's parents are not actually+ * commit objects.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ return pending.next();+ }++ /**+ * Obtain the sort types applied to the commits returned.+ *+ * @return the sorting strategies employed. At least one strategy is always+ * used, but that strategy may be {@link RevSort#NONE}.+ */+ public EnumSet<RevSort> getRevSort() {+ return sorting.clone();+ }++ /**+ * Check whether the provided sorting strategy is enabled.+ *+ * @param sort+ * a sorting strategy to look for.+ * @return true if this strategy is enabled, false otherwise+ */+ public boolean hasRevSort(RevSort sort) {+ return sorting.contains(sort);+ }++ /**+ * Select a single sorting strategy for the returned commits.+ * <p>+ * Disables all sorting strategies, then enables only the single strategy+ * supplied by the caller.+ *+ * @param s+ * a sorting strategy to enable.+ */+ public void sort(final RevSort s) {+ assertNotStarted();+ sorting.clear();+ sorting.add(s);+ }++ /**+ * Add or remove a sorting strategy for the returned commits.+ * <p>+ * Multiple strategies can be applied at once, in which case some strategies+ * may take precedence over others. As an example, {@link RevSort#TOPO} must+ * take precedence over {@link RevSort#COMMIT_TIME_DESC}, otherwise it+ * cannot enforce its ordering.+ *+ * @param s+ * a sorting strategy to enable or disable.+ * @param use+ * true if this strategy should be used, false if it should be+ * removed.+ */+ public void sort(final RevSort s, final boolean use) {+ assertNotStarted();+ if (use)+ sorting.add(s);+ else+ sorting.remove(s);++ if (sorting.size() > 1)+ sorting.remove(RevSort.NONE);+ else if (sorting.size() == 0)+ sorting.add(RevSort.NONE);+ }++ /**+ * Get the currently configured commit filter.+ *+ * @return the current filter. Never null as a filter is always needed.+ */+ public RevFilter getRevFilter() {+ return filter;+ }++ /**+ * Set the commit filter for this walker.+ * <p>+ * Multiple filters may be combined by constructing an arbitrary tree of+ * <code>AndRevFilter</code> or <code>OrRevFilter</code> instances to+ * describe the boolean expression required by the application. Custom+ * filter implementations may also be constructed by applications.+ * <p>+ * Note that filters are not thread-safe and may not be shared by concurrent+ * RevWalk instances. Every RevWalk must be supplied its own unique filter,+ * unless the filter implementation specifically states it is (and always+ * will be) thread-safe. Callers may use {@link RevFilter#clone()} to create+ * a unique filter tree for this RevWalk instance.+ *+ * @param newFilter+ * the new filter. If null the special {@link RevFilter#ALL}+ * filter will be used instead, as it matches every commit.+ * @see org.eclipse.jgit.revwalk.filter.AndRevFilter+ * @see org.eclipse.jgit.revwalk.filter.OrRevFilter+ */+ public void setRevFilter(final RevFilter newFilter) {+ assertNotStarted();+ filter = newFilter != null ? newFilter : RevFilter.ALL;+ }++ /**+ * Get the tree filter used to simplify commits by modified paths.+ *+ * @return the current filter. Never null as a filter is always needed. If+ * no filter is being applied {@link TreeFilter#ALL} is returned.+ */+ public TreeFilter getTreeFilter() {+ return treeFilter;+ }++ /**+ * Set the tree filter used to simplify commits by modified paths.+ * <p>+ * If null or {@link TreeFilter#ALL} the path limiter is removed. Commits+ * will not be simplified.+ * <p>+ * If non-null and not {@link TreeFilter#ALL} then the tree filter will be+ * installed. Commits will have their ancestry simplified to hide commits that+ * do not contain tree entries matched by the filter, unless+ * {@code setRewriteParents(false)} is called.+ * <p>+ * Usually callers should be inserting a filter graph including+ * {@link TreeFilter#ANY_DIFF} along with one or more+ * {@link org.eclipse.jgit.treewalk.filter.PathFilter} instances.+ *+ * @param newFilter+ * new filter. If null the special {@link TreeFilter#ALL} filter+ * will be used instead, as it matches everything.+ * @see org.eclipse.jgit.treewalk.filter.PathFilter+ */+ public void setTreeFilter(final TreeFilter newFilter) {+ assertNotStarted();+ treeFilter = newFilter != null ? newFilter : TreeFilter.ALL;+ }++ /**+ * Set whether to rewrite parent pointers when filtering by modified paths.+ * <p>+ * By default, when {@link #setTreeFilter(TreeFilter)} is called with non-+ * null and non-{@link TreeFilter#ALL} filter, commits will have their+ * ancestry simplified and parents rewritten to hide commits that do not match+ * the filter.+ * <p>+ * This behavior can be bypassed by passing false to this method.+ *+ * @param rewrite+ * whether to rewrite parents; defaults to true.+ * @since 3.4+ */+ public void setRewriteParents(boolean rewrite) {+ rewriteParents = rewrite;+ }++ boolean getRewriteParents() {+ return rewriteParents;+ }++ /**+ * Should the body of a commit or tag be retained after parsing its headers?+ * <p>+ * Usually the body is always retained, but some application code might not+ * care and would prefer to discard the body of a commit as early as+ * possible, to reduce memory usage.+ *+ * @return true if the body should be retained; false it is discarded.+ */+ public boolean isRetainBody() {+ return retainBody;+ }++ /**+ * Set whether or not the body of a commit or tag is retained.+ * <p>+ * If a body of a commit or tag is not retained, the application must+ * call {@link #parseBody(RevObject)} before the body can be safely+ * accessed through the type specific access methods.+ *+ * @param retain true to retain bodies; false to discard them early.+ */+ public void setRetainBody(final boolean retain) {+ retainBody = retain;+ }++ /**+ * Locate a reference to a blob without loading it.+ * <p>+ * The blob may or may not exist in the repository. It is impossible to tell+ * from this method's return value.+ *+ * @param id+ * name of the blob object.+ * @return reference to the blob object. Never null.+ */+ public RevBlob lookupBlob(final AnyObjectId id) {+ RevBlob c = (RevBlob) objects.get(id);+ if (c == null) {+ c = new RevBlob(id);+ objects.add(c);+ }+ return c;+ }++ /**+ * Locate a reference to a tree without loading it.+ * <p>+ * The tree may or may not exist in the repository. It is impossible to tell+ * from this method's return value.+ *+ * @param id+ * name of the tree object.+ * @return reference to the tree object. Never null.+ */+ public RevTree lookupTree(final AnyObjectId id) {+ RevTree c = (RevTree) objects.get(id);+ if (c == null) {+ c = new RevTree(id);+ objects.add(c);+ }+ return c;+ }++ /**+ * Locate a reference to a commit without loading it.+ * <p>+ * The commit may or may not exist in the repository. It is impossible to+ * tell from this method's return value.+ * <p>+ * See {@link #parseHeaders(RevObject)} and {@link #parseBody(RevObject)}+ * for loading contents.+ *+ * @param id+ * name of the commit object.+ * @return reference to the commit object. Never null.+ */+ public RevCommit lookupCommit(final AnyObjectId id) {+ RevCommit c = (RevCommit) objects.get(id);+ if (c == null) {+ c = createCommit(id);+ objects.add(c);+ }+ return c;+ }++ /**+ * Locate a reference to a tag without loading it.+ * <p>+ * The tag may or may not exist in the repository. It is impossible to tell+ * from this method's return value.+ *+ * @param id+ * name of the tag object.+ * @return reference to the tag object. Never null.+ */+ public RevTag lookupTag(final AnyObjectId id) {+ RevTag c = (RevTag) objects.get(id);+ if (c == null) {+ c = new RevTag(id);+ objects.add(c);+ }+ return c;+ }++ /**+ * Locate a reference to any object without loading it.+ * <p>+ * The object may or may not exist in the repository. It is impossible to+ * tell from this method's return value.+ *+ * @param id+ * name of the object.+ * @param type+ * type of the object. Must be a valid Git object type.+ * @return reference to the object. Never null.+ */+ public RevObject lookupAny(final AnyObjectId id, final int type) {+ RevObject r = objects.get(id);+ if (r == null) {+ switch (type) {+ case Constants.OBJ_COMMIT:+ r = createCommit(id);+ break;+ case Constants.OBJ_TREE:+ r = new RevTree(id);+ break;+ case Constants.OBJ_BLOB:+ r = new RevBlob(id);+ break;+ case Constants.OBJ_TAG:+ r = new RevTag(id);+ break;+ default:+ throw new IllegalArgumentException(MessageFormat.format(+ JGitText.get().invalidGitType, Integer.valueOf(type)));+ }+ objects.add(r);+ }+ return r;+ }++ /**+ * Locate an object that was previously allocated in this walk.+ *+ * @param id+ * name of the object.+ * @return reference to the object if it has been previously located;+ * otherwise null.+ */+ public RevObject lookupOrNull(AnyObjectId id) {+ return objects.get(id);+ }++ /**+ * Locate a reference to a commit and immediately parse its content.+ * <p>+ * Unlike {@link #lookupCommit(AnyObjectId)} this method only returns+ * successfully if the commit object exists, is verified to be a commit, and+ * was parsed without error.+ *+ * @param id+ * name of the commit object.+ * @return reference to the commit object. Never null.+ * @throws MissingObjectException+ * the supplied commit does not exist.+ * @throws IncorrectObjectTypeException+ * the supplied id is not a commit or an annotated tag.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public RevCommit parseCommit(final AnyObjectId id)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ RevObject c = peel(parseAny(id));+ if (!(c instanceof RevCommit))+ throw new IncorrectObjectTypeException(id.toObjectId(),+ Constants.TYPE_COMMIT);+ return (RevCommit) c;+ }++ /**+ * Locate a reference to a tree.+ * <p>+ * This method only returns successfully if the tree object exists, is+ * verified to be a tree.+ *+ * @param id+ * name of the tree object, or a commit or annotated tag that may+ * reference a tree.+ * @return reference to the tree object. Never null.+ * @throws MissingObjectException+ * the supplied tree does not exist.+ * @throws IncorrectObjectTypeException+ * the supplied id is not a tree, a commit or an annotated tag.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public RevTree parseTree(final AnyObjectId id)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ RevObject c = peel(parseAny(id));++ final RevTree t;+ if (c instanceof RevCommit)+ t = ((RevCommit) c).getTree();+ else if (!(c instanceof RevTree))+ throw new IncorrectObjectTypeException(id.toObjectId(),+ Constants.TYPE_TREE);+ else+ t = (RevTree) c;+ parseHeaders(t);+ return t;+ }++ /**+ * Locate a reference to an annotated tag and immediately parse its content.+ * <p>+ * Unlike {@link #lookupTag(AnyObjectId)} this method only returns+ * successfully if the tag object exists, is verified to be a tag, and was+ * parsed without error.+ *+ * @param id+ * name of the tag object.+ * @return reference to the tag object. Never null.+ * @throws MissingObjectException+ * the supplied tag does not exist.+ * @throws IncorrectObjectTypeException+ * the supplied id is not a tag or an annotated tag.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public RevTag parseTag(final AnyObjectId id) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ RevObject c = parseAny(id);+ if (!(c instanceof RevTag))+ throw new IncorrectObjectTypeException(id.toObjectId(),+ Constants.TYPE_TAG);+ return (RevTag) c;+ }++ /**+ * Locate a reference to any object and immediately parse its headers.+ * <p>+ * This method only returns successfully if the object exists and was parsed+ * without error. Parsing an object can be expensive as the type must be+ * determined. For blobs this may mean the blob content was unpacked+ * unnecessarily, and thrown away.+ *+ * @param id+ * name of the object.+ * @return reference to the object. Never null.+ * @throws MissingObjectException+ * the supplied does not exist.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public RevObject parseAny(final AnyObjectId id)+ throws MissingObjectException, IOException {+ RevObject r = objects.get(id);+ if (r == null)+ r = parseNew(id, reader.open(id));+ else+ parseHeaders(r);+ return r;+ }++ private RevObject parseNew(AnyObjectId id, ObjectLoader ldr)+ throws LargeObjectException, CorruptObjectException,+ MissingObjectException, IOException {+ RevObject r;+ int type = ldr.getType();+ switch (type) {+ case Constants.OBJ_COMMIT: {+ final RevCommit c = createCommit(id);+ c.parseCanonical(this, getCachedBytes(c, ldr));+ r = c;+ break;+ }+ case Constants.OBJ_TREE: {+ r = new RevTree(id);+ r.flags |= PARSED;+ break;+ }+ case Constants.OBJ_BLOB: {+ r = new RevBlob(id);+ r.flags |= PARSED;+ break;+ }+ case Constants.OBJ_TAG: {+ final RevTag t = new RevTag(id);+ t.parseCanonical(this, getCachedBytes(t, ldr));+ r = t;+ break;+ }+ default:+ throw new IllegalArgumentException(MessageFormat.format(+ JGitText.get().badObjectType, Integer.valueOf(type)));+ }+ objects.add(r);+ return r;+ }++ byte[] getCachedBytes(RevObject obj) throws LargeObjectException,+ MissingObjectException, IncorrectObjectTypeException, IOException {+ return getCachedBytes(obj, reader.open(obj, obj.getType()));+ }++ byte[] getCachedBytes(RevObject obj, ObjectLoader ldr)+ throws LargeObjectException, MissingObjectException, IOException {+ try {+ return ldr.getCachedBytes(5 * MB);+ } catch (LargeObjectException tooBig) {+ tooBig.setObjectId(obj);+ throw tooBig;+ }+ }++ /**+ * Asynchronous object parsing.+ *+ * @param <T>+ * any ObjectId type.+ * @param objectIds+ * objects to open from the object store. The supplied collection+ * must not be modified until the queue has finished.+ * @param reportMissing+ * if true missing objects are reported by calling failure with a+ * MissingObjectException. This may be more expensive for the+ * implementation to guarantee. If false the implementation may+ * choose to report MissingObjectException, or silently skip over+ * the object with no warning.+ * @return queue to read the objects from.+ */+ public <T extends ObjectId> AsyncRevObjectQueue parseAny(+ Iterable<T> objectIds, boolean reportMissing) {+ List<T> need = new ArrayList<T>();+ List<RevObject> have = new ArrayList<RevObject>();+ for (T id : objectIds) {+ RevObject r = objects.get(id);+ if (r != null && (r.flags & PARSED) != 0)+ have.add(r);+ else+ need.add(id);+ }++ final Iterator<RevObject> objItr = have.iterator();+ if (need.isEmpty()) {+ return new AsyncRevObjectQueue() {+ public RevObject next() {+ return objItr.hasNext() ? objItr.next() : null;+ }++ public boolean cancel(boolean mayInterruptIfRunning) {+ return true;+ }++ public void release() {+ // In-memory only, no action required.+ }+ };+ }++ final AsyncObjectLoaderQueue<T> lItr = reader.open(need, reportMissing);+ return new AsyncRevObjectQueue() {+ public RevObject next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ if (objItr.hasNext())+ return objItr.next();+ if (!lItr.next())+ return null;++ ObjectId id = lItr.getObjectId();+ ObjectLoader ldr = lItr.open();+ RevObject r = objects.get(id);+ if (r == null)+ r = parseNew(id, ldr);+ else if (r instanceof RevCommit) {+ byte[] raw = ldr.getCachedBytes();+ ((RevCommit) r).parseCanonical(RevWalk.this, raw);+ } else if (r instanceof RevTag) {+ byte[] raw = ldr.getCachedBytes();+ ((RevTag) r).parseCanonical(RevWalk.this, raw);+ } else+ r.flags |= PARSED;+ return r;+ }++ public boolean cancel(boolean mayInterruptIfRunning) {+ return lItr.cancel(mayInterruptIfRunning);+ }++ public void release() {+ lItr.release();+ }+ };+ }++ /**+ * Ensure the object's critical headers have been parsed.+ * <p>+ * This method only returns successfully if the object exists and was parsed+ * without error.+ *+ * @param obj+ * the object the caller needs to be parsed.+ * @throws MissingObjectException+ * the supplied does not exist.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public void parseHeaders(final RevObject obj)+ throws MissingObjectException, IOException {+ if ((obj.flags & PARSED) == 0)+ obj.parseHeaders(this);+ }++ /**+ * Ensure the object's full body content is available.+ * <p>+ * This method only returns successfully if the object exists and was parsed+ * without error.+ *+ * @param obj+ * the object the caller needs to be parsed.+ * @throws MissingObjectException+ * the supplied does not exist.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public void parseBody(final RevObject obj)+ throws MissingObjectException, IOException {+ obj.parseBody(this);+ }++ /**+ * Peel back annotated tags until a non-tag object is found.+ *+ * @param obj+ * the starting object.+ * @return If {@code obj} is not an annotated tag, {@code obj}. Otherwise+ * the first non-tag object that {@code obj} references. The+ * returned object's headers have been parsed.+ * @throws MissingObjectException+ * a referenced object cannot be found.+ * @throws IOException+ * a pack file or loose object could not be read.+ */+ public RevObject peel(RevObject obj) throws MissingObjectException,+ IOException {+ while (obj instanceof RevTag) {+ parseHeaders(obj);+ obj = ((RevTag) obj).getObject();+ }+ parseHeaders(obj);+ return obj;+ }++ /**+ * Create a new flag for application use during walking.+ * <p>+ * Applications are only assured to be able to create 24 unique flags on any+ * given revision walker instance. Any flags beyond 24 are offered only if+ * the implementation has extra free space within its internal storage.+ *+ * @param name+ * description of the flag, primarily useful for debugging.+ * @return newly constructed flag instance.+ * @throws IllegalArgumentException+ * too many flags have been reserved on this revision walker.+ */+ public RevFlag newFlag(final String name) {+ final int m = allocFlag();+ return new RevFlag(this, name, m);+ }++ int allocFlag() {+ if (freeFlags == 0)+ throw new IllegalArgumentException(MessageFormat.format(+ JGitText.get().flagsAlreadyCreated,+ Integer.valueOf(32 - RESERVED_FLAGS)));+ final int m = Integer.lowestOneBit(freeFlags);+ freeFlags &= ~m;+ return m;+ }++ /**+ * Automatically carry a flag from a child commit to its parents.+ * <p>+ * A carried flag is copied from the child commit onto its parents when the+ * child commit is popped from the lowest level of walk's internal graph.+ *+ * @param flag+ * the flag to carry onto parents, if set on a descendant.+ */+ public void carry(final RevFlag flag) {+ if ((freeFlags & flag.mask) != 0)+ throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name));+ if (flag.walker != this)+ throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name));+ carryFlags |= flag.mask;+ }++ /**+ * Automatically carry flags from a child commit to its parents.+ * <p>+ * A carried flag is copied from the child commit onto its parents when the+ * child commit is popped from the lowest level of walk's internal graph.+ *+ * @param set+ * the flags to carry onto parents, if set on a descendant.+ */+ public void carry(final Collection<RevFlag> set) {+ for (final RevFlag flag : set)+ carry(flag);+ }++ /**+ * Preserve a RevFlag during all {@code reset} methods.+ * <p>+ * Calling {@code retainOnReset(flag)} avoids needing to pass the flag+ * during each {@code resetRetain()} invocation on this instance.+ * <p>+ * Clearing flags marked retainOnReset requires disposing of the flag with+ * {@code #disposeFlag(RevFlag)} or disposing of the entire RevWalk by+ * {@code #dispose()}.+ *+ * @param flag+ * the flag to retain during all resets.+ * @since 3.6+ */+ public final void retainOnReset(RevFlag flag) {+ if ((freeFlags & flag.mask) != 0)+ throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name));+ if (flag.walker != this)+ throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name));+ retainOnReset |= flag.mask;+ }++ /**+ * Preserve a set of RevFlags during all {@code reset} methods.+ * <p>+ * Calling {@code retainOnReset(set)} avoids needing to pass the flags+ * during each {@code resetRetain()} invocation on this instance.+ * <p>+ * Clearing flags marked retainOnReset requires disposing of the flag with+ * {@code #disposeFlag(RevFlag)} or disposing of the entire RevWalk by+ * {@code #dispose()}.+ *+ * @param flags+ * the flags to retain during all resets.+ * @since 3.6+ */+ public final void retainOnReset(Collection<RevFlag> flags) {+ for (RevFlag f : flags)+ retainOnReset(f);+ }++ /**+ * Allow a flag to be recycled for a different use.+ * <p>+ * Recycled flags always come back as a different Java object instance when+ * assigned again by {@link #newFlag(String)}.+ * <p>+ * If the flag was previously being carried, the carrying request is+ * removed. Disposing of a carried flag while a traversal is in progress has+ * an undefined behavior.+ *+ * @param flag+ * the to recycle.+ */+ public void disposeFlag(final RevFlag flag) {+ freeFlag(flag.mask);+ }++ void freeFlag(final int mask) {+ retainOnReset &= ~mask;+ if (isNotStarted()) {+ freeFlags |= mask;+ carryFlags &= ~mask;+ } else {+ delayFreeFlags |= mask;+ }+ }++ private void finishDelayedFreeFlags() {+ if (delayFreeFlags != 0) {+ freeFlags |= delayFreeFlags;+ carryFlags &= ~delayFreeFlags;+ delayFreeFlags = 0;+ }+ }++ /**+ * Resets internal state and allows this instance to be used again.+ * <p>+ * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)+ * instances are not invalidated. RevFlag instances are not invalidated, but+ * are removed from all RevObjects.+ */+ public final void reset() {+ reset(0);+ }++ /**+ * Resets internal state and allows this instance to be used again.+ * <p>+ * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)+ * instances are not invalidated. RevFlag instances are not invalidated, but+ * are removed from all RevObjects.+ *+ * @param retainFlags+ * application flags that should <b>not</b> be cleared from+ * existing commit objects.+ */+ public final void resetRetain(final RevFlagSet retainFlags) {+ reset(retainFlags.mask);+ }++ /**+ * Resets internal state and allows this instance to be used again.+ * <p>+ * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)+ * instances are not invalidated. RevFlag instances are not invalidated, but+ * are removed from all RevObjects.+ * <p>+ * See {@link #retainOnReset(RevFlag)} for an alternative that does not+ * require passing the flags during each reset.+ *+ * @param retainFlags+ * application flags that should <b>not</b> be cleared from+ * existing commit objects.+ */+ public final void resetRetain(final RevFlag... retainFlags) {+ int mask = 0;+ for (final RevFlag flag : retainFlags)+ mask |= flag.mask;+ reset(mask);+ }++ /**+ * Resets internal state and allows this instance to be used again.+ * <p>+ * Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)+ * instances are not invalidated. RevFlag instances are not invalidated, but+ * are removed from all RevObjects.+ *+ * @param retainFlags+ * application flags that should <b>not</b> be cleared from+ * existing commit objects.+ */+ protected void reset(int retainFlags) {+ finishDelayedFreeFlags();+ retainFlags |= PARSED | retainOnReset;+ final int clearFlags = ~retainFlags;++ final FIFORevQueue q = new FIFORevQueue();+ for (final RevCommit c : roots) {+ if ((c.flags & clearFlags) == 0)+ continue;+ c.flags &= retainFlags;+ c.reset();+ q.add(c);+ }++ for (;;) {+ final RevCommit c = q.next();+ if (c == null)+ break;+ if (c.parents == null)+ continue;+ for (final RevCommit p : c.parents) {+ if ((p.flags & clearFlags) == 0)+ continue;+ p.flags &= retainFlags;+ p.reset();+ q.add(p);+ }+ }++ roots.clear();+ queue = new DateRevQueue();+ pending = new StartGenerator(this);+ }++ /**+ * Dispose all internal state and invalidate all RevObject instances.+ * <p>+ * All RevObject (and thus RevCommit, etc.) instances previously acquired+ * from this RevWalk are invalidated by a dispose call. Applications must+ * not retain or use RevObject instances obtained prior to the dispose call.+ * All RevFlag instances are also invalidated, and must not be reused.+ */+ public void dispose() {+ reader.release();+ freeFlags = APP_FLAGS;+ delayFreeFlags = 0;+ retainOnReset = 0;+ carryFlags = UNINTERESTING;+ objects.clear();+ reader.release();+ roots.clear();+ queue = new DateRevQueue();+ pending = new StartGenerator(this);+ shallowCommitsInitialized = false;+ }++ /**+ * Returns an Iterator over the commits of this walker.+ * <p>+ * The returned iterator is only useful for one walk. If this RevWalk gets+ * reset a new iterator must be obtained to walk over the new results.+ * <p>+ * Applications must not use both the Iterator and the {@link #next()} API+ * at the same time. Pick one API and use that for the entire walk.+ * <p>+ * If a checked exception is thrown during the walk (see {@link #next()})+ * it is rethrown from the Iterator as a {@link RevWalkException}.+ *+ * @return an iterator over this walker's commits.+ * @see RevWalkException+ */+ public Iterator<RevCommit> iterator() {+ final RevCommit first;+ try {+ first = RevWalk.this.next();+ } catch (MissingObjectException e) {+ throw new RevWalkException(e);+ } catch (IncorrectObjectTypeException e) {+ throw new RevWalkException(e);+ } catch (IOException e) {+ throw new RevWalkException(e);+ }++ return new Iterator<RevCommit>() {+ RevCommit next = first;++ public boolean hasNext() {+ return next != null;+ }++ public RevCommit next() {+ try {+ final RevCommit r = next;+ next = RevWalk.this.next();+ return r;+ } catch (MissingObjectException e) {+ throw new RevWalkException(e);+ } catch (IncorrectObjectTypeException e) {+ throw new RevWalkException(e);+ } catch (IOException e) {+ throw new RevWalkException(e);+ }+ }++ public void remove() {+ throw new UnsupportedOperationException();+ }+ };+ }++ /** Throws an exception if we have started producing output. */+ protected void assertNotStarted() {+ if (isNotStarted())+ return;+ throw new IllegalStateException(JGitText.get().outputHasAlreadyBeenStarted);+ }++ private boolean isNotStarted() {+ return pending instanceof StartGenerator;+ }++ /**+ * Create and return an {@link ObjectWalk} using the same objects.+ * <p>+ * Prior to using this method, the caller must reset this RevWalk to clean+ * any flags that were used during the last traversal.+ * <p>+ * The returned ObjectWalk uses the same ObjectReader, internal object pool,+ * and free RevFlags. Once the ObjectWalk is created, this RevWalk should+ * not be used anymore.+ *+ * @return a new walk, using the exact same object pool.+ */+ public ObjectWalk toObjectWalkWithSameObjects() {+ ObjectWalk ow = new ObjectWalk(reader);+ RevWalk rw = ow;+ rw.objects = objects;+ rw.freeFlags = freeFlags;+ return ow;+ }++ /**+ * Construct a new unparsed commit for the given object.+ *+ * @param id+ * the object this walker requires a commit reference for.+ * @return a new unparsed reference for the object.+ */+ protected RevCommit createCommit(final AnyObjectId id) {+ return new RevCommit(id);+ }++ void carryFlagsImpl(final RevCommit c) {+ final int carry = c.flags & carryFlags;+ if (carry != 0)+ RevCommit.carryFlags(c, carry);+ }++ /**+ * Assume additional commits are shallow (have no parents).+ *+ * @param ids+ * commits that should be treated as shallow commits, in addition+ * to any commits already known to be shallow by the repository.+ * @since 3.3+ */+ public void assumeShallow(Collection<? extends ObjectId> ids) {+ for (ObjectId id : ids)+ lookupCommit(id).parents = RevCommit.NO_PARENTS;+ }++ void initializeShallowCommits() throws IOException {+ if (shallowCommitsInitialized)+ throw new IllegalStateException(+ JGitText.get().shallowCommitsAlreadyInitialized);++ shallowCommitsInitialized = true;++ if (reader == null)+ return;++ for (ObjectId id : reader.getShallowCommits())+ lookupCommit(id).parents = RevCommit.NO_PARENTS;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevWalkUtils.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevWalkUtils.javanew file mode 100644index 0000000000..11fec31e91--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RevWalkUtils.java@@ -0,0 +1,180 @@+/*+ * Copyright (C) 2011-2012, Robin Stocker <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;+import java.util.ArrayList;+import java.util.Collection;+import java.util.List;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.lib.Ref;++/**+ * Utility methods for {@link RevWalk}.+ */+public final class RevWalkUtils {++ private RevWalkUtils() {+ // Utility class+ }++ /**+ * Count the number of commits that are reachable from <code>start</code>+ * until a commit that is reachable from <code>end</code> is encountered. In+ * other words, count the number of commits that are in <code>start</code>,+ * but not in <code>end</code>.+ * <p>+ * Note that this method calls {@link RevWalk#reset()} at the beginning.+ * Also note that the existing rev filter on the walk is left as-is, so be+ * sure to set the right rev filter before calling this method.+ *+ * @param walk+ * the rev walk to use+ * @param start+ * the commit to start counting from+ * @param end+ * the commit where counting should end, or null if counting+ * should be done until there are no more commits+ *+ * @return the number of commits+ * @throws MissingObjectException+ * @throws IncorrectObjectTypeException+ * @throws IOException+ */+ public static int count(final RevWalk walk, final RevCommit start,+ final RevCommit end) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ return find(walk, start, end).size();+ }++ /**+ * Find commits that are reachable from <code>start</code> until a commit+ * that is reachable from <code>end</code> is encountered. In other words,+ * Find of commits that are in <code>start</code>, but not in+ * <code>end</code>.+ * <p>+ * Note that this method calls {@link RevWalk#reset()} at the beginning.+ * Also note that the existing rev filter on the walk is left as-is, so be+ * sure to set the right rev filter before calling this method.+ *+ * @param walk+ * the rev walk to use+ * @param start+ * the commit to start counting from+ * @param end+ * the commit where counting should end, or null if counting+ * should be done until there are no more commits+ * @return the commits found+ * @throws MissingObjectException+ * @throws IncorrectObjectTypeException+ * @throws IOException+ */+ public static List<RevCommit> find(final RevWalk walk,+ final RevCommit start, final RevCommit end)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {+ walk.reset();+ walk.markStart(start);+ if (end != null)+ walk.markUninteresting(end);++ List<RevCommit> commits = new ArrayList<RevCommit>();+ for (RevCommit c : walk)+ commits.add(c);+ return commits;+ }++ /**+ * Find the list of branches a given commit is reachable from when following+ * parent.s+ * <p>+ * Note that this method calls {@link RevWalk#reset()} at the beginning.+ * <p>+ * In order to improve performance this method assumes clock skew among+ * committers is never larger than 24 hours.+ *+ * @param commit+ * the commit we are looking at+ * @param revWalk+ * The RevWalk to be used.+ * @param refs+ * the set of branches we want to see reachability from+ * @return the list of branches a given commit is reachable from+ * @throws MissingObjectException+ * @throws IncorrectObjectTypeException+ * @throws IOException+ */+ public static List<Ref> findBranchesReachableFrom(RevCommit commit,+ RevWalk revWalk, Collection<Ref> refs)+ throws MissingObjectException, IncorrectObjectTypeException,+ IOException {++ // Make sure commit is from the same RevWalk+ commit = revWalk.parseCommit(commit.getId());+ revWalk.reset();+ List<Ref> result = new ArrayList<Ref>();++ final int SKEW = 24*3600; // one day clock skew++ for (Ref ref : refs) {+ RevObject maybehead = revWalk.parseAny(ref.getObjectId());+ if (!(maybehead instanceof RevCommit))+ continue;+ RevCommit headCommit = (RevCommit) maybehead;++ // if commit is in the ref branch, then the tip of ref should be+ // newer than the commit we are looking for. Allow for a large+ // clock skew.+ if (headCommit.getCommitTime() + SKEW < commit.getCommitTime())+ continue;++ if (revWalk.isMergedInto(commit, headCommit))+ result.add(ref);+ }+ return result;+ }++}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/RewriteGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RewriteGenerator.javanew file mode 100644index 0000000000..3ab96ca228--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/RewriteGenerator.java@@ -0,0 +1,188 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/**+ * Replaces a RevCommit's parents until not colored with REWRITE.+ * <p>+ * Before a RevCommit is returned to the caller its parents are updated to+ * create a dense DAG. Instead of reporting the actual parents as recorded when+ * the commit was created the returned commit will reflect the next closest+ * commit that matched the revision walker's filters.+ * <p>+ * This generator is the second phase of a path limited revision walk and+ * assumes it is receiving RevCommits from {@link TreeRevFilter},+ * after they have been fully buffered by {@link AbstractRevQueue}. The full+ * buffering is necessary to allow the simple loop used within our own+ * {@link #rewrite(RevCommit)} to pull completely through a strand of+ * {@link RevWalk#REWRITE} colored commits and come up with a simplification+ * that makes the DAG dense. Not fully buffering the commits first would cause+ * this loop to abort early, due to commits not being parsed and colored+ * correctly.+ *+ * @see TreeRevFilter+ */+class RewriteGenerator extends Generator {+ private static final int REWRITE = RevWalk.REWRITE;++ /** For {@link #cleanup(RevCommit[])} to remove duplicate parents. */+ private static final int DUPLICATE = RevWalk.TEMP_MARK;++ private final Generator source;++ RewriteGenerator(final Generator s) {+ source = s;+ }++ @Override+ void shareFreeList(final BlockRevQueue q) {+ source.shareFreeList(q);+ }++ @Override+ int outputType() {+ return source.outputType() & ~NEEDS_REWRITE;+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ for (;;) {+ final RevCommit c = source.next();+ if (c == null)+ return null;++ boolean rewrote = false;+ final RevCommit[] pList = c.parents;+ final int nParents = pList.length;+ for (int i = 0; i < nParents; i++) {+ final RevCommit oldp = pList[i];+ final RevCommit newp = rewrite(oldp);+ if (oldp != newp) {+ pList[i] = newp;+ rewrote = true;+ }+ }+ if (rewrote)+ c.parents = cleanup(pList);++ return c;+ }+ }++ private RevCommit rewrite(RevCommit p) {+ for (;;) {+ final RevCommit[] pList = p.parents;+ if (pList.length > 1) {+ // This parent is a merge, so keep it.+ //+ return p;+ }++ if ((p.flags & RevWalk.UNINTERESTING) != 0) {+ // Retain uninteresting parents. They show where the+ // DAG was cut off because it wasn't interesting.+ //+ return p;+ }++ if ((p.flags & REWRITE) == 0) {+ // This parent was not eligible for rewriting. We+ // need to keep it in the DAG.+ //+ return p;+ }++ if (pList.length == 0) {+ // We can't go back any further, other than to+ // just delete the parent entirely.+ //+ return null;+ }++ p = pList[0];+ }+ }++ private RevCommit[] cleanup(final RevCommit[] oldList) {+ // Remove any duplicate parents caused due to rewrites (e.g. a merge+ // with two sides that both simplified back into the merge base).+ // We also may have deleted a parent by marking it null.+ //+ int newCnt = 0;+ for (int o = 0; o < oldList.length; o++) {+ final RevCommit p = oldList[o];+ if (p == null)+ continue;+ if ((p.flags & DUPLICATE) != 0) {+ oldList[o] = null;+ continue;+ }+ p.flags |= DUPLICATE;+ newCnt++;+ }++ if (newCnt == oldList.length) {+ for (final RevCommit p : oldList)+ p.flags &= ~DUPLICATE;+ return oldList;+ }++ final RevCommit[] newList = new RevCommit[newCnt];+ newCnt = 0;+ for (final RevCommit p : oldList) {+ if (p != null) {+ newList[newCnt++] = p;+ p.flags &= ~DUPLICATE;+ }+ }++ return newList;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/StartGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/StartGenerator.javanew file mode 100644index 0000000000..593e09e255--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/StartGenerator.java@@ -0,0 +1,188 @@+/*+ * Copyright (C) 2008-2009, Google Inc.+ * Copyright (C) 2008, Marek Zawirski <[email protected]>+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;+import java.text.MessageFormat;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.internal.JGitText;+import org.eclipse.jgit.revwalk.filter.AndRevFilter;+import org.eclipse.jgit.revwalk.filter.RevFilter;+import org.eclipse.jgit.treewalk.filter.TreeFilter;++/**+ * Initial RevWalk generator that bootstraps a new walk.+ * <p>+ * Initially RevWalk starts with this generator as its chosen implementation.+ * The first request for a RevCommit from the RevWalk instance calls to our+ * {@link #next()} method, and we replace ourselves with the best Generator+ * implementation available based upon the current RevWalk configuration.+ */+class StartGenerator extends Generator {+ private final RevWalk walker;++ StartGenerator(final RevWalk w) {+ walker = w;+ }++ @Override+ int outputType() {+ return 0;+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ Generator g;++ final RevWalk w = walker;+ RevFilter rf = w.getRevFilter();+ final TreeFilter tf = w.getTreeFilter();+ AbstractRevQueue q = walker.queue;++ w.reader.walkAdviceBeginCommits(w, w.roots);++ if (rf == RevFilter.MERGE_BASE) {+ // Computing for merge bases is a special case and does not+ // use the bulk of the generator pipeline.+ //+ if (tf != TreeFilter.ALL)+ throw new IllegalStateException(MessageFormat.format(+ JGitText.get().cannotCombineTreeFilterWithRevFilter, tf, rf));++ final MergeBaseGenerator mbg = new MergeBaseGenerator(w);+ walker.pending = mbg;+ walker.queue = AbstractRevQueue.EMPTY_QUEUE;+ mbg.init(q);+ return mbg.next();+ }++ final boolean uninteresting = q.anybodyHasFlag(RevWalk.UNINTERESTING);+ boolean boundary = walker.hasRevSort(RevSort.BOUNDARY);++ if (!boundary && walker instanceof ObjectWalk) {+ // The object walker requires boundary support to color+ // trees and blobs at the boundary uninteresting so it+ // does not produce those in the result.+ //+ boundary = true;+ }+ if (boundary && !uninteresting) {+ // If we were not fed uninteresting commits we will never+ // construct a boundary. There is no reason to include the+ // extra overhead associated with that in our pipeline.+ //+ boundary = false;+ }++ final DateRevQueue pending;+ int pendingOutputType = 0;+ if (q instanceof DateRevQueue)+ pending = (DateRevQueue)q;+ else+ pending = new DateRevQueue(q);+ if (tf != TreeFilter.ALL) {+ int rewriteFlag;+ if (w.getRewriteParents()) {+ pendingOutputType |= HAS_REWRITE | NEEDS_REWRITE;+ rewriteFlag = RevWalk.REWRITE;+ } else+ rewriteFlag = 0;+ rf = AndRevFilter.create(new TreeRevFilter(w, tf, rewriteFlag), rf);+ }++ walker.queue = q;++ if (walker instanceof DepthWalk) {+ DepthWalk dw = (DepthWalk) walker;+ g = new DepthGenerator(dw, pending);+ } else {+ g = new PendingGenerator(w, pending, rf, pendingOutputType);++ if (boundary) {+ // Because the boundary generator may produce uninteresting+ // commits we cannot allow the pending generator to dispose+ // of them early.+ //+ ((PendingGenerator) g).canDispose = false;+ }+ }++ if ((g.outputType() & NEEDS_REWRITE) != 0) {+ // Correction for an upstream NEEDS_REWRITE is to buffer+ // fully and then apply a rewrite generator that can+ // pull through the rewrite chain and produce a dense+ // output graph.+ //+ g = new FIFORevQueue(g);+ g = new RewriteGenerator(g);+ }++ if (walker.hasRevSort(RevSort.TOPO)+ && (g.outputType() & SORT_TOPO) == 0)+ g = new TopoSortGenerator(g);+ if (walker.hasRevSort(RevSort.REVERSE))+ g = new LIFORevQueue(g);+ if (boundary)+ g = new BoundaryGenerator(w, g);+ else if (uninteresting) {+ // Try to protect ourselves from uninteresting commits producing+ // due to clock skew in the commit time stamps. Delay such that+ // we have a chance at coloring enough of the graph correctly,+ // and then strip any UNINTERESTING nodes that may have leaked+ // through early.+ //+ if (pending.peek() != null)+ g = new DelayRevQueue(g);+ g = new FixUninterestingGenerator(g);+ }++ w.pending = g;+ return g.next();+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/TopoSortGenerator.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/TopoSortGenerator.javanew file mode 100644index 0000000000..7b11d04901--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/TopoSortGenerator.java@@ -0,0 +1,129 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;++import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;++/** Sorts commits in topological order. */+class TopoSortGenerator extends Generator {+ private static final int TOPO_DELAY = RevWalk.TOPO_DELAY;++ private final FIFORevQueue pending;++ private final int outputType;++ /**+ * Create a new sorter and completely spin the generator.+ * <p>+ * When the constructor completes the supplied generator will have no+ * commits remaining, as all of the commits will be held inside of this+ * generator's internal buffer.+ *+ * @param s+ * generator to pull all commits out of, and into this buffer.+ * @throws MissingObjectException+ * @throws IncorrectObjectTypeException+ * @throws IOException+ */+ TopoSortGenerator(final Generator s) throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ pending = new FIFORevQueue();+ outputType = s.outputType() | SORT_TOPO;+ s.shareFreeList(pending);+ for (;;) {+ final RevCommit c = s.next();+ if (c == null)+ break;+ for (final RevCommit p : c.parents)+ p.inDegree++;+ pending.add(c);+ }+ }++ @Override+ int outputType() {+ return outputType;+ }++ @Override+ void shareFreeList(final BlockRevQueue q) {+ q.shareFreeList(pending);+ }++ @Override+ RevCommit next() throws MissingObjectException,+ IncorrectObjectTypeException, IOException {+ for (;;) {+ final RevCommit c = pending.next();+ if (c == null)+ return null;++ if (c.inDegree > 0) {+ // At least one of our children is missing. We delay+ // production until all of our children are output.+ //+ c.flags |= TOPO_DELAY;+ continue;+ }++ // All of our children have already produced,+ // so it is OK for us to produce now as well.+ //+ for (final RevCommit p : c.parents) {+ 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+ // behind this child.+ //+ p.flags &= ~TOPO_DELAY;+ pending.unpop(p);+ }+ }+ return c;+ }+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/TreeRevFilter.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/TreeRevFilter.javanew file mode 100644index 0000000000..e561c62a80--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/TreeRevFilter.java@@ -0,0 +1,304 @@+/*+ * Copyright (C) 2008, Shawn O. Pearce <[email protected]>+ * and other copyright owners as documented in the project's IP log.+ *+ * This program and the accompanying materials are made available+ * under the terms of the Eclipse Distribution License v1.0 which+ * accompanies this distribution, is reproduced below, and is+ * available at http://www.eclipse.org/org/documents/edl-v10.php+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or+ * without modification, are permitted provided that the following+ * conditions are met:+ *+ * - Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * - Redistributions in binary form must reproduce the above+ * copyright notice, this list of conditions and the following+ * disclaimer in the documentation and/or other materials provided+ * with the distribution.+ *+ * - Neither the name of the Eclipse Foundation, Inc. nor the+ * names of its contributors may be used to endorse or promote+ * products derived from this software without specific prior+ * written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+ */++package org.eclipse.jgit.revwalk;++import java.io.IOException;+import java.util.List;++import org.eclipse.jgit.diff.DiffConfig;+import org.eclipse.jgit.diff.DiffEntry;+import org.eclipse.jgit.diff.DiffEntry.ChangeType;+import org.eclipse.jgit.diff.RenameDetector;+import org.eclipse.jgit.errors.CorruptObjectException;+import org.eclipse.jgit.errors.IncorrectObjectTypeException;+import org.eclipse.jgit.errors.MissingObjectException;+import org.eclipse.jgit.errors.StopWalkException;+import org.eclipse.jgit.lib.ObjectId;+import org.eclipse.jgit.revwalk.filter.RevFilter;+import org.eclipse.jgit.treewalk.TreeWalk;+import org.eclipse.jgit.treewalk.filter.TreeFilter;++/**+ * Filter applying a {@link TreeFilter} against changed paths in each commit.+ * <p>+ * Each commit is differenced concurrently against all of its parents to look+ * for tree entries that are interesting to the {@link TreeFilter}.+ *+ * @since 3.5+ */+public class TreeRevFilter extends RevFilter {+ private static final int PARSED = RevWalk.PARSED;++ private static final int UNINTERESTING = RevWalk.UNINTERESTING;++ private final int rewriteFlag;+ private final TreeWalk pathFilter;++ /**+ * Create a {@link RevFilter} from a {@link TreeFilter}.+ *+ * @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+ * following new paths after a rename.+ * @since 3.5+ */+ public TreeRevFilter(final RevWalk walker, final TreeFilter t) {+ this(walker, t, 0);+ }+++ /**+ * 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.+ * <p>+ * If no interesting tree entries are found the commit is colored with+ * {@code rewriteFlag}, allowing a later pass implemented by+ * {@link RewriteGenerator} to remove those colored commits from the DAG.+ *+ * @see RewriteGenerator+ *+ * @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+ * following new paths after a rename.+ * @param rewriteFlag+ * flag to color commits to be removed from the simplified DAT.+ */+ TreeRevFilter(final RevWalk walker, final TreeFilter t,+ final int rewriteFlag) {+ pathFilter = new TreeWalk(walker.reader);+ pathFilter.setFilter(t);+ pathFilter.setRecursive(t.shouldBeRecursive());+ this.rewriteFlag = rewriteFlag;+ }++ @Override+ public RevFilter clone() {+ throw new UnsupportedOperationException();+ }++ @Override+ public boolean include(final RevWalk walker, final RevCommit c)+ throws StopWalkException, MissingObjectException,+ IncorrectObjectTypeException, IOException {+ // Reset the tree filter to scan this commit and parents.+ //+ final RevCommit[] pList = c.parents;+ final int nParents = pList.length;+ final TreeWalk tw = pathFilter;+ final ObjectId[] trees = new ObjectId[nParents + 1];+ for (int i = 0; i < nParents; i++) {+ final RevCommit p = c.parents[i];+ if ((p.flags & PARSED) == 0)+ p.parseHeaders(walker);+ trees[i] = p.getTree();+ }+ trees[nParents] = c.getTree();+ tw.reset(trees);++ if (nParents == 1) {+ // We have exactly one parent. This is a very common case.+ //+ int chgs = 0, adds = 0;+ while (tw.next()) {+ chgs++;+ if (tw.getRawMode(0) == 0 && tw.getRawMode(1) != 0)+ adds++;+ else+ break; // no point in looking at this further.+ }++ if (chgs == 0) {+ // No changes, so our tree is effectively the same as+ // our parent tree. We pass the buck to our parent.+ //+ c.flags |= rewriteFlag;+ return false;+ } else {+ // We have interesting items, but neither of the special+ // cases denoted above.+ //+ if (adds > 0 && tw.getFilter() instanceof FollowFilter) {+ // One of the paths we care about was added in this+ // commit. We need to update our filter to its older+ // name, if we can discover it. Find out what that is.+ //+ updateFollowFilter(trees, ((FollowFilter) tw.getFilter()).cfg);+ }+ return true;+ }+ } else if (nParents == 0) {+ // We have no parents to compare against. Consider us to be+ // REWRITE only if we have no paths matching our filter.+ //+ if (tw.next())+ return true;+ c.flags |= rewriteFlag;+ return false;+ }++ // We are a merge commit. We can only be REWRITE if we are same+ // to _all_ parents. We may also be able to eliminate a parent if+ // it does not contribute changes to us. Such a parent may be an+ // uninteresting side branch.+ //+ final int[] chgs = new int[nParents];+ final int[] adds = new int[nParents];+ while (tw.next()) {+ final int myMode = tw.getRawMode(nParents);+ for (int i = 0; i < nParents; i++) {+ final int pMode = tw.getRawMode(i);+ if (myMode == pMode && tw.idEqual(i, nParents))+ continue;++ chgs[i]++;+ if (pMode == 0 && myMode != 0)+ adds[i]++;+ }+ }++ boolean same = false;+ boolean diff = false;+ for (int i = 0; i < nParents; i++) {+ if (chgs[i] == 0) {+ // No changes, so our tree is effectively the same as+ // this parent tree. We pass the buck to only this one+ // parent commit.+ //++ final RevCommit p = pList[i];+ if ((p.flags & UNINTERESTING) != 0) {+ // This parent was marked as not interesting by the+ // application. We should look for another parent+ // that is interesting.+ //+ same = true;+ continue;+ }++ c.flags |= rewriteFlag;+ c.parents = new RevCommit[] { p };+ return false;+ }++ // Comment out below as this assumption is incorrect+ /*+ if (chgs[i] == adds[i]) {+ // All of the differences from this parent were because we+ // added files that they did not have. This parent is our+ // "empty tree root" and thus their history is not relevant.+ // Cut our grandparents to be an empty list.+ //+ pList[i].parents = RevCommit.NO_PARENTS;+ }+ */++ // We have an interesting difference relative to this parent.+ //+ diff = true;+ }++ if (diff && !same) {+ // We did not abort above, so we are different in at least one+ // way from all of our parents. We have to take the blame for+ // that difference.+ //+ return true;+ }++ // We are the same as all of our parents. We must keep them+ // as they are and allow those parents to flow into pending+ // for further scanning.+ //+ c.flags |= rewriteFlag;+ return false;+ }++ @Override+ public boolean requiresCommitBody() {+ return false;+ }++ private void updateFollowFilter(ObjectId[] trees, DiffConfig cfg)+ throws MissingObjectException, IncorrectObjectTypeException,+ CorruptObjectException, IOException {+ TreeWalk tw = pathFilter;+ FollowFilter oldFilter = (FollowFilter) tw.getFilter();+ tw.setFilter(TreeFilter.ANY_DIFF);+ tw.reset(trees);++ List<DiffEntry> files = DiffEntry.scan(tw);+ RenameDetector rd = new RenameDetector(tw.getObjectReader(), cfg);+ rd.addAll(files);+ files = rd.compute();++ TreeFilter newFilter = oldFilter;+ for (DiffEntry ent : files) {+ if (isRename(ent) && ent.getNewPath().equals(oldFilter.getPath())) {+ newFilter = FollowFilter.create(ent.getOldPath(), cfg);+ RenameCallback callback = oldFilter.getRenameCallback();+ if (callback != null) {+ callback.renamed(ent);+ // forward the callback to the new follow filter+ ((FollowFilter) newFilter).setRenameCallback(callback);+ }+ break;+ }+ }+ tw.setFilter(newFilter);+ }++ private static boolean isRename(DiffEntry ent) {+ return ent.getChangeType() == ChangeType.RENAME+ || ent.getChangeType() == ChangeType.COPY;+ }+}diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/package-info.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/package-info.javanew file mode 100644index 0000000000..05ab51e48f--- /dev/null+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/package-info.java@@ -0,0 +1,4 @@+/**+ * Walking revision graphs (commit history).+ */+package org.eclipse.jgit.revwalk;diff --git a/gitplex.product/src/test/java/gitplex/product/Test.java b/gitplex.product/src/test/java/gitplex/product/Test.javaindex 7b86136437..456cbbc2c5 100644--- a/gitplex.product/src/test/java/gitplex/product/Test.java+++ b/gitplex.product/src/test/java/gitplex/product/Test.java@@ -2,34 +2,26 @@ package gitplex.product;import java.io.File;import java.io.IOException;-import java.util.Iterator;+import java.util.Map;-import org.eclipse.jgit.api.Git;-import org.eclipse.jgit.api.LogCommand;import org.eclipse.jgit.api.errors.GitAPIException;import org.eclipse.jgit.api.errors.NoHeadException;+import org.eclipse.jgit.internal.storage.file.FileRepository;import org.eclipse.jgit.lib.Repository;-import org.eclipse.jgit.lib.RepositoryCache;-import org.eclipse.jgit.lib.RepositoryCache.FileKey;-import org.eclipse.jgit.revwalk.RevCommit;-import org.eclipse.jgit.util.FS;++import com.pmease.commons.git.LastCommitInfo;+import com.pmease.commons.git.LastCommitsOfChildren;public class Test {@org.junit.Testpublic void test() throws IOException, NoHeadException, GitAPIException {- Repository repo = RepositoryCache.open(FileKey.exact(new File("w:\\temp\\repo\\.git"), FS.DETECTED));- Git git = Git.wrap(repo);- LogCommand log = git.log().add(repo.resolve("master"));- Iterable<RevCommit> commits = log.call();- Iterator<RevCommit> it = commits.iterator();- int i=0;- while (it.hasNext()) {- RevCommit commit = it.next();- i++;+ Repository repo = new FileRepository(new File("w:\\linux\\.git"));+ LastCommitsOfChildren lastCommits = new LastCommitsOfChildren(repo, repo.resolve("master"), "Documentation");+ for (Map.Entry<String, LastCommitInfo> entry: lastCommits.entrySet()) {+ System.out.println(entry.getKey() + ": " + entry.getValue().getId());}- System.out.println(i);repo.close();}-+}\ No newline at end of file