aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
diff options
context:
space:
mode:
authorkylezhao <kylezhao@tencent.com>2021-07-14 19:02:12 +0800
committerkylezhao <kylezhao@tencent.com>2023-01-10 14:56:33 +0800
commitde7d06775c5cf071fb5a14b19d230f5e0845b9ef (patch)
tree967a126338467cc2088f872b1cfa54ae32984943 /org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
parent801a56b48a7fe3c6e171073211cc62194184fe79 (diff)
downloadjgit-de7d06775c5cf071fb5a14b19d230f5e0845b9ef.tar.gz
jgit-de7d06775c5cf071fb5a14b19d230f5e0845b9ef.zip
RevWalk: integrate commit-graph with commit parsing
RevWalk#createCommit() will inspect the commit-graph file to find the specified object's graph position and then return a new RevCommitCG instance. RevCommitGC is a RevCommit with an additional "pointer" (the position) to the commit-graph, so it can load the headers and metadata from there instead of the pack. This saves IO access in walks where the body is not needed (i.e. #isRetainBody is false and #parseBody is not invoked). RevWalk uses automatically the commit-graph if available, no action needed from callers. The commit-graph is fetched on first access from the reader (that internally can keep it loaded and reuse it between walks). The startup cost of reading the entire commit graph is small. After testing, reading a commit-graph with 1 million commits takes less than 50ms. If we use RepositoryCache, it will not be initialized util the commit-graph is rewritten. Bug: 574368 Change-Id: I90d0f64af24f3acc3eae6da984eae302d338f5ee Signed-off-by: kylezhao <kylezhao@tencent.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java25
1 files changed, 24 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
index 6b644cef90..e155a25638 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
@@ -105,7 +105,12 @@ public class RevCommit extends RevObject {
static final RevCommit[] NO_PARENTS = {};
- private RevTree tree;
+ /**
+ * Tree reference of the commit.
+ *
+ * @since 6.5
+ */
+ protected RevTree tree;
/**
* Avoid accessing this field directly. Use method
@@ -657,6 +662,24 @@ public class RevCommit extends RevObject {
}
/**
+ * Get the distance of the commit from the root, as defined in
+ * {@link org.eclipse.jgit.internal.storage.commitgraph.CommitGraph}
+ * <p>
+ * Generation number is
+ * {@link org.eclipse.jgit.lib.Constants#COMMIT_GENERATION_UNKNOWN} when the
+ * commit is not in the commit-graph. If a commit-graph file was written by
+ * a version of Git that did not compute generation numbers, then those
+ * commits in commit-graph will have generation number represented by
+ * {@link org.eclipse.jgit.lib.Constants#COMMIT_GENERATION_NOT_COMPUTED}.
+ *
+ * @return the generation number
+ * @since 6.5
+ */
+ int getGeneration() {
+ return Constants.COMMIT_GENERATION_UNKNOWN;
+ }
+
+ /**
* Reset this commit to allow another RevWalk with the same instances.
* <p>
* Subclasses <b>must</b> call <code>super.reset()</code> to ensure the