Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:36

0001 /*
0002  * Copyright (C) the libgit2 contributors. All rights reserved.
0003  *
0004  * This file is part of libgit2, distributed under the GNU GPL v2 with
0005  * a Linking Exception. For full terms see the included COPYING file.
0006  */
0007 #ifndef INCLUDE_sys_git_commit_graph_h__
0008 #define INCLUDE_sys_git_commit_graph_h__
0009 
0010 #include "git2/common.h"
0011 #include "git2/types.h"
0012 
0013 /**
0014  * @file git2/sys/commit_graph.h
0015  * @brief Git commit-graph
0016  * @defgroup git_commit_graph Git commit-graph APIs
0017  * @ingroup Git
0018  * @{
0019  */
0020 GIT_BEGIN_DECL
0021 
0022 /**
0023  * Opens a `git_commit_graph` from a path to an objects directory.
0024  *
0025  * This finds, opens, and validates the `commit-graph` file.
0026  *
0027  * @param cgraph_out the `git_commit_graph` struct to initialize.
0028  * @param objects_dir the path to a git objects directory.
0029  * @return Zero on success; -1 on failure.
0030  */
0031 GIT_EXTERN(int) git_commit_graph_open(
0032     git_commit_graph **cgraph_out,
0033     const char *objects_dir
0034 #ifdef GIT_EXPERIMENTAL_SHA256
0035     , git_oid_t oid_type
0036 #endif
0037     );
0038 
0039 /**
0040  * Frees commit-graph data. This should only be called when memory allocated
0041  * using `git_commit_graph_open` is not returned to libgit2 because it was not
0042  * associated with the ODB through a successful call to
0043  * `git_odb_set_commit_graph`.
0044  *
0045  * @param cgraph the commit-graph object to free. If NULL, no action is taken.
0046  */
0047 GIT_EXTERN(void) git_commit_graph_free(git_commit_graph *cgraph);
0048 
0049 /**
0050  * Create a new writer for `commit-graph` files.
0051  *
0052  * @param out Location to store the writer pointer.
0053  * @param objects_info_dir The `objects/info` directory.
0054  * The `commit-graph` file will be written in this directory.
0055  * @return 0 or an error code
0056  */
0057 GIT_EXTERN(int) git_commit_graph_writer_new(
0058         git_commit_graph_writer **out,
0059         const char *objects_info_dir
0060 #ifdef GIT_EXPERIMENTAL_SHA256
0061     , git_oid_t oid_type
0062 #endif
0063         );
0064 
0065 /**
0066  * Free the commit-graph writer and its resources.
0067  *
0068  * @param w The writer to free. If NULL no action is taken.
0069  */
0070 GIT_EXTERN(void) git_commit_graph_writer_free(git_commit_graph_writer *w);
0071 
0072 /**
0073  * Add an `.idx` file (associated to a packfile) to the writer.
0074  *
0075  * @param w The writer.
0076  * @param repo The repository that owns the `.idx` file.
0077  * @param idx_path The path of an `.idx` file.
0078  * @return 0 or an error code
0079  */
0080 GIT_EXTERN(int) git_commit_graph_writer_add_index_file(
0081         git_commit_graph_writer *w,
0082         git_repository *repo,
0083         const char *idx_path);
0084 
0085 /**
0086  * Add a revwalk to the writer. This will add all the commits from the revwalk
0087  * to the commit-graph.
0088  *
0089  * @param w The writer.
0090  * @param walk The git_revwalk.
0091  * @return 0 or an error code
0092  */
0093 GIT_EXTERN(int) git_commit_graph_writer_add_revwalk(
0094         git_commit_graph_writer *w,
0095         git_revwalk *walk);
0096 
0097 
0098 /**
0099  * The strategy to use when adding a new set of commits to a pre-existing
0100  * commit-graph chain.
0101  */
0102 typedef enum {
0103     /**
0104      * Do not split commit-graph files. The other split strategy-related option
0105      * fields are ignored.
0106      */
0107     GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0
0108 } git_commit_graph_split_strategy_t;
0109 
0110 /**
0111  * Options structure for
0112  * `git_commit_graph_writer_commit`/`git_commit_graph_writer_dump`.
0113  *
0114  * Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively, you
0115  * can use `git_commit_graph_writer_options_init`.
0116  */
0117 typedef struct {
0118     unsigned int version;
0119 
0120     /**
0121      * The strategy to use when adding new commits to a pre-existing commit-graph
0122      * chain.
0123      */
0124     git_commit_graph_split_strategy_t split_strategy;
0125 
0126     /**
0127      * The number of commits in level N is less than X times the number of
0128      * commits in level N + 1. Default is 2.
0129      */
0130     float size_multiple;
0131 
0132     /**
0133      * The number of commits in level N + 1 is more than C commits.
0134      * Default is 64000.
0135      */
0136     size_t max_commits;
0137 } git_commit_graph_writer_options;
0138 
0139 #define GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION 1
0140 #define GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT { \
0141         GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION \
0142     }
0143 
0144 /**
0145  * Initialize git_commit_graph_writer_options structure
0146  *
0147  * Initializes a `git_commit_graph_writer_options` with default values. Equivalent to
0148  * creating an instance with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`.
0149  *
0150  * @param opts The `git_commit_graph_writer_options` struct to initialize.
0151  * @param version The struct version; pass `GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION`.
0152  * @return Zero on success; -1 on failure.
0153  */
0154 GIT_EXTERN(int) git_commit_graph_writer_options_init(
0155     git_commit_graph_writer_options *opts,
0156     unsigned int version);
0157 
0158 /**
0159  * Write a `commit-graph` file to a file.
0160  *
0161  * @param w The writer
0162  * @param opts Pointer to git_commit_graph_writer_options struct.
0163  * @return 0 or an error code
0164  */
0165 GIT_EXTERN(int) git_commit_graph_writer_commit(
0166         git_commit_graph_writer *w,
0167         git_commit_graph_writer_options *opts);
0168 
0169 /**
0170  * Dump the contents of the `commit-graph` to an in-memory buffer.
0171  *
0172  * @param buffer Buffer where to store the contents of the `commit-graph`.
0173  * @param w The writer.
0174  * @param opts Pointer to git_commit_graph_writer_options struct.
0175  * @return 0 or an error code
0176  */
0177 GIT_EXTERN(int) git_commit_graph_writer_dump(
0178         git_buf *buffer,
0179         git_commit_graph_writer *w,
0180         git_commit_graph_writer_options *opts);
0181 
0182 /** @} */
0183 GIT_END_DECL
0184 #endif