@@ -380,6 +380,12 @@ static int batch_objects(struct batch_options *batch, const struct option *optio
if (batch->print_contents)
strbuf_addstr(&format, "\n%(raw)");
batch->format.format = format.buf;
+
+ if (batch->cmdmode == 'c')
+ batch->format.use_textconv = 1;
+ else if (batch->cmdmode == 'w')
+ batch->format.use_filters = 1;
+
if (verify_ref_format(&batch->format))
usage_with_options(cat_file_usage, options);
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "parse-options.h"
@@ -84,6 +85,9 @@ static struct expand_data {
struct object_info info;
} oi, oi_deref;
+int use_filters;
+int use_textconv;
+
struct ref_to_worktree_entry {
struct hashmap_entry ent;
struct worktree *wt; /* key is wt->head_ref */
@@ -1031,6 +1035,9 @@ int verify_ref_format(struct ref_format *format)
used_atom[at].atom_type == ATOM_WORKTREEPATH)))
die(_("this command reject atom %%(%.*s)"), (int)(ep - sp - 2), sp + 2);
+ use_filters = format->use_filters;
+ use_textconv = format->use_textconv;
+
if ((format->quote_style == QUOTE_PYTHON ||
format->quote_style == QUOTE_SHELL ||
format->quote_style == QUOTE_TCL) &&
@@ -1742,10 +1749,38 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
{
/* parse_object_buffer() will set eaten to 0 if free() will be needed */
int eaten = 1;
+ struct expand_data *actual_oi = oi;
+ struct expand_data act_oi = {0};
+
if (oi->info.contentp) {
/* We need to know that to use parse_object_buffer properly */
+ void **temp_contentp = oi->info.contentp;
+ oi->info.contentp = NULL;
oi->info.sizep = &oi->size;
oi->info.typep = &oi->type;
+
+ /* get the type and size */
+ if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
+ OBJECT_INFO_LOOKUP_REPLACE))
+ return strbuf_addf_ret(err, 1, _("%s missing"),
+ oid_to_hex(&oi->oid));
+
+ oi->info.sizep = NULL;
+ oi->info.typep = NULL;
+ oi->info.contentp = temp_contentp;
+
+ if (use_textconv && !ref->rest)
+ return strbuf_addf_ret(err, -1, _("missing path for '%s'"),
+ oid_to_hex(&act_oi.oid));
+ if (use_textconv && oi->type == OBJ_BLOB) {
+ act_oi = *oi;
+ if (textconv_object(the_repository,
+ ref->rest, 0100644, &act_oi.oid,
+ 1, (char **)(&act_oi.content), &act_oi.size)) {
+ actual_oi = &act_oi;
+ goto success;
+ }
+ }
}
if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
OBJECT_INFO_LOOKUP_REPLACE))
@@ -1755,19 +1790,39 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
BUG("Object size is less than zero.");
if (oi->info.contentp) {
- *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten);
+ if (use_filters && !ref->rest)
+ return strbuf_addf_ret(err, -1, _("missing path for '%s'"),
+ oid_to_hex(&oi->oid));
+ if (use_filters && oi->type == OBJ_BLOB) {
+ struct strbuf strbuf = STRBUF_INIT;
+ struct checkout_metadata meta;
+ act_oi = *oi;
+
+ init_checkout_metadata(&meta, NULL, NULL, &act_oi.oid);
+ if (!convert_to_working_tree(&the_index, ref->rest, act_oi.content, act_oi.size, &strbuf, &meta))
+ die("could not convert '%s' %s",
+ oid_to_hex(&oi->oid), ref->rest);
+ act_oi.size = strbuf.len;
+ act_oi.content = strbuf_detach(&strbuf, NULL);
+ actual_oi = &act_oi;
+ }
+
+success:
+ *obj = parse_object_buffer(the_repository, &actual_oi->oid, actual_oi->type, actual_oi->size, actual_oi->content, &eaten);
if (!*obj) {
if (!eaten)
free(oi->content);
return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
oid_to_hex(&oi->oid), ref->refname);
}
- grab_values(ref->value, deref, *obj, oi);
+ grab_values(ref->value, deref, *obj, actual_oi);
}
grab_common_values(ref->value, deref, oi);
if (!eaten)
free(oi->content);
+ if (actual_oi != oi)
+ free(actual_oi->content);
return 0;
}
@@ -80,6 +80,8 @@ struct ref_format {
const char *rest;
int cat_file_mode;
int quote_style;
+ int use_textconv;
+ int use_filters;
int use_rest;
int use_color;