summaryrefslogtreecommitdiff
path: root/convert.c
diff options
context:
space:
mode:
Diffstat (limited to 'convert.c')
-rw-r--r--convert.c79
1 files changed, 61 insertions, 18 deletions
diff --git a/convert.c b/convert.c
index 5ead3ce678..9ecc1c699c 100644
--- a/convert.c
+++ b/convert.c
@@ -195,7 +195,7 @@ static enum eol output_eol(enum crlf_action crlf_action)
return core_eol;
}
-static void check_global_conv_flags_eol(const char *path, enum crlf_action crlf_action,
+static void check_global_conv_flags_eol(const char *path,
struct text_stat *old_stats, struct text_stat *new_stats,
int conv_flags)
{
@@ -547,7 +547,7 @@ static int crlf_to_git(const struct index_state *istate,
new_stats.crlf += new_stats.lonelf;
new_stats.lonelf = 0;
}
- check_global_conv_flags_eol(path, crlf_action, &stats, &new_stats, conv_flags);
+ check_global_conv_flags_eol(path, &stats, &new_stats, conv_flags);
}
if (!convert_crlf_into_lf)
return 0;
@@ -638,7 +638,6 @@ static int filter_buffer_or_fd(int in, int out, void *data)
struct child_process child_process = CHILD_PROCESS_INIT;
struct filter_params *params = (struct filter_params *)data;
int write_err, status;
- const char *argv[] = { NULL, NULL };
/* apply % substitution to cmd */
struct strbuf cmd = STRBUF_INIT;
@@ -656,9 +655,7 @@ static int filter_buffer_or_fd(int in, int out, void *data)
strbuf_expand(&cmd, params->cmd, strbuf_expand_dict_cb, &dict);
strbuf_release(&path);
- argv[0] = cmd.buf;
-
- child_process.argv = argv;
+ strvec_push(&child_process.args, cmd.buf);
child_process.use_shell = 1;
child_process.in = -1;
child_process.out = out;
@@ -797,6 +794,7 @@ static void handle_filter_error(const struct strbuf *filter_status,
static int apply_multi_file_filter(const char *path, const char *src, size_t len,
int fd, struct strbuf *dst, const char *cmd,
const unsigned int wanted_capability,
+ const struct checkout_metadata *meta,
struct delayed_checkout *dco)
{
int err;
@@ -855,6 +853,24 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
if (err)
goto done;
+ if (meta && meta->refname) {
+ err = packet_write_fmt_gently(process->in, "ref=%s\n", meta->refname);
+ if (err)
+ goto done;
+ }
+
+ if (meta && !is_null_oid(&meta->treeish)) {
+ err = packet_write_fmt_gently(process->in, "treeish=%s\n", oid_to_hex(&meta->treeish));
+ if (err)
+ goto done;
+ }
+
+ if (meta && !is_null_oid(&meta->blob)) {
+ err = packet_write_fmt_gently(process->in, "blob=%s\n", oid_to_hex(&meta->blob));
+ if (err)
+ goto done;
+ }
+
if ((entry->supported_capabilities & CAP_DELAY) &&
dco && dco->state == CE_CAN_DELAY) {
can_delay = 1;
@@ -971,6 +987,7 @@ static struct convert_driver {
static int apply_filter(const char *path, const char *src, size_t len,
int fd, struct strbuf *dst, struct convert_driver *drv,
const unsigned int wanted_capability,
+ const struct checkout_metadata *meta,
struct delayed_checkout *dco)
{
const char *cmd = NULL;
@@ -990,7 +1007,7 @@ static int apply_filter(const char *path, const char *src, size_t len,
return apply_single_file_filter(path, src, len, fd, dst, cmd);
else if (drv->process && *drv->process)
return apply_multi_file_filter(path, src, len, fd, dst,
- drv->process, wanted_capability, dco);
+ drv->process, wanted_capability, meta, dco);
return 0;
}
@@ -998,7 +1015,7 @@ static int apply_filter(const char *path, const char *src, size_t len,
static int read_convert_config(const char *var, const char *value, void *cb)
{
const char *key, *name;
- int namelen;
+ size_t namelen;
struct convert_driver *drv;
/*
@@ -1011,7 +1028,7 @@ static int read_convert_config(const char *var, const char *value, void *cb)
if (!strncmp(drv->name, name, namelen) && !drv->name[namelen])
break;
if (!drv) {
- drv = xcalloc(1, sizeof(struct convert_driver));
+ CALLOC_ARRAY(drv, 1);
drv->name = xmemdupz(name, namelen);
*user_convert_tail = drv;
user_convert_tail = &(drv->next);
@@ -1368,7 +1385,7 @@ int would_convert_to_git_filter_fd(const struct index_state *istate, const char
if (!ca.drv->required)
return 0;
- return apply_filter(path, NULL, 0, -1, NULL, ca.drv, CAP_CLEAN, NULL);
+ return apply_filter(path, NULL, 0, -1, NULL, ca.drv, CAP_CLEAN, NULL, NULL);
}
const char *get_convert_attr_ascii(const struct index_state *istate, const char *path)
@@ -1406,7 +1423,7 @@ int convert_to_git(const struct index_state *istate,
convert_attrs(istate, &ca, path);
- ret |= apply_filter(path, src, len, -1, dst, ca.drv, CAP_CLEAN, NULL);
+ ret |= apply_filter(path, src, len, -1, dst, ca.drv, CAP_CLEAN, NULL, NULL);
if (!ret && ca.drv && ca.drv->required)
die(_("%s: clean filter '%s' failed"), path, ca.drv->name);
@@ -1441,7 +1458,7 @@ void convert_to_git_filter_fd(const struct index_state *istate,
assert(ca.drv);
assert(ca.drv->clean || ca.drv->process);
- if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN, NULL))
+ if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN, NULL, NULL))
die(_("%s: clean filter '%s' failed"), path, ca.drv->name);
encode_to_git(path, dst->buf, dst->len, dst, ca.working_tree_encoding, conv_flags);
@@ -1452,7 +1469,9 @@ void convert_to_git_filter_fd(const struct index_state *istate,
static int convert_to_working_tree_internal(const struct index_state *istate,
const char *path, const char *src,
size_t len, struct strbuf *dst,
- int normalizing, struct delayed_checkout *dco)
+ int normalizing,
+ const struct checkout_metadata *meta,
+ struct delayed_checkout *dco)
{
int ret = 0, ret_filter = 0;
struct conv_attrs ca;
@@ -1484,7 +1503,7 @@ static int convert_to_working_tree_internal(const struct index_state *istate,
}
ret_filter = apply_filter(
- path, src, len, -1, dst, ca.drv, CAP_SMUDGE, dco);
+ path, src, len, -1, dst, ca.drv, CAP_SMUDGE, meta, dco);
if (!ret_filter && ca.drv && ca.drv->required)
die(_("%s: smudge filter %s failed"), path, ca.drv->name);
@@ -1494,22 +1513,24 @@ static int convert_to_working_tree_internal(const struct index_state *istate,
int async_convert_to_working_tree(const struct index_state *istate,
const char *path, const char *src,
size_t len, struct strbuf *dst,
+ const struct checkout_metadata *meta,
void *dco)
{
- return convert_to_working_tree_internal(istate, path, src, len, dst, 0, dco);
+ return convert_to_working_tree_internal(istate, path, src, len, dst, 0, meta, dco);
}
int convert_to_working_tree(const struct index_state *istate,
const char *path, const char *src,
- size_t len, struct strbuf *dst)
+ size_t len, struct strbuf *dst,
+ const struct checkout_metadata *meta)
{
- return convert_to_working_tree_internal(istate, path, src, len, dst, 0, NULL);
+ return convert_to_working_tree_internal(istate, path, src, len, dst, 0, meta, NULL);
}
int renormalize_buffer(const struct index_state *istate, const char *path,
const char *src, size_t len, struct strbuf *dst)
{
- int ret = convert_to_working_tree_internal(istate, path, src, len, dst, 1, NULL);
+ int ret = convert_to_working_tree_internal(istate, path, src, len, dst, 1, NULL, NULL);
if (ret) {
src = dst->buf;
len = dst->len;
@@ -1982,3 +2003,25 @@ int stream_filter(struct stream_filter *filter,
{
return filter->vtbl->filter(filter, input, isize_p, output, osize_p);
}
+
+void init_checkout_metadata(struct checkout_metadata *meta, const char *refname,
+ const struct object_id *treeish,
+ const struct object_id *blob)
+{
+ memset(meta, 0, sizeof(*meta));
+ if (refname)
+ meta->refname = refname;
+ if (treeish)
+ oidcpy(&meta->treeish, treeish);
+ if (blob)
+ oidcpy(&meta->blob, blob);
+}
+
+void clone_checkout_metadata(struct checkout_metadata *dst,
+ const struct checkout_metadata *src,
+ const struct object_id *blob)
+{
+ memcpy(dst, src, sizeof(*dst));
+ if (blob)
+ oidcpy(&dst->blob, blob);
+}