diff options
| author | Junio C Hamano <gitster@pobox.com> | 2008-07-01 16:22:35 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2008-07-01 16:22:35 -0700 |
| commit | d4b76e15ea733002e364298a81889452b8bb2dfd (patch) | |
| tree | 5a8456715cf28f96e247cd2f3f61cf5922910b09 /ws.c | |
| parent | f7c3cf8106c09c714d46d39e8eef69838db8b339 (diff) | |
| parent | ab20fda99236e38edf5d63f964b6b920b494aacb (diff) | |
| download | git-d4b76e15ea733002e364298a81889452b8bb2dfd.tar.xz | |
Merge branch 'jc/checkdiff'
* jc/checkdiff:
Fix t4017-diff-retval for white-space from wc
Update sample pre-commit hook to use "diff --check"
diff --check: detect leftover conflict markers
Teach "diff --check" about new blank lines at end
checkdiff: pass diff_options to the callback
check_and_emit_line(): rename and refactor
diff --check: explain why we do not care whether old side is binary
Diffstat (limited to 'ws.c')
| -rw-r--r-- | ws.c | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -117,9 +117,9 @@ char *whitespace_error_string(unsigned ws) } /* If stream is non-NULL, emits the line after checking. */ -unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, - FILE *stream, const char *set, - const char *reset, const char *ws) +static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule, + FILE *stream, const char *set, + const char *reset, const char *ws) { unsigned result = 0; int written = 0; @@ -213,6 +213,33 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, return result; } +void ws_check_emit(const char *line, int len, unsigned ws_rule, + FILE *stream, const char *set, + const char *reset, const char *ws) +{ + (void)ws_check_emit_1(line, len, ws_rule, stream, set, reset, ws); +} + +unsigned ws_check(const char *line, int len, unsigned ws_rule) +{ + return ws_check_emit_1(line, len, ws_rule, NULL, NULL, NULL, NULL); +} + +int ws_blank_line(const char *line, int len, unsigned ws_rule) +{ + /* + * We _might_ want to treat CR differently from other + * whitespace characters when ws_rule has WS_CR_AT_EOL, but + * for now we just use this stupid definition. + */ + while (len-- > 0) { + if (!isspace(*line)) + return 0; + line++; + } + return 1; +} + /* Copy the line to the buffer while fixing whitespaces */ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *error_count) { |
