mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 23:26:39 +00:00
git_writestream: from git_filter_stream
This commit is contained in:
parent
8c2dfb38db
commit
b75f15aaf1
@ -140,18 +140,18 @@ GIT_EXTERN(int) git_filter_list_apply_to_blob(
|
|||||||
GIT_EXTERN(int) git_filter_list_stream_data(
|
GIT_EXTERN(int) git_filter_list_stream_data(
|
||||||
git_filter_list *filters,
|
git_filter_list *filters,
|
||||||
git_buf *data,
|
git_buf *data,
|
||||||
git_filter_stream *target);
|
git_writestream *target);
|
||||||
|
|
||||||
GIT_EXTERN(int) git_filter_list_stream_file(
|
GIT_EXTERN(int) git_filter_list_stream_file(
|
||||||
git_filter_list *filters,
|
git_filter_list *filters,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
const char *path,
|
const char *path,
|
||||||
git_filter_stream *target);
|
git_writestream *target);
|
||||||
|
|
||||||
GIT_EXTERN(int) git_filter_list_stream_blob(
|
GIT_EXTERN(int) git_filter_list_stream_blob(
|
||||||
git_filter_list *filters,
|
git_filter_list *filters,
|
||||||
git_blob *blob,
|
git_blob *blob,
|
||||||
git_filter_stream *target);
|
git_writestream *target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free a git_filter_list
|
* Free a git_filter_list
|
||||||
|
@ -208,18 +208,12 @@ typedef int (*git_filter_apply_fn)(
|
|||||||
const git_buf *from,
|
const git_buf *from,
|
||||||
const git_filter_source *src);
|
const git_filter_source *src);
|
||||||
|
|
||||||
struct git_filter_stream {
|
|
||||||
int (*write)(git_filter_stream *stream, const char *buffer, size_t len);
|
|
||||||
int (*close)(git_filter_stream *stream);
|
|
||||||
void (*free)(git_filter_stream *stream);
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef int (*git_filter_stream_fn)(
|
typedef int (*git_filter_stream_fn)(
|
||||||
git_filter_stream **out,
|
git_writestream **out,
|
||||||
git_filter *self,
|
git_filter *self,
|
||||||
void **payload,
|
void **payload,
|
||||||
const git_filter_source *src,
|
const git_filter_source *src,
|
||||||
git_filter_stream *next);
|
git_writestream *next);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to clean up after filtering has been applied
|
* Callback to clean up after filtering has been applied
|
||||||
|
@ -410,8 +410,14 @@ typedef enum {
|
|||||||
GIT_SUBMODULE_RECURSE_ONDEMAND = 2,
|
GIT_SUBMODULE_RECURSE_ONDEMAND = 2,
|
||||||
} git_submodule_recurse_t;
|
} git_submodule_recurse_t;
|
||||||
|
|
||||||
/** A stream to write filters. */
|
/** A type to write in a streaming fashion, for example, for filters. */
|
||||||
typedef struct git_filter_stream git_filter_stream;
|
typedef struct git_writestream git_writestream;
|
||||||
|
|
||||||
|
struct git_writestream {
|
||||||
|
int (*write)(git_writestream *stream, const char *buffer, size_t len);
|
||||||
|
int (*close)(git_writestream *stream);
|
||||||
|
void (*free)(git_writestream *stream);
|
||||||
|
};
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
GIT_END_DECL
|
GIT_END_DECL
|
||||||
|
@ -1373,14 +1373,14 @@ static int mkpath2file(
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct checkout_stream {
|
struct checkout_stream {
|
||||||
git_filter_stream base;
|
git_writestream base;
|
||||||
const char *path;
|
const char *path;
|
||||||
int fd;
|
int fd;
|
||||||
int open;
|
int open;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int checkout_stream_write(
|
static int checkout_stream_write(
|
||||||
git_filter_stream *s, const char *buffer, size_t len)
|
git_writestream *s, const char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
struct checkout_stream *stream = (struct checkout_stream *)s;
|
struct checkout_stream *stream = (struct checkout_stream *)s;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1391,7 +1391,7 @@ static int checkout_stream_write(
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int checkout_stream_close(git_filter_stream *s)
|
static int checkout_stream_close(git_writestream *s)
|
||||||
{
|
{
|
||||||
struct checkout_stream *stream = (struct checkout_stream *)s;
|
struct checkout_stream *stream = (struct checkout_stream *)s;
|
||||||
assert(stream && stream->open);
|
assert(stream && stream->open);
|
||||||
@ -1400,7 +1400,7 @@ static int checkout_stream_close(git_filter_stream *s)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkout_stream_free(git_filter_stream *s)
|
static void checkout_stream_free(git_writestream *s)
|
||||||
{
|
{
|
||||||
GIT_UNUSED(s);
|
GIT_UNUSED(s);
|
||||||
}
|
}
|
||||||
@ -1456,7 +1456,7 @@ static int blob_content_to_file(
|
|||||||
writer.fd = fd;
|
writer.fd = fd;
|
||||||
writer.open = 1;
|
writer.open = 1;
|
||||||
|
|
||||||
error = git_filter_list_stream_blob(fl, blob, (git_filter_stream *)&writer);
|
error = git_filter_list_stream_blob(fl, blob, (git_writestream *)&writer);
|
||||||
|
|
||||||
assert(writer.open == 0);
|
assert(writer.open == 0);
|
||||||
|
|
||||||
|
50
src/filter.c
50
src/filter.c
@ -624,13 +624,13 @@ static int filter_list_out_buffer_from_raw(
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct buf_stream {
|
struct buf_stream {
|
||||||
git_filter_stream base;
|
git_writestream base;
|
||||||
git_buf *target;
|
git_buf *target;
|
||||||
bool complete;
|
bool complete;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int buf_stream_write(
|
static int buf_stream_write(
|
||||||
git_filter_stream *s, const char *buffer, size_t len)
|
git_writestream *s, const char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
struct buf_stream *buf_stream = (struct buf_stream *)s;
|
struct buf_stream *buf_stream = (struct buf_stream *)s;
|
||||||
assert(buf_stream);
|
assert(buf_stream);
|
||||||
@ -640,7 +640,7 @@ static int buf_stream_write(
|
|||||||
return git_buf_put(buf_stream->target, buffer, len);
|
return git_buf_put(buf_stream->target, buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int buf_stream_close(git_filter_stream *s)
|
static int buf_stream_close(git_writestream *s)
|
||||||
{
|
{
|
||||||
struct buf_stream *buf_stream = (struct buf_stream *)s;
|
struct buf_stream *buf_stream = (struct buf_stream *)s;
|
||||||
assert(buf_stream);
|
assert(buf_stream);
|
||||||
@ -651,7 +651,7 @@ static int buf_stream_close(git_filter_stream *s)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buf_stream_free(git_filter_stream *s)
|
static void buf_stream_free(git_writestream *s)
|
||||||
{
|
{
|
||||||
GIT_UNUSED(s);
|
GIT_UNUSED(s);
|
||||||
}
|
}
|
||||||
@ -683,7 +683,7 @@ int git_filter_list_apply_to_data(
|
|||||||
buf_stream_init(&writer, tgt);
|
buf_stream_init(&writer, tgt);
|
||||||
|
|
||||||
if ((error = git_filter_list_stream_data(filters, src,
|
if ((error = git_filter_list_stream_data(filters, src,
|
||||||
(git_filter_stream *)&writer)) < 0)
|
(git_writestream *)&writer)) < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
assert(writer.complete);
|
assert(writer.complete);
|
||||||
@ -702,7 +702,7 @@ int git_filter_list_apply_to_file(
|
|||||||
buf_stream_init(&writer, out);
|
buf_stream_init(&writer, out);
|
||||||
|
|
||||||
if ((error = git_filter_list_stream_file(
|
if ((error = git_filter_list_stream_file(
|
||||||
filters, repo, path, (git_filter_stream *)&writer)) < 0)
|
filters, repo, path, (git_writestream *)&writer)) < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
assert(writer.complete);
|
assert(writer.complete);
|
||||||
@ -736,7 +736,7 @@ int git_filter_list_apply_to_blob(
|
|||||||
buf_stream_init(&writer, out);
|
buf_stream_init(&writer, out);
|
||||||
|
|
||||||
if ((error = git_filter_list_stream_blob(
|
if ((error = git_filter_list_stream_blob(
|
||||||
filters, blob, (git_filter_stream *)&writer)) < 0)
|
filters, blob, (git_writestream *)&writer)) < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
assert(writer.complete);
|
assert(writer.complete);
|
||||||
@ -744,18 +744,18 @@ int git_filter_list_apply_to_blob(
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct proxy_stream {
|
struct proxy_stream {
|
||||||
git_filter_stream base;
|
git_writestream base;
|
||||||
git_filter *filter;
|
git_filter *filter;
|
||||||
const git_filter_source *source;
|
const git_filter_source *source;
|
||||||
void **payload;
|
void **payload;
|
||||||
git_buf input;
|
git_buf input;
|
||||||
git_buf temp_buf;
|
git_buf temp_buf;
|
||||||
git_buf *output;
|
git_buf *output;
|
||||||
git_filter_stream *target;
|
git_writestream *target;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int proxy_stream_write(
|
static int proxy_stream_write(
|
||||||
git_filter_stream *s, const char *buffer, size_t len)
|
git_writestream *s, const char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
|
struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
|
||||||
assert(proxy_stream);
|
assert(proxy_stream);
|
||||||
@ -763,7 +763,7 @@ static int proxy_stream_write(
|
|||||||
return git_buf_put(&proxy_stream->input, buffer, len);
|
return git_buf_put(&proxy_stream->input, buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int proxy_stream_close(git_filter_stream *s)
|
static int proxy_stream_close(git_writestream *s)
|
||||||
{
|
{
|
||||||
struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
|
struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
|
||||||
git_buf *writebuf;
|
git_buf *writebuf;
|
||||||
@ -794,7 +794,7 @@ static int proxy_stream_close(git_filter_stream *s)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void proxy_stream_free(git_filter_stream *s)
|
static void proxy_stream_free(git_writestream *s)
|
||||||
{
|
{
|
||||||
struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
|
struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
|
||||||
assert(proxy_stream);
|
assert(proxy_stream);
|
||||||
@ -805,12 +805,12 @@ static void proxy_stream_free(git_filter_stream *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int proxy_stream_init(
|
static int proxy_stream_init(
|
||||||
git_filter_stream **out,
|
git_writestream **out,
|
||||||
git_filter *filter,
|
git_filter *filter,
|
||||||
git_buf *temp_buf,
|
git_buf *temp_buf,
|
||||||
void **payload,
|
void **payload,
|
||||||
const git_filter_source *source,
|
const git_filter_source *source,
|
||||||
git_filter_stream *target)
|
git_writestream *target)
|
||||||
{
|
{
|
||||||
struct proxy_stream *proxy_stream = git__calloc(1, sizeof(struct proxy_stream));
|
struct proxy_stream *proxy_stream = git__calloc(1, sizeof(struct proxy_stream));
|
||||||
GITERR_CHECK_ALLOC(proxy_stream);
|
GITERR_CHECK_ALLOC(proxy_stream);
|
||||||
@ -824,17 +824,17 @@ static int proxy_stream_init(
|
|||||||
proxy_stream->target = target;
|
proxy_stream->target = target;
|
||||||
proxy_stream->output = temp_buf ? temp_buf : &proxy_stream->temp_buf;
|
proxy_stream->output = temp_buf ? temp_buf : &proxy_stream->temp_buf;
|
||||||
|
|
||||||
*out = (git_filter_stream *)proxy_stream;
|
*out = (git_writestream *)proxy_stream;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stream_list_init(
|
static int stream_list_init(
|
||||||
git_filter_stream **out,
|
git_writestream **out,
|
||||||
git_vector *streams,
|
git_vector *streams,
|
||||||
git_filter_list *filters,
|
git_filter_list *filters,
|
||||||
git_filter_stream *target)
|
git_writestream *target)
|
||||||
{
|
{
|
||||||
git_filter_stream *last_stream = target;
|
git_writestream *last_stream = target;
|
||||||
size_t i;
|
size_t i;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
@ -850,7 +850,7 @@ static int stream_list_init(
|
|||||||
size_t filter_idx = (filters->source.mode == GIT_FILTER_TO_WORKTREE) ?
|
size_t filter_idx = (filters->source.mode == GIT_FILTER_TO_WORKTREE) ?
|
||||||
git_array_size(filters->filters) - 1 - i : i;
|
git_array_size(filters->filters) - 1 - i : i;
|
||||||
git_filter_entry *fe = git_array_get(filters->filters, filter_idx);
|
git_filter_entry *fe = git_array_get(filters->filters, filter_idx);
|
||||||
git_filter_stream *filter_stream;
|
git_writestream *filter_stream;
|
||||||
|
|
||||||
assert(fe->filter->stream || fe->filter->apply);
|
assert(fe->filter->stream || fe->filter->apply);
|
||||||
|
|
||||||
@ -879,7 +879,7 @@ static int stream_list_init(
|
|||||||
|
|
||||||
void stream_list_free(git_vector *streams)
|
void stream_list_free(git_vector *streams)
|
||||||
{
|
{
|
||||||
git_filter_stream *stream;
|
git_writestream *stream;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
git_vector_foreach(streams, i, stream)
|
git_vector_foreach(streams, i, stream)
|
||||||
@ -894,13 +894,13 @@ int git_filter_list_stream_file(
|
|||||||
git_filter_list *filters,
|
git_filter_list *filters,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
const char *path,
|
const char *path,
|
||||||
git_filter_stream *target)
|
git_writestream *target)
|
||||||
{
|
{
|
||||||
char buf[STREAM_BUFSIZE];
|
char buf[STREAM_BUFSIZE];
|
||||||
git_buf abspath = GIT_BUF_INIT;
|
git_buf abspath = GIT_BUF_INIT;
|
||||||
const char *base = repo ? git_repository_workdir(repo) : NULL;
|
const char *base = repo ? git_repository_workdir(repo) : NULL;
|
||||||
git_vector filter_streams = GIT_VECTOR_INIT;
|
git_vector filter_streams = GIT_VECTOR_INIT;
|
||||||
git_filter_stream *stream_start;
|
git_writestream *stream_start;
|
||||||
ssize_t readlen;
|
ssize_t readlen;
|
||||||
int fd, error;
|
int fd, error;
|
||||||
|
|
||||||
@ -935,10 +935,10 @@ done:
|
|||||||
int git_filter_list_stream_data(
|
int git_filter_list_stream_data(
|
||||||
git_filter_list *filters,
|
git_filter_list *filters,
|
||||||
git_buf *data,
|
git_buf *data,
|
||||||
git_filter_stream *target)
|
git_writestream *target)
|
||||||
{
|
{
|
||||||
git_vector filter_streams = GIT_VECTOR_INIT;
|
git_vector filter_streams = GIT_VECTOR_INIT;
|
||||||
git_filter_stream *stream_start;
|
git_writestream *stream_start;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
git_buf_sanitize(data);
|
git_buf_sanitize(data);
|
||||||
@ -956,7 +956,7 @@ int git_filter_list_stream_data(
|
|||||||
int git_filter_list_stream_blob(
|
int git_filter_list_stream_blob(
|
||||||
git_filter_list *filters,
|
git_filter_list *filters,
|
||||||
git_blob *blob,
|
git_blob *blob,
|
||||||
git_filter_stream *target)
|
git_writestream *target)
|
||||||
{
|
{
|
||||||
git_buf in = GIT_BUF_INIT;
|
git_buf in = GIT_BUF_INIT;
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ void test_filter_stream__cleanup(void)
|
|||||||
#define CHUNKSIZE 10240
|
#define CHUNKSIZE 10240
|
||||||
|
|
||||||
struct compress_stream {
|
struct compress_stream {
|
||||||
git_filter_stream base;
|
git_writestream base;
|
||||||
git_filter_stream *next;
|
git_writestream *next;
|
||||||
git_filter_mode_t mode;
|
git_filter_mode_t mode;
|
||||||
char current;
|
char current;
|
||||||
size_t current_chunk;
|
size_t current_chunk;
|
||||||
@ -78,7 +78,7 @@ static int compress_stream_write__inflated(struct compress_stream *stream, const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compress_stream_write(git_filter_stream *s, const char *buffer, size_t len)
|
static int compress_stream_write(git_writestream *s, const char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
struct compress_stream *stream = (struct compress_stream *)s;
|
struct compress_stream *stream = (struct compress_stream *)s;
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ static int compress_stream_write(git_filter_stream *s, const char *buffer, size_
|
|||||||
compress_stream_write__inflated(stream, buffer, len);
|
compress_stream_write__inflated(stream, buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compress_stream_close(git_filter_stream *s)
|
static int compress_stream_close(git_writestream *s)
|
||||||
{
|
{
|
||||||
struct compress_stream *stream = (struct compress_stream *)s;
|
struct compress_stream *stream = (struct compress_stream *)s;
|
||||||
cl_assert_equal_i(0, stream->current_chunk);
|
cl_assert_equal_i(0, stream->current_chunk);
|
||||||
@ -95,17 +95,17 @@ static int compress_stream_close(git_filter_stream *s)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compress_stream_free(git_filter_stream *stream)
|
static void compress_stream_free(git_writestream *stream)
|
||||||
{
|
{
|
||||||
git__free(stream);
|
git__free(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compress_filter_stream_init(
|
static int compress_filter_stream_init(
|
||||||
git_filter_stream **out,
|
git_writestream **out,
|
||||||
git_filter *self,
|
git_filter *self,
|
||||||
void **payload,
|
void **payload,
|
||||||
const git_filter_source *src,
|
const git_filter_source *src,
|
||||||
git_filter_stream *next)
|
git_writestream *next)
|
||||||
{
|
{
|
||||||
struct compress_stream *stream = git__calloc(1, sizeof(struct compress_stream));
|
struct compress_stream *stream = git__calloc(1, sizeof(struct compress_stream));
|
||||||
cl_assert(stream);
|
cl_assert(stream);
|
||||||
@ -119,7 +119,7 @@ static int compress_filter_stream_init(
|
|||||||
stream->next = next;
|
stream->next = next;
|
||||||
stream->mode = git_filter_source_mode(src);
|
stream->mode = git_filter_source_mode(src);
|
||||||
|
|
||||||
*out = (git_filter_stream *)stream;
|
*out = (git_writestream *)stream;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user