123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /*
- * Copyright (C) 2021, Tencent.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Distribution License v. 1.0 which is available at
- * https://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
- package org.eclipse.jgit.lib;
-
- /**
- * The CommitGraph is a supplemental data structure that accelerates commit
- * graph walks.
- * <p>
- * If a user downgrades or disables the <code>core.commitGraph</code> config
- * setting, then the existing object database is sufficient.
- * </p>
- * <p>
- * It stores the commit graph structure along with some extra metadata to speed
- * up graph walks. By listing commit OIDs in lexicographic order, we can
- * identify an integer position for each commit and refer to the parents of a
- * commit using those integer positions. We use binary search to find initial
- * commits and then use the integer positions for fast lookups during the walk.
- * </p>
- *
- * @since 5.13
- */
- public interface CommitGraph {
-
- /**
- * We use GENERATION_NUMBER_INFINITY(-1) to mark commits not in the
- * commit-graph file.
- */
- int GENERATION_NUMBER_INFINITY = -1;
-
- /**
- * If a commit-graph file was written by a version of Git that did not
- * compute generation numbers, then those commits will have generation
- * number represented by GENERATION_NUMBER_ZERO(0).
- */
- int GENERATION_NUMBER_ZERO = 0;
-
- /**
- * Get the metadata of a commit.
- *
- * @param commit
- * the commit object id to inspect.
- * @return the metadata of a commit or null if it's not found.
- */
- CommitData getCommitData(AnyObjectId commit);
-
- /**
- * Get the metadata of a commit。
- *
- * @param graphPos
- * the position in the commit-graph of the object.
- * @return the metadata of a commit or null if it's not found.
- */
- CommitData getCommitData(int graphPos);
-
- /**
- * Get the object at the commit-graph position.
- *
- * @param graphPos
- * the position in the commit-graph of the object.
- * @return the ObjectId or null if it's not found.
- */
- ObjectId getObjectId(int graphPos);
-
- /**
- * Obtain the total number of commits described by this commit-graph.
- *
- * @return number of commits in this commit-graph
- */
- long getCommitCnt();
-
- /**
- * Metadata of a commit in commit data chunk.
- */
- interface CommitData {
-
- /**
- * Get a reference to this commit's tree.
- *
- * @return tree of this commit.
- */
- ObjectId getTree();
-
- /**
- * Obtain an array of all parents.
- * <p>
- * The method only provides the positions of parents in commit-graph,
- * call {@link CommitGraph#getObjectId(int)} to get the real objectId.
- *
- * @return the array of parents.
- */
- int[] getParents();
-
- /**
- * Time from the "committer" line.
- *
- * @return commit time
- */
- long getCommitTime();
-
- /**
- * Get the generation number of the commit.
- * <p>
- * If A and B are commits with generation numbers N and M, respectively,
- * and N <= M, then A cannot reach B. That is, we know without searching
- * that B is not an ancestor of A because it is further from a root
- * commit than A.
- * <p>
- * Conversely, when checking if A is an ancestor of B, then we only need
- * to walk commits until all commits on the walk boundary have
- * generation number at most N. If we walk commits using a priority
- * queue seeded by generation numbers, then we always expand the
- * boundary commit with highest generation number and can easily detect
- * the stopping condition.
- * <p>
- * We use {@value #GENERATION_NUMBER_INFINITY} to mark commits not in
- * the commit-graph file. If a commit-graph file was written without
- * computing generation numbers, then those commits will have generation
- * number represented by {@value #GENERATION_NUMBER_ZERO}.
- *
- * @return the generation number
- */
- int getGeneration();
- }
- }
|