summaryrefslogtreecommitdiff
path: root/include/git2
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-08-29 21:30:51 -0400
committerGitHub <noreply@github.com>2021-08-29 21:30:51 -0400
commit78cd76249cb32e65860156f758d33264bf3db766 (patch)
tree4dc102b5a6e72fe552fb5945b55e50dc4e9605cb /include/git2
parent0a79012e9df33db31046c653ab04c69eaeed200a (diff)
parente66545e30fe862d6c2ccfc06275fcadd0dce0953 (diff)
downloadlibgit2-78cd76249cb32e65860156f758d33264bf3db766.tar.gz
Merge pull request #5404 from lhchavez/multi-pack-index-write
midx: Add a way to write multi-pack-index files
Diffstat (limited to 'include/git2')
-rw-r--r--include/git2/sys/midx.h74
-rw-r--r--include/git2/types.h3
2 files changed, 77 insertions, 0 deletions
diff --git a/include/git2/sys/midx.h b/include/git2/sys/midx.h
new file mode 100644
index 000000000..e3d749829
--- /dev/null
+++ b/include/git2/sys/midx.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_sys_git_midx_h__
+#define INCLUDE_sys_git_midx_h__
+
+#include "git2/common.h"
+#include "git2/types.h"
+
+/**
+ * @file git2/midx.h
+ * @brief Git multi-pack-index routines
+ * @defgroup git_midx Git multi-pack-index routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Create a new writer for `multi-pack-index` files.
+ *
+ * @param out location to store the writer pointer.
+ * @param pack_dir the directory where the `.pack` and `.idx` files are. The
+ * `multi-pack-index` file will be written in this directory, too.
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_midx_writer_new(
+ git_midx_writer **out,
+ const char *pack_dir);
+
+/**
+ * Free the multi-pack-index writer and its resources.
+ *
+ * @param w the writer to free. If NULL no action is taken.
+ */
+GIT_EXTERN(void) git_midx_writer_free(git_midx_writer *w);
+
+/**
+ * Add an `.idx` file to the writer.
+ *
+ * @param w the writer
+ * @param idx_path the path of an `.idx` file.
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_midx_writer_add(
+ git_midx_writer *w,
+ const char *idx_path);
+
+/**
+ * Write a `multi-pack-index` file to a file.
+ *
+ * @param w the writer
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_midx_writer_commit(
+ git_midx_writer *w);
+
+/**
+ * Dump the contents of the `multi-pack-index` to an in-memory buffer.
+ *
+ * @param midx Buffer where to store the contents of the `multi-pack-index`.
+ * @param w the writer
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_midx_writer_dump(
+ git_buf *midx,
+ git_midx_writer *w);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/types.h b/include/git2/types.h
index 562eb8e5f..4de0672f9 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -96,6 +96,9 @@ typedef struct git_odb_stream git_odb_stream;
/** A stream to write a packfile to the ODB */
typedef struct git_odb_writepack git_odb_writepack;
+/** a writer for multi-pack-index files. */
+typedef struct git_midx_writer git_midx_writer;
+
/** An open refs database handle. */
typedef struct git_refdb git_refdb;