diff options
Diffstat (limited to 'convert.c')
-rw-r--r-- | convert.c | 81 |
1 files changed, 44 insertions, 37 deletions
@@ -1,14 +1,21 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "advice.h" #include "config.h" -#include "object-store.h" +#include "convert.h" +#include "copy.h" +#include "gettext.h" +#include "hex.h" +#include "object-store-ll.h" #include "attr.h" #include "run-command.h" #include "quote.h" +#include "read-cache-ll.h" #include "sigchain.h" #include "pkt-line.h" #include "sub-process.h" +#include "trace.h" #include "utf8.h" -#include "ll-merge.h" +#include "merge-ll.h" /* * convert.c - convert a file when checking it out and checking it in. @@ -195,9 +202,9 @@ static void check_global_conv_flags_eol(const char *path, if (conv_flags & CONV_EOL_RNDTRP_DIE) die(_("CRLF would be replaced by LF in %s"), path); else if (conv_flags & CONV_EOL_RNDTRP_WARN) - warning(_("CRLF will be replaced by LF in %s.\n" - "The file will have its original line" - " endings in your working directory"), path); + warning(_("in the working copy of '%s', CRLF will be" + " replaced by LF the next time Git touches" + " it"), path); } else if (old_stats->lonelf && !new_stats->lonelf ) { /* * CRLFs would be added by checkout @@ -205,9 +212,9 @@ static void check_global_conv_flags_eol(const char *path, if (conv_flags & CONV_EOL_RNDTRP_DIE) die(_("LF would be replaced by CRLF in %s"), path); else if (conv_flags & CONV_EOL_RNDTRP_WARN) - warning(_("LF will be replaced by CRLF in %s.\n" - "The file will have its original line" - " endings in your working directory"), path); + warning(_("in the working copy of '%s', LF will be" + " replaced by CRLF the next time Git touches" + " it"), path); } } @@ -613,36 +620,34 @@ static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf, struct filter_params { const char *src; - unsigned long size; + size_t size; int fd; const char *cmd; const char *path; }; -static int filter_buffer_or_fd(int in, int out, void *data) +static int filter_buffer_or_fd(int in UNUSED, int out, void *data) { /* * Spawn cmd and feed the buffer contents through its stdin. */ struct child_process child_process = CHILD_PROCESS_INIT; struct filter_params *params = (struct filter_params *)data; + const char *format = params->cmd; int write_err, status; /* apply % substitution to cmd */ struct strbuf cmd = STRBUF_INIT; - struct strbuf path = STRBUF_INIT; - struct strbuf_expand_dict_entry dict[] = { - { "f", NULL, }, - { NULL, NULL, }, - }; - - /* quote the path to preserve spaces, etc. */ - sq_quote_buf(&path, params->path); - dict[0].value = path.buf; - /* expand all %f with the quoted path */ - strbuf_expand(&cmd, params->cmd, strbuf_expand_dict_cb, &dict); - strbuf_release(&path); + /* expand all %f with the quoted path; quote to preserve space, etc. */ + while (strbuf_expand_step(&cmd, &format)) { + if (skip_prefix(format, "%", &format)) + strbuf_addch(&cmd, '%'); + else if (skip_prefix(format, "f", &format)) + sq_quote_buf(&cmd, params->path); + else + strbuf_addch(&cmd, '%'); + } strvec_push(&child_process.args, cmd.buf); child_process.use_shell = 1; @@ -1008,7 +1013,9 @@ static int apply_filter(const char *path, const char *src, size_t len, return 0; } -static int read_convert_config(const char *var, const char *value, void *cb) +static int read_convert_config(const char *var, const char *value, + const struct config_context *ctx UNUSED, + void *cb UNUSED) { const char *key, *name; size_t namelen; @@ -1021,7 +1028,7 @@ static int read_convert_config(const char *var, const char *value, void *cb) if (parse_config_key(var, "filter", &name, &namelen, &key) < 0 || !name) return 0; for (drv = user_convert; drv; drv = drv->next) - if (!strncmp(drv->name, name, namelen) && !drv->name[namelen]) + if (!xstrncmpz(drv->name, name, namelen)) break; if (!drv) { CALLOC_ARRAY(drv, 1); @@ -1159,7 +1166,7 @@ static int ident_to_worktree(const char *src, size_t len, /* are we "faking" in place editing ? */ if (src == buf->buf) to_free = strbuf_detach(buf, NULL); - hash_object_file(the_hash_algo, src, len, "blob", &oid); + hash_object_file(the_hash_algo, src, len, OBJ_BLOB, &oid); strbuf_grow(buf, len + cnt * (the_hash_algo->hexsz + 3)); for (;;) { @@ -1549,7 +1556,7 @@ struct stream_filter { struct stream_filter_vtbl *vtbl; }; -static int null_filter_fn(struct stream_filter *filter, +static int null_filter_fn(struct stream_filter *filter UNUSED, const char *input, size_t *isize_p, char *output, size_t *osize_p) { @@ -1568,18 +1575,18 @@ static int null_filter_fn(struct stream_filter *filter, return 0; } -static void null_free_fn(struct stream_filter *filter) +static void null_free_fn(struct stream_filter *filter UNUSED) { ; /* nothing -- null instances are shared */ } static struct stream_filter_vtbl null_vtbl = { - null_filter_fn, - null_free_fn, + .filter = null_filter_fn, + .free = null_free_fn, }; static struct stream_filter null_filter_singleton = { - &null_vtbl, + .vtbl = &null_vtbl, }; int is_null_stream_filter(struct stream_filter *filter) @@ -1683,8 +1690,8 @@ static void lf_to_crlf_free_fn(struct stream_filter *filter) } static struct stream_filter_vtbl lf_to_crlf_vtbl = { - lf_to_crlf_filter_fn, - lf_to_crlf_free_fn, + .filter = lf_to_crlf_filter_fn, + .free = lf_to_crlf_free_fn, }; static struct stream_filter *lf_to_crlf_filter(void) @@ -1779,8 +1786,8 @@ static void cascade_free_fn(struct stream_filter *filter) } static struct stream_filter_vtbl cascade_vtbl = { - cascade_filter_fn, - cascade_free_fn, + .filter = cascade_filter_fn, + .free = cascade_free_fn, }; static struct stream_filter *cascade_filter(struct stream_filter *one, @@ -1931,8 +1938,8 @@ static void ident_free_fn(struct stream_filter *filter) } static struct stream_filter_vtbl ident_vtbl = { - ident_filter_fn, - ident_free_fn, + .filter = ident_filter_fn, + .free = ident_free_fn, }; static struct stream_filter *ident_filter(const struct object_id *oid) |