You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommitGraphSingleImpl.java 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2021, Tencent.
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.internal.storage.commitgraph;
  11. import org.eclipse.jgit.lib.AnyObjectId;
  12. import org.eclipse.jgit.lib.CommitGraph;
  13. import org.eclipse.jgit.lib.ObjectId;
  14. /**
  15. * CommitGraph implementation by a single commit-graph file.
  16. *
  17. * @see CommitGraph
  18. */
  19. public class CommitGraphSingleImpl implements CommitGraph {
  20. private final CommitGraphData graphData;
  21. /**
  22. * Creates CommitGraph by a single commit-graph file.
  23. *
  24. * @param graphData
  25. * the commit-graph file in memory
  26. */
  27. public CommitGraphSingleImpl(CommitGraphData graphData) {
  28. this.graphData = graphData;
  29. }
  30. /** {@inheritDoc} */
  31. @Override
  32. public CommitData getCommitData(AnyObjectId commit) {
  33. int graphPos = graphData.findGraphPosition(commit);
  34. return getCommitData(graphPos);
  35. }
  36. /** {@inheritDoc} */
  37. @Override
  38. public CommitData getCommitData(int graphPos) {
  39. if (graphPos < 0 || graphPos > graphData.getCommitCnt()) {
  40. return null;
  41. }
  42. return graphData.getCommitData(graphPos);
  43. }
  44. /** {@inheritDoc} */
  45. @Override
  46. public ObjectId getObjectId(int graphPos) {
  47. return graphData.getObjectId(graphPos);
  48. }
  49. /** {@inheritDoc} */
  50. @Override
  51. public long getCommitCnt() {
  52. return graphData.getCommitCnt();
  53. }
  54. }