Blame include/git2/pack.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_git_pack_h__
Packit Service 20376f
#define INCLUDE_git_pack_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "oid.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/pack.h
Packit Service 20376f
 * @brief Git pack management routines
Packit Service 20376f
 *
Packit Service 20376f
 * Packing objects
Packit Service 20376f
 * ---------------
Packit Service 20376f
 *
Packit Service 20376f
 * Creation of packfiles requires two steps:
Packit Service 20376f
 *
Packit Service 20376f
 * - First, insert all the objects you want to put into the packfile
Packit Service 20376f
 *   using `git_packbuilder_insert` and `git_packbuilder_insert_tree`.
Packit Service 20376f
 *   It's important to add the objects in recency order ("in the order
Packit Service 20376f
 *   that they are 'reachable' from head").
Packit Service 20376f
 *
Packit Service 20376f
 *   "ANY order will give you a working pack, ... [but it is] the thing
Packit Service 20376f
 *   that gives packs good locality. It keeps the objects close to the
Packit Service 20376f
 *   head (whether they are old or new, but they are _reachable_ from the
Packit Service 20376f
 *   head) at the head of the pack. So packs actually have absolutely
Packit Service 20376f
 *   _wonderful_ IO patterns." - Linus Torvalds
Packit Service 20376f
 *   git.git/Documentation/technical/pack-heuristics.txt
Packit Service 20376f
 *
Packit Service 20376f
 * - Second, use `git_packbuilder_write` or `git_packbuilder_foreach` to
Packit Service 20376f
 *   write the resulting packfile.
Packit Service 20376f
 *
Packit Service 20376f
 *   libgit2 will take care of the delta ordering and generation.
Packit Service 20376f
 *   `git_packbuilder_set_threads` can be used to adjust the number of
Packit Service 20376f
 *   threads used for the process.
Packit Service 20376f
 *
Packit Service 20376f
 * See tests/pack/packbuilder.c for an example.
Packit Service 20376f
 *
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Stages that are reported by the packbuilder progress callback.
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	GIT_PACKBUILDER_ADDING_OBJECTS = 0,
Packit Service 20376f
	GIT_PACKBUILDER_DELTAFICATION = 1,
Packit Service 20376f
} git_packbuilder_stage_t;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initialize a new packbuilder
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The new packbuilder object
Packit Service 20376f
 * @param repo The repository
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_new(git_packbuilder **out, git_repository *repo);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set number of threads to spawn
Packit Service 20376f
 *
Packit Service 20376f
 * By default, libgit2 won't spawn any threads at all;
Packit Service 20376f
 * when set to 0, libgit2 will autodetect the number of
Packit Service 20376f
 * CPUs.
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb The packbuilder
Packit Service 20376f
 * @param n Number of threads to spawn
Packit Service 20376f
 * @return number of actual threads to be used
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(unsigned int) git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Insert a single object
Packit Service 20376f
 *
Packit Service 20376f
 * For an optimal pack it's mandatory to insert objects in recency order,
Packit Service 20376f
 * commits followed by trees and blobs.
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb The packbuilder
Packit Service 20376f
 * @param id The oid of the commit
Packit Service 20376f
 * @param name The name; might be NULL
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_insert(git_packbuilder *pb, const git_oid *id, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Insert a root tree object
Packit Service 20376f
 *
Packit Service 20376f
 * This will add the tree as well as all referenced trees and blobs.
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb The packbuilder
Packit Service 20376f
 * @param id The oid of the root tree
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *id);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Insert a commit object
Packit Service 20376f
 *
Packit Service 20376f
 * This will add a commit as well as the completed referenced tree.
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb The packbuilder
Packit Service 20376f
 * @param id The oid of the commit
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *id);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Insert objects as given by the walk
Packit Service 20376f
 *
Packit Service 20376f
 * Those commits and all objects they reference will be inserted into
Packit Service 20376f
 * the packbuilder.
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb the packbuilder
Packit Service 20376f
 * @param walk the revwalk to use to fill the packbuilder
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Recursively insert an object and its referenced objects
Packit Service 20376f
 *
Packit Service 20376f
 * Insert the object as well as any object it references.
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb the packbuilder
Packit Service 20376f
 * @param id the id of the root object to insert
Packit Service 20376f
 * @param name optional name for the object
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Write the contents of the packfile to an in-memory buffer
Packit Service 20376f
 *
Packit Service 20376f
 * The contents of the buffer will become a valid packfile, even though there
Packit Service 20376f
 * will be no attached index
Packit Service 20376f
 *
Packit Service 20376f
 * @param buf Buffer where to write the packfile
Packit Service 20376f
 * @param pb The packbuilder
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Write the new pack and corresponding index file to path.
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb The packbuilder
Packit Service 20376f
 * @param path to the directory where the packfile and index should be stored
Packit Service 20376f
 * @param mode permissions to use creating a packfile or 0 for defaults
Packit Service 20376f
 * @param progress_cb function to call with progress information from the indexer (optional)
Packit Service 20376f
 * @param progress_cb_payload payload for the progress callback (optional)
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_write(
Packit Service 20376f
	git_packbuilder *pb,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	unsigned int mode,
Packit Service 20376f
	git_transfer_progress_cb progress_cb,
Packit Service 20376f
	void *progress_cb_payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
* Get the packfile's hash
Packit Service 20376f
*
Packit Service 20376f
* A packfile's name is derived from the sorted hashing of all object
Packit Service 20376f
* names. This is only correct after the packfile has been written.
Packit Service 20376f
*
Packit Service 20376f
* @param pb The packbuilder object
Packit Service 20376f
*/
Packit Service 20376f
GIT_EXTERN(const git_oid *) git_packbuilder_hash(git_packbuilder *pb);
Packit Service 20376f
Packit Service 20376f
typedef int (*git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create the new pack and pass each object to the callback
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb the packbuilder
Packit Service 20376f
 * @param cb the callback to call with each packed object's buffer
Packit Service 20376f
 * @param payload the callback's data
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_foreach(git_packbuilder *pb, git_packbuilder_foreach_cb cb, void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the total number of objects the packbuilder will write out
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb the packbuilder
Packit Service 20376f
 * @return the number of objects in the packfile
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(size_t) git_packbuilder_object_count(git_packbuilder *pb);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the number of objects the packbuilder has already written out
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb the packbuilder
Packit Service 20376f
 * @return the number of objects which have already been written
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(size_t) git_packbuilder_written(git_packbuilder *pb);
Packit Service 20376f
Packit Service 20376f
/** Packbuilder progress notification function */
Packit Service 20376f
typedef int (*git_packbuilder_progress)(
Packit Service 20376f
	int stage,
Packit Service 20376f
	uint32_t current,
Packit Service 20376f
	uint32_t total,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the callbacks for a packbuilder
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb The packbuilder object
Packit Service 20376f
 * @param progress_cb Function to call with progress information during
Packit Service 20376f
 * pack building. Be aware that this is called inline with pack building
Packit Service 20376f
 * operations, so performance may be affected.
Packit Service 20376f
 * @param progress_cb_payload Payload for progress callback.
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_packbuilder_set_callbacks(
Packit Service 20376f
	git_packbuilder *pb,
Packit Service 20376f
	git_packbuilder_progress progress_cb,
Packit Service 20376f
	void *progress_cb_payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free the packbuilder and all associated data
Packit Service 20376f
 *
Packit Service 20376f
 * @param pb The packbuilder
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_packbuilder_free(git_packbuilder *pb);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif