Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93ab8d8

Browse files
committed
commit-graph: Add a way to write commit-graph files
This change adds the git_commit_graph_writer_* functions to allow to write and create `commit-graph` files from `.idx`/`.pack` files or `git_revwalk`s. Part of: #5757
1 parent 744c6bb commit 93ab8d8

File tree

5 files changed

+778
-1
lines changed

5 files changed

+778
-1
lines changed

include/git2/sys/commit_graph.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
#ifndef INCLUDE_sys_git_commit_graph_h__
8+
#define INCLUDE_sys_git_commit_graph_h__
9+
10+
#include "git2/common.h"
11+
#include "git2/types.h"
12+
13+
/**
14+
* @file git2/commit_graph.h
15+
* @brief Git commit-graph routines
16+
* @defgroup git_commit_graph Git commit-graph routines
17+
* @ingroup Git
18+
* @{
19+
*/
20+
GIT_BEGIN_DECL
21+
22+
/**
23+
* Create a new writer for `commit-graph` files.
24+
*
25+
* @param out location to store the writer pointer
26+
* @param objects_info_dir the `objects/info` directory.
27+
* The `commit-graph` file will be written in this directory.
28+
* @return 0 or an error code
29+
*/
30+
GIT_EXTERN(int) git_commit_graph_writer_new(
31+
git_commit_graph_writer **out,
32+
const char *objects_info_dir);
33+
34+
/**
35+
* Free the commit-graph writer and its resources.
36+
*
37+
* @param w the writer to free. If NULL no action is taken.
38+
*/
39+
GIT_EXTERN(void) git_commit_graph_writer_free(git_commit_graph_writer *w);
40+
41+
/**
42+
* Add an `.idx` file (associated to a packfile) to the writer.
43+
*
44+
* @param w the writer
45+
* @param repo the repository that owns the `.idx` file
46+
* @param idx_path the path of an `.idx` file
47+
* @return 0 or an error code
48+
*/
49+
GIT_EXTERN(int) git_commit_graph_writer_add_index_file(
50+
git_commit_graph_writer *w,
51+
git_repository *repo,
52+
const char *idx_path);
53+
54+
/**
55+
* Add a revwalk to the writer. This will add all the commits from the revwalk
56+
* to the commit-graph.
57+
*
58+
* @param w the writer
59+
* @param walk the git_revwalk
60+
* @return 0 or an error code
61+
*/
62+
GIT_EXTERN(int) git_commit_graph_writer_add_revwalk(
63+
git_commit_graph_writer *w,
64+
git_revwalk *walk);
65+
66+
/**
67+
* Write a `commit-graph` file to a file.
68+
*
69+
* @param w the writer
70+
* @return 0 or an error code
71+
*/
72+
GIT_EXTERN(int) git_commit_graph_writer_commit(
73+
git_commit_graph_writer *w);
74+
75+
/**
76+
* Dump the contents of the `commit-graph` to an in-memory buffer.
77+
*
78+
* @param buffer buffer where to store the contents of the `commit-graph`.
79+
* @param w the writer
80+
* @return 0 or an error code
81+
*/
82+
GIT_EXTERN(int) git_commit_graph_writer_dump(
83+
git_buf *buffer,
84+
git_commit_graph_writer *w);
85+
86+
/** @} */
87+
GIT_END_DECL
88+
#endif

include/git2/types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ typedef struct git_odb_stream git_odb_stream;
9696
/** A stream to write a packfile to the ODB */
9797
typedef struct git_odb_writepack git_odb_writepack;
9898

99+
/** a writer for commit-graph files. */
100+
typedef struct git_commit_graph_writer git_commit_graph_writer;
101+
99102
/** An open refs database handle. */
100103
typedef struct git_refdb git_refdb;
101104

0 commit comments

Comments
 (0)