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

Skip to content

Commit fff209c

Browse files
committed
midx: Add a way to write multi-pack-index files
This change adds the git_midx_writer_* functions to allow to write and create `multi-pack-index` files from `.idx`/`.pack` files. Part of: #5399
1 parent 2370e49 commit fff209c

File tree

7 files changed

+601
-0
lines changed

7 files changed

+601
-0
lines changed

include/git2/sys/midx.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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_midx_h__
8+
#define INCLUDE_sys_git_midx_h__
9+
10+
#include "git2/common.h"
11+
#include "git2/types.h"
12+
13+
/**
14+
* @file git2/midx.h
15+
* @brief Git multi-pack-index routines
16+
* @defgroup git_midx Git multi-pack-index routines
17+
* @ingroup Git
18+
* @{
19+
*/
20+
GIT_BEGIN_DECL
21+
22+
/**
23+
* Create a new writer for `multi-pack-index` files.
24+
*
25+
* @param out location to store the writer pointer.
26+
* @param pack_dir the directory where the `.pack` and `.idx` files are. The
27+
* `multi-pack-index` file will be written in this directory, too.
28+
* @return 0 or an error code
29+
*/
30+
GIT_EXTERN(int) git_midx_writer_new(
31+
git_midx_writer **out,
32+
const char *pack_dir);
33+
34+
/**
35+
* Free the multi-pack-index writer and its resources.
36+
*
37+
* @param w the writer to free. If NULL no action is taken.
38+
*/
39+
GIT_EXTERN(void) git_midx_writer_free(git_midx_writer *w);
40+
41+
/**
42+
* Add an `.idx` file to the writer.
43+
*
44+
* @param w the writer
45+
* @param idx_path the path of an `.idx` file.
46+
* @return 0 or an error code
47+
*/
48+
GIT_EXTERN(int) git_midx_writer_add(
49+
git_midx_writer *w,
50+
const char *idx_path);
51+
52+
/**
53+
* Write a `multi-pack-index` file to a file.
54+
*
55+
* @param w the writer
56+
* @return 0 or an error code
57+
*/
58+
GIT_EXTERN(int) git_midx_writer_commit(
59+
git_midx_writer *w);
60+
61+
/**
62+
* Dump the contents of the `multi-pack-index` to an in-memory buffer.
63+
*
64+
* @param midx Buffer where to store the contents of the `multi-pack-index`.
65+
* @param w the writer
66+
* @return 0 or an error code
67+
*/
68+
GIT_EXTERN(int) git_midx_writer_dump(
69+
git_buf *midx,
70+
git_midx_writer *w);
71+
72+
/** @} */
73+
GIT_END_DECL
74+
#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 multi-pack-index files. */
100+
typedef struct git_midx_writer git_midx_writer;
101+
99102
/** An open refs database handle. */
100103
typedef struct git_refdb git_refdb;
101104

0 commit comments

Comments
 (0)