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.

commit-graph.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef COMMIT_GRAPH_H
  2. #define COMMIT_GRAPH_H
  3. #include "git-compat-util.h"
  4. #include "repository.h"
  5. #include "string-list.h"
  6. #include "cache.h"
  7. #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
  8. #define GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD "GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD"
  9. struct commit;
  10. char *get_commit_graph_filename(const char *obj_dir);
  11. int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
  12. /*
  13. * Given a commit struct, try to fill the commit struct info, including:
  14. * 1. tree object
  15. * 2. date
  16. * 3. parents.
  17. *
  18. * Returns 1 if and only if the commit was found in the packed graph.
  19. *
  20. * See parse_commit_buffer() for the fallback after this call.
  21. */
  22. int parse_commit_in_graph(struct repository *r, struct commit *item);
  23. /*
  24. * It is possible that we loaded commit contents from the commit buffer,
  25. * but we also want to ensure the commit-graph content is correctly
  26. * checked and filled. Fill the graph_pos and generation members of
  27. * the given commit.
  28. */
  29. void load_commit_graph_info(struct repository *r, struct commit *item);
  30. struct tree *get_commit_tree_in_graph(struct repository *r,
  31. const struct commit *c);
  32. struct commit_graph {
  33. int graph_fd;
  34. const unsigned char *data;
  35. size_t data_len;
  36. unsigned char hash_len;
  37. unsigned char num_chunks;
  38. uint32_t num_commits;
  39. struct object_id oid;
  40. char *filename;
  41. const char *obj_dir;
  42. uint32_t num_commits_in_base;
  43. struct commit_graph *base_graph;
  44. const uint32_t *chunk_oid_fanout;
  45. const unsigned char *chunk_oid_lookup;
  46. const unsigned char *chunk_commit_data;
  47. const unsigned char *chunk_extra_edges;
  48. const unsigned char *chunk_base_graphs;
  49. };
  50. struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st);
  51. struct commit_graph *read_commit_graph_one(struct repository *r, const char *obj_dir);
  52. struct commit_graph *parse_commit_graph(void *graph_map, int fd,
  53. size_t graph_size);
  54. /*
  55. * Return 1 if and only if the repository has a commit-graph
  56. * file and generation numbers are computed in that file.
  57. */
  58. int generation_numbers_enabled(struct repository *r);
  59. enum commit_graph_write_flags {
  60. COMMIT_GRAPH_WRITE_APPEND = (1 << 0),
  61. COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),
  62. COMMIT_GRAPH_WRITE_SPLIT = (1 << 2),
  63. /* Make sure that each OID in the input is a valid commit OID. */
  64. COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3)
  65. };
  66. struct split_commit_graph_opts {
  67. int size_multiple;
  68. int max_commits;
  69. timestamp_t expire_time;
  70. };
  71. /*
  72. * The write_commit_graph* methods return zero on success
  73. * and a negative value on failure. Note that if the repository
  74. * is not compatible with the commit-graph feature, then the
  75. * methods will return 0 without writing a commit-graph.
  76. */
  77. int write_commit_graph_reachable(const char *obj_dir,
  78. enum commit_graph_write_flags flags,
  79. const struct split_commit_graph_opts *split_opts);
  80. int write_commit_graph(const char *obj_dir,
  81. struct string_list *pack_indexes,
  82. struct string_list *commit_hex,
  83. enum commit_graph_write_flags flags,
  84. const struct split_commit_graph_opts *split_opts);
  85. #define COMMIT_GRAPH_VERIFY_SHALLOW (1 << 0)
  86. int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
  87. void close_commit_graph(struct raw_object_store *);
  88. void free_commit_graph(struct commit_graph *);
  89. #endif