summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-18 09:25:32 -0500
committerEdward Thomson <ethomson@microsoft.com>2015-02-18 10:24:23 -0500
commitb75f15aaf1587594cd398b192cdc40aa83ba8e23 (patch)
tree573ec7432ddfb2ba6a17b4e092c579c9c3dfa27b
parent8c2dfb38dbc782a6b964bfcfd43e4f46bb71526e (diff)
downloadlibgit2-b75f15aaf1587594cd398b192cdc40aa83ba8e23.tar.gz
git_writestream: from git_filter_stream
-rw-r--r--include/git2/filter.h6
-rw-r--r--include/git2/sys/filter.h10
-rw-r--r--include/git2/types.h10
-rw-r--r--src/checkout.c10
-rw-r--r--src/filter.c50
-rw-r--r--tests/filter/stream.c16
6 files changed, 51 insertions, 51 deletions
diff --git a/include/git2/filter.h b/include/git2/filter.h
index 600356c71..c0aaf1508 100644
--- a/include/git2/filter.h
+++ b/include/git2/filter.h
@@ -140,18 +140,18 @@ GIT_EXTERN(int) git_filter_list_apply_to_blob(
GIT_EXTERN(int) git_filter_list_stream_data(
git_filter_list *filters,
git_buf *data,
- git_filter_stream *target);
+ git_writestream *target);
GIT_EXTERN(int) git_filter_list_stream_file(
git_filter_list *filters,
git_repository *repo,
const char *path,
- git_filter_stream *target);
+ git_writestream *target);
GIT_EXTERN(int) git_filter_list_stream_blob(
git_filter_list *filters,
git_blob *blob,
- git_filter_stream *target);
+ git_writestream *target);
/**
* Free a git_filter_list
diff --git a/include/git2/sys/filter.h b/include/git2/sys/filter.h
index cc06c54ad..9b560fa75 100644
--- a/include/git2/sys/filter.h
+++ b/include/git2/sys/filter.h
@@ -208,18 +208,12 @@ typedef int (*git_filter_apply_fn)(
const git_buf *from,
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)(
- git_filter_stream **out,
+ git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
- git_filter_stream *next);
+ git_writestream *next);
/**
* Callback to clean up after filtering has been applied
diff --git a/include/git2/types.h b/include/git2/types.h
index 3ed97d189..c90ac4776 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -410,8 +410,14 @@ typedef enum {
GIT_SUBMODULE_RECURSE_ONDEMAND = 2,
} git_submodule_recurse_t;
-/** A stream to write filters. */
-typedef struct git_filter_stream git_filter_stream;
+/** A type to write in a streaming fashion, for example, for filters. */
+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
diff --git a/src/checkout.c b/src/checkout.c
index 35129d771..1585a4fb5 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -1373,14 +1373,14 @@ static int mkpath2file(
}
struct checkout_stream {
- git_filter_stream base;
+ git_writestream base;
const char *path;
int fd;
int open;
};
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;
int ret;
@@ -1391,7 +1391,7 @@ static int checkout_stream_write(
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;
assert(stream && stream->open);
@@ -1400,7 +1400,7 @@ static int checkout_stream_close(git_filter_stream *s)
return 0;
}
-static void checkout_stream_free(git_filter_stream *s)
+static void checkout_stream_free(git_writestream *s)
{
GIT_UNUSED(s);
}
@@ -1456,7 +1456,7 @@ static int blob_content_to_file(
writer.fd = fd;
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);
diff --git a/src/filter.c b/src/filter.c
index 2cae24e20..af5902e06 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -624,13 +624,13 @@ static int filter_list_out_buffer_from_raw(
}
struct buf_stream {
- git_filter_stream base;
+ git_writestream base;
git_buf *target;
bool complete;
};
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;
assert(buf_stream);
@@ -640,7 +640,7 @@ static int buf_stream_write(
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;
assert(buf_stream);
@@ -651,7 +651,7 @@ static int buf_stream_close(git_filter_stream *s)
return 0;
}
-static void buf_stream_free(git_filter_stream *s)
+static void buf_stream_free(git_writestream *s)
{
GIT_UNUSED(s);
}
@@ -683,7 +683,7 @@ int git_filter_list_apply_to_data(
buf_stream_init(&writer, tgt);
if ((error = git_filter_list_stream_data(filters, src,
- (git_filter_stream *)&writer)) < 0)
+ (git_writestream *)&writer)) < 0)
return error;
assert(writer.complete);
@@ -702,7 +702,7 @@ int git_filter_list_apply_to_file(
buf_stream_init(&writer, out);
if ((error = git_filter_list_stream_file(
- filters, repo, path, (git_filter_stream *)&writer)) < 0)
+ filters, repo, path, (git_writestream *)&writer)) < 0)
return error;
assert(writer.complete);
@@ -736,7 +736,7 @@ int git_filter_list_apply_to_blob(
buf_stream_init(&writer, out);
if ((error = git_filter_list_stream_blob(
- filters, blob, (git_filter_stream *)&writer)) < 0)
+ filters, blob, (git_writestream *)&writer)) < 0)
return error;
assert(writer.complete);
@@ -744,18 +744,18 @@ int git_filter_list_apply_to_blob(
}
struct proxy_stream {
- git_filter_stream base;
+ git_writestream base;
git_filter *filter;
const git_filter_source *source;
void **payload;
git_buf input;
git_buf temp_buf;
git_buf *output;
- git_filter_stream *target;
+ git_writestream *target;
};
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;
assert(proxy_stream);
@@ -763,7 +763,7 @@ static int proxy_stream_write(
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;
git_buf *writebuf;
@@ -794,7 +794,7 @@ static int proxy_stream_close(git_filter_stream *s)
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;
assert(proxy_stream);
@@ -805,12 +805,12 @@ static void proxy_stream_free(git_filter_stream *s)
}
static int proxy_stream_init(
- git_filter_stream **out,
+ git_writestream **out,
git_filter *filter,
git_buf *temp_buf,
void **payload,
const git_filter_source *source,
- git_filter_stream *target)
+ git_writestream *target)
{
struct proxy_stream *proxy_stream = git__calloc(1, sizeof(struct proxy_stream));
GITERR_CHECK_ALLOC(proxy_stream);
@@ -824,17 +824,17 @@ static int proxy_stream_init(
proxy_stream->target = target;
proxy_stream->output = temp_buf ? temp_buf : &proxy_stream->temp_buf;
- *out = (git_filter_stream *)proxy_stream;
+ *out = (git_writestream *)proxy_stream;
return 0;
}
static int stream_list_init(
- git_filter_stream **out,
+ git_writestream **out,
git_vector *streams,
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;
int error = 0;
@@ -850,7 +850,7 @@ static int stream_list_init(
size_t filter_idx = (filters->source.mode == GIT_FILTER_TO_WORKTREE) ?
git_array_size(filters->filters) - 1 - i : i;
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);
@@ -879,7 +879,7 @@ static int stream_list_init(
void stream_list_free(git_vector *streams)
{
- git_filter_stream *stream;
+ git_writestream *stream;
size_t i;
git_vector_foreach(streams, i, stream)
@@ -894,13 +894,13 @@ int git_filter_list_stream_file(
git_filter_list *filters,
git_repository *repo,
const char *path,
- git_filter_stream *target)
+ git_writestream *target)
{
char buf[STREAM_BUFSIZE];
git_buf abspath = GIT_BUF_INIT;
const char *base = repo ? git_repository_workdir(repo) : NULL;
git_vector filter_streams = GIT_VECTOR_INIT;
- git_filter_stream *stream_start;
+ git_writestream *stream_start;
ssize_t readlen;
int fd, error;
@@ -935,10 +935,10 @@ done:
int git_filter_list_stream_data(
git_filter_list *filters,
git_buf *data,
- git_filter_stream *target)
+ git_writestream *target)
{
git_vector filter_streams = GIT_VECTOR_INIT;
- git_filter_stream *stream_start;
+ git_writestream *stream_start;
int error = 0;
git_buf_sanitize(data);
@@ -956,7 +956,7 @@ int git_filter_list_stream_data(
int git_filter_list_stream_blob(
git_filter_list *filters,
git_blob *blob,
- git_filter_stream *target)
+ git_writestream *target)
{
git_buf in = GIT_BUF_INIT;
diff --git a/tests/filter/stream.c b/tests/filter/stream.c
index ff5361a37..f7456b8a4 100644
--- a/tests/filter/stream.c
+++ b/tests/filter/stream.c
@@ -30,8 +30,8 @@ void test_filter_stream__cleanup(void)
#define CHUNKSIZE 10240
struct compress_stream {
- git_filter_stream base;
- git_filter_stream *next;
+ git_writestream base;
+ git_writestream *next;
git_filter_mode_t mode;
char current;
size_t current_chunk;
@@ -78,7 +78,7 @@ static int compress_stream_write__inflated(struct compress_stream *stream, const
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;
@@ -87,7 +87,7 @@ static int compress_stream_write(git_filter_stream *s, const char *buffer, size_
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;
cl_assert_equal_i(0, stream->current_chunk);
@@ -95,17 +95,17 @@ static int compress_stream_close(git_filter_stream *s)
return 0;
}
-static void compress_stream_free(git_filter_stream *stream)
+static void compress_stream_free(git_writestream *stream)
{
git__free(stream);
}
static int compress_filter_stream_init(
- git_filter_stream **out,
+ git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
- git_filter_stream *next)
+ git_writestream *next)
{
struct compress_stream *stream = git__calloc(1, sizeof(struct compress_stream));
cl_assert(stream);
@@ -119,7 +119,7 @@ static int compress_filter_stream_init(
stream->next = next;
stream->mode = git_filter_source_mode(src);
- *out = (git_filter_stream *)stream;
+ *out = (git_writestream *)stream;
return 0;
}