diff options
author | Russell Belfer <rb@github.com> | 2012-11-28 09:58:48 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-11-28 09:58:48 -0800 |
commit | 7bf87ab6987cf6b9e166e23d2d9dbdcd2511fb32 (patch) | |
tree | dcc8a92ce69b2a0d9d8cca98d67f0cc71177ce40 /src/filter.c | |
parent | 693021262ba0eeac2923bbce1b2262717019c807 (diff) | |
download | libgit2-7bf87ab6987cf6b9e166e23d2d9dbdcd2511fb32.tar.gz |
Consolidate text buffer functions
There are many scattered functions that look into the contents of
buffers to do various text manipulations (such as escaping or
unescaping data, calculating text stats, guessing if content is
binary, etc). This groups all those functions together into a
new file and converts the code to use that.
This has two enhancements to existing functionality. The old
text stats function is significantly rewritten and the BOM
detection code was extended (although largely we can't deal with
anything other than a UTF8 BOM).
Diffstat (limited to 'src/filter.c')
-rw-r--r-- | src/filter.c | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/src/filter.c b/src/filter.c index f2ab1b85a..6d27c0c46 100644 --- a/src/filter.c +++ b/src/filter.c @@ -13,75 +13,6 @@ #include "git2/config.h" #include "blob.h" -/* 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; - - memset(stats, 0, sizeof(*stats)); - - for (i = 0; i < git_buf_len(text); i++) { - unsigned char c = text->ptr[i]; - - if (c == '\r') { - stats->cr++; - - if (i + 1 < git_buf_len(text) && text->ptr[i + 1] == '\n') - stats->crlf++; - } - - else if (c == '\n') - stats->lf++; - - else if (c == 127) - /* DEL */ - stats->nonprintable++; - - else if (c <= 0x1F || (c >= 0x80 && c <= 0x9F)) { - switch (c) { - /* BS, HT, ESC and FF */ - case '\b': case '\t': case '\033': case '\014': - stats->printable++; - break; - case 0: - stats->nul++; - /* fall through */ - default: - stats->nonprintable++; - } - } - - else - stats->printable++; - } - - /* If file ends with EOF then don't count this EOF as non-printable. */ - if (git_buf_len(text) >= 1 && text->ptr[text->size - 1] == '\032') - stats->nonprintable--; -} - -/* - * Fresh from Core Git - */ -int git_text_is_binary(git_text_stats *stats) -{ - if (stats->nul) - return 1; - - if ((stats->printable >> 7) < stats->nonprintable) - return 1; - /* - * Other heuristics? Average line length might be relevant, - * as might LF vs CR vs CRLF counts.. - * - * NOTE! It might be normal to have a low ratio of CRLF to LF - * (somebody starts with a LF-only file and edits it with an editor - * that adds CRLF only to lines that are added..). But do we - * want to support CR-only? Probably not. - */ - return 0; -} - int git_filters_load(git_vector *filters, git_repository *repo, const char *path, int mode) { int error; |