|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* diff-delta code taken from git.git. See diff-delta.c for details.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
#ifndef INCLUDE_git_delta_h__
|
|
Packit Service |
20376f |
#define INCLUDE_git_delta_h__
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#include "common.h"
|
|
Packit Service |
20376f |
#include "pack.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
typedef struct git_delta_index git_delta_index;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* git_delta_index_init: compute index data from given buffer
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* This returns a pointer to a struct delta_index that should be passed to
|
|
Packit Service |
20376f |
* subsequent create_delta() calls, or to free_delta_index(). A NULL pointer
|
|
Packit Service |
20376f |
* is returned on failure. The given buffer must not be freed nor altered
|
|
Packit Service |
20376f |
* before free_delta_index() is called. The returned pointer must be freed
|
|
Packit Service |
20376f |
* using free_delta_index().
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
extern int git_delta_index_init(
|
|
Packit Service |
20376f |
git_delta_index **out, const void *buf, size_t bufsize);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* Free the index created by git_delta_index_init()
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
extern void git_delta_index_free(git_delta_index *index);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* Returns memory usage of delta index.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
extern size_t git_delta_index_size(git_delta_index *index);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* create_delta: create a delta from given index for the given buffer
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* This function may be called multiple times with different buffers using
|
|
Packit Service |
20376f |
* the same delta_index pointer. If max_delta_size is non-zero and the
|
|
Packit Service |
20376f |
* resulting delta is to be larger than max_delta_size then NULL is returned.
|
|
Packit Service |
20376f |
* On success, a non-NULL pointer to the buffer with the delta data is
|
|
Packit Service |
20376f |
* returned and *delta_size is updated with its size. The returned buffer
|
|
Packit Service |
20376f |
* must be freed by the caller.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
extern int git_delta_create_from_index(
|
|
Packit Service |
20376f |
void **out,
|
|
Packit Service |
20376f |
size_t *out_size,
|
|
Packit Service |
20376f |
const struct git_delta_index *index,
|
|
Packit Service |
20376f |
const void *buf,
|
|
Packit Service |
20376f |
size_t bufsize,
|
|
Packit Service |
20376f |
size_t max_delta_size);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* diff_delta: create a delta from source buffer to target buffer
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* If max_delta_size is non-zero and the resulting delta is to be larger
|
|
Packit Service |
20376f |
* than max_delta_size then GIT_EBUFS is returned. On success, a non-NULL
|
|
Packit Service |
20376f |
* pointer to the buffer with the delta data is returned and *delta_size is
|
|
Packit Service |
20376f |
* updated with its size. The returned buffer must be freed by the caller.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
GIT_INLINE(int) git_delta(
|
|
Packit Service |
20376f |
void **out, size_t *out_len,
|
|
Packit Service |
20376f |
const void *src_buf, size_t src_bufsize,
|
|
Packit Service |
20376f |
const void *trg_buf, size_t trg_bufsize,
|
|
Packit Service |
20376f |
size_t max_delta_size)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
git_delta_index *index;
|
|
Packit Service |
20376f |
int error = 0;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
*out = NULL;
|
|
Packit Service |
20376f |
*out_len = 0;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if ((error = git_delta_index_init(&index, src_buf, src_bufsize)) < 0)
|
|
Packit Service |
20376f |
return error;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (index) {
|
|
Packit Service |
20376f |
error = git_delta_create_from_index(out, out_len,
|
|
Packit Service |
20376f |
index, trg_buf, trg_bufsize, max_delta_size);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_delta_index_free(index);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return error;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* the smallest possible delta size is 4 bytes */
|
|
Packit Service |
20376f |
#define GIT_DELTA_SIZE_MIN 4
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Apply a git binary delta to recover the original content.
|
|
Packit Service |
20376f |
* The caller is responsible for freeing the returned buffer.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param out the output buffer
|
|
Packit Service |
20376f |
* @param out_len the length of the output buffer
|
|
Packit Service |
20376f |
* @param base the base to copy from during copy instructions.
|
|
Packit Service |
20376f |
* @param base_len number of bytes available at base.
|
|
Packit Service |
20376f |
* @param delta the delta to execute copy/insert instructions from.
|
|
Packit Service |
20376f |
* @param delta_len total number of bytes in the delta.
|
|
Packit Service |
20376f |
* @return 0 on success or an error code
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
extern int git_delta_apply(
|
|
Packit Service |
20376f |
void **out,
|
|
Packit Service |
20376f |
size_t *out_len,
|
|
Packit Service |
20376f |
const unsigned char *base,
|
|
Packit Service |
20376f |
size_t base_len,
|
|
Packit Service |
20376f |
const unsigned char *delta,
|
|
Packit Service |
20376f |
size_t delta_len);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Read the header of a git binary delta.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* @param base_out pointer to store the base size field.
|
|
Packit Service |
20376f |
* @param result_out pointer to store the result size field.
|
|
Packit Service |
20376f |
* @param delta the delta to execute copy/insert instructions from.
|
|
Packit Service |
20376f |
* @param delta_len total number of bytes in the delta.
|
|
Packit Service |
20376f |
* @return 0 on success or an error code
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
extern int git_delta_read_header(
|
|
Packit Service |
20376f |
size_t *base_out,
|
|
Packit Service |
20376f |
size_t *result_out,
|
|
Packit Service |
20376f |
const unsigned char *delta,
|
|
Packit Service |
20376f |
size_t delta_len);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Read the header of a git binary delta
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* This variant reads just enough from the packfile stream to read the
|
|
Packit Service |
20376f |
* delta header.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
extern int git_delta_read_header_fromstream(
|
|
Packit Service |
20376f |
size_t *base_out,
|
|
Packit Service |
20376f |
size_t *result_out,
|
|
Packit Service |
20376f |
git_packfile_stream *stream);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#endif
|