Merge branches 'bp/reset-quiet' and 'js/mingw-http-ssl' into nd/config-split
[gitweb.git] / builtin / cat-file.c
index 3ed1d0be806c488647e9c85579813b72b5e7016b..8d97c84725cd0f7f5347e8ca808072bd227d4d1c 100644 (file)
@@ -40,7 +40,7 @@ static int filter_object(const char *path, unsigned mode,
                             oid_to_hex(oid), path);
        if ((type == OBJ_BLOB) && S_ISREG(mode)) {
                struct strbuf strbuf = STRBUF_INIT;
-               if (convert_to_working_tree(path, *buf, *size, &strbuf)) {
+               if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) {
                        free(*buf);
                        *size = strbuf.len;
                        *buf = strbuf_detach(&strbuf, NULL);
@@ -113,7 +113,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
                        die("git cat-file --textconv %s: <object> must be <sha1:path>",
                            obj_name);
 
-               if (textconv_object(path, obj_context.mode, &oid, 1, &buf, &size))
+               if (textconv_object(the_repository, path, obj_context.mode,
+                                   &oid, 1, &buf, &size))
                        break;
                /* else fallthrough */
 
@@ -305,7 +306,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
                                            oid_to_hex(oid), data->rest);
                        } else if (opt->cmdmode == 'c') {
                                enum object_type type;
-                               if (!textconv_object(data->rest, 0100644, oid,
+                               if (!textconv_object(the_repository,
+                                                    data->rest, 0100644, oid,
                                                     1, &contents, &size))
                                        contents = read_object_file(oid,
                                                                    &type,
@@ -338,11 +340,11 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
        }
 }
 
-static void batch_object_write(const char *obj_name, struct batch_options *opt,
+static void batch_object_write(const char *obj_name,
+                              struct strbuf *scratch,
+                              struct batch_options *opt,
                               struct expand_data *data)
 {
-       struct strbuf buf = STRBUF_INIT;
-
        if (!data->skip_object_info &&
            oid_object_info_extended(the_repository, &data->oid, &data->info,
                                     OBJECT_INFO_LOOKUP_REPLACE) < 0) {
@@ -352,10 +354,10 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
                return;
        }
 
-       strbuf_expand(&buf, opt->format, expand_format, data);
-       strbuf_addch(&buf, '\n');
-       batch_write(opt, buf.buf, buf.len);
-       strbuf_release(&buf);
+       strbuf_reset(scratch);
+       strbuf_expand(scratch, opt->format, expand_format, data);
+       strbuf_addch(scratch, '\n');
+       batch_write(opt, scratch->buf, scratch->len);
 
        if (opt->print_contents) {
                print_object_or_die(opt, data);
@@ -363,7 +365,9 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
        }
 }
 
-static void batch_one_object(const char *obj_name, struct batch_options *opt,
+static void batch_one_object(const char *obj_name,
+                            struct strbuf *scratch,
+                            struct batch_options *opt,
                             struct expand_data *data)
 {
        struct object_context ctx;
@@ -405,20 +409,21 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
                return;
        }
 
-       batch_object_write(obj_name, opt, data);
+       batch_object_write(obj_name, scratch, opt, data);
 }
 
 struct object_cb_data {
        struct batch_options *opt;
        struct expand_data *expand;
        struct oidset *seen;
+       struct strbuf *scratch;
 };
 
 static int batch_object_cb(const struct object_id *oid, void *vdata)
 {
        struct object_cb_data *data = vdata;
        oidcpy(&data->expand->oid, oid);
-       batch_object_write(NULL, data->opt, data->expand);
+       batch_object_write(NULL, data->scratch, data->opt, data->expand);
        return 0;
 }
 
@@ -509,6 +514,7 @@ static int batch_objects(struct batch_options *opt)
 
                cb.opt = opt;
                cb.expand = &data;
+               cb.scratch = &output;
 
                if (opt->unordered) {
                        struct oidset seen = OIDSET_INIT;
@@ -531,6 +537,7 @@ static int batch_objects(struct batch_options *opt)
                        oid_array_clear(&sa);
                }
 
+               strbuf_release(&output);
                return 0;
        }
 
@@ -559,10 +566,11 @@ static int batch_objects(struct batch_options *opt)
                        data.rest = p;
                }
 
-               batch_one_object(input.buf, opt, &data);
+               batch_one_object(input.buf, &output, opt, &data);
        }
 
        strbuf_release(&input);
+       strbuf_release(&output);
        warn_on_object_refname_ambiguity = save_warning;
        return retval;
 }