Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-03-03 03:09:40 +0400
committerRussell Belfer <arrbee@arrbee.com>2012-03-03 03:09:40 +0400
commitce49c7a8a902bd3a74a59a356dd11886e83d2e92 (patch)
treee336ef425b5bda0e7c05acfbcf51fabb758ca662 /src/filter.c
parentd377fe80b1396b82f8af7bfcd76f869410865001 (diff)
Add filter tests and fix some bugs
This adds some initial unit tests for file filtering and fixes some simple bugs in filter application.
Diffstat (limited to 'src/filter.c')
-rw-r--r--src/filter.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/filter.c b/src/filter.c
index f93730acb..f0ee1ad39 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -12,7 +12,7 @@
#include "repository.h"
#include "git2/config.h"
-/* Fresh from Core Git. I wonder what we could use this for... */
+/* Tweaked from Core Git. I wonder what we could use this for... */
void git_text_gather_stats(git_text_stats *stats, const git_buf *text)
{
size_t i;
@@ -27,20 +27,20 @@ void git_text_gather_stats(git_text_stats *stats, const git_buf *text)
if (i + 1 < text->size && text->ptr[i + 1] == '\n')
stats->crlf++;
-
- continue;
}
- if (c == '\n') {
+ else if (c == '\n')
stats->lf++;
- continue;
- }
- if (c == 127)
+ else if (c == 0x85)
+ /* Unicode CR+LF */
+ stats->crlf++;
+
+ else if (c == 127)
/* DEL */
stats->nonprintable++;
- else if (c < 32) {
+ else if (c <= 0x1F || (c >= 0x80 && c <= 0x9F)) {
switch (c) {
/* BS, HT, ESC and FF */
case '\b': case '\t': case '\033': case '\014':
@@ -53,6 +53,7 @@ void git_text_gather_stats(git_text_stats *stats, const git_buf *text)
stats->nonprintable++;
}
}
+
else
stats->printable++;
}
@@ -118,7 +119,7 @@ void git_filters_free(git_vector *filters)
int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
{
- unsigned int src, dst, i;
+ unsigned int i, src;
git_buf *dbuffer[2];
dbuffer[0] = source;
@@ -138,28 +139,26 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
for (i = 0; i < filters->length; ++i) {
git_filter *filter = git_vector_get(filters, i);
- dst = (src + 1) % 2;
+ unsigned int dst = 1 - src;
git_buf_clear(dbuffer[dst]);
- /* Apply the filter, from dbuffer[src] to dbuffer[dst];
+ /* Apply the filter from dbuffer[src] to the other buffer;
* if the filtering is canceled by the user mid-filter,
* we skip to the next filter without changing the source
* of the double buffering (so that the text goes through
* cleanly).
*/
- if (filter->apply(filter, dbuffer[dst], dbuffer[src]) == 0) {
- src = (src + 1) % 2;
- }
+ if (filter->apply(filter, dbuffer[dst], dbuffer[src]) == 0)
+ src = dst;
if (git_buf_oom(dbuffer[dst]))
return GIT_ENOMEM;
}
/* Ensure that the output ends up in dbuffer[1] (i.e. the dest) */
- if (dst != 1) {
+ if (src != 1)
git_buf_swap(dest, source);
- }
return GIT_SUCCESS;
}