X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=convert.c;h=491e7141b4ea29b3cf754cbaf2656a0c3ca8c46c;hb=b7eb912b0d3352d43a11c79fab97cd7f92f0646e;hp=d8c94cb3edeceff7a79b2f5e6ba7cad250e6b301;hpb=f23ffbe890d36e277f02d4a84c2b52de3a4e3173;p=git.git diff --git a/convert.c b/convert.c index d8c94cb3e..491e7141b 100644 --- a/convert.c +++ b/convert.c @@ -61,6 +61,10 @@ static void gather_stats(const char *buf, unsigned long size, struct text_stat * else stats->printable++; } + + /* If file ends with EOF then don't count this EOF as non-printable. */ + if (size >= 1 && buf[size-1] == '\032') + stats->nonprintable--; } /* @@ -263,7 +267,7 @@ static int filter_buffer(int fd, void *data) status = finish_command(&child_process); if (status) - error("external filter %s failed %d", params->cmd, -status); + error("external filter %s failed %d", params->cmd, status); return (write_err || status); } @@ -277,7 +281,7 @@ static int apply_filter(const char *path, const char *src, size_t len, * (child --> cmd) --> us */ int ret = 1; - struct strbuf nbuf; + struct strbuf nbuf = STRBUF_INIT; struct async async; struct filter_params params; @@ -295,7 +299,6 @@ static int apply_filter(const char *path, const char *src, size_t len, if (start_async(&async)) return 0; /* error was already reported */ - strbuf_init(&nbuf, 0); if (strbuf_read(&nbuf, async.out, len) < 0) { error("read from external filter %s failed", cmd); ret = 0; @@ -319,11 +322,11 @@ static int apply_filter(const char *path, const char *src, size_t len, static struct convert_driver { const char *name; struct convert_driver *next; - char *smudge; - char *clean; + const char *smudge; + const char *clean; } *user_convert, **user_convert_tail; -static int read_convert_config(const char *var, const char *value) +static int read_convert_config(const char *var, const char *value, void *cb) { const char *ep, *name; int namelen; @@ -358,19 +361,12 @@ static int read_convert_config(const char *var, const char *value) * The command-line will not be interpolated in any way. */ - if (!strcmp("smudge", ep)) { - if (!value) - return config_error_nonbool(var); - drv->smudge = strdup(value); - return 0; - } + if (!strcmp("smudge", ep)) + return git_config_string(&drv->smudge, var, value); + + if (!strcmp("clean", ep)) + return git_config_string(&drv->clean, var, value); - if (!strcmp("clean", ep)) { - if (!value) - return config_error_nonbool(var); - drv->clean = strdup(value); - return 0; - } return 0; } @@ -385,7 +381,7 @@ static void setup_convert_check(struct git_attr_check *check) attr_ident = git_attr("ident", 5); attr_filter = git_attr("filter", 6); user_convert_tail = &user_convert; - git_config(read_convert_config); + git_config(read_convert_config, NULL); } check[0].attr = attr_crlf; check[1].attr = attr_ident; @@ -576,7 +572,7 @@ int convert_to_git(const char *path, const char *src, size_t len, struct git_attr_check check[3]; int crlf = CRLF_GUESS; int ident = 0, ret = 0; - char *filter = NULL; + const char *filter = NULL; setup_convert_check(check); if (!git_checkattr(path, ARRAY_SIZE(check), check)) { @@ -606,7 +602,7 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc struct git_attr_check check[3]; int crlf = CRLF_GUESS; int ident = 0, ret = 0; - char *filter = NULL; + const char *filter = NULL; setup_convert_check(check); if (!git_checkattr(path, ARRAY_SIZE(check), check)) {