]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/cat-file.c
object-file.h: move declarations for object-file.c functions from cache.h
[thirdparty/git.git] / builtin / cat-file.c
index b3be58b1fb06678376568753f9fc221d8cfb3750..0bafc14e6c03ac1c034e64878b884ebcb15128af 100644 (file)
@@ -5,18 +5,28 @@
  */
 #define USE_THE_INDEX_VARIABLE
 #include "cache.h"
+#include "alloc.h"
 #include "config.h"
+#include "convert.h"
 #include "builtin.h"
 #include "diff.h"
+#include "environment.h"
+#include "gettext.h"
+#include "hex.h"
+#include "ident.h"
 #include "parse-options.h"
 #include "userdiff.h"
 #include "streaming.h"
 #include "tree-walk.h"
 #include "oid-array.h"
 #include "packfile.h"
+#include "object-file.h"
+#include "object-name.h"
 #include "object-store.h"
+#include "replace-object.h"
 #include "promisor-remote.h"
 #include "mailmap.h"
+#include "write-or-die.h"
 
 enum batch_mode {
        BATCH_MODE_CONTENTS,
@@ -60,7 +70,7 @@ static int filter_object(const char *path, unsigned mode,
 {
        enum object_type type;
 
-       *buf = read_object_file(oid, &type, size);
+       *buf = repo_read_object_file(the_repository, oid, &type, size);
        if (!*buf)
                return error(_("cannot read object %s '%s'"),
                             oid_to_hex(oid), path);
@@ -132,14 +142,27 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 
        case 's':
                oi.sizep = &size;
+
+               if (use_mailmap) {
+                       oi.typep = &type;
+                       oi.contentp = (void**)&buf;
+               }
+
                if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
                        die("git cat-file: could not get object info");
+
+               if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
+                       size_t s = size;
+                       buf = replace_idents_using_mailmap(buf, &s);
+                       size = cast_size_t_to_ulong(s);
+               }
+
                printf("%"PRIuMAX"\n", (uintmax_t)size);
                ret = 0;
                goto cleanup;
 
        case 'e':
-               return !has_object_file(&oid);
+               return !repo_has_object_file(the_repository, &oid);
 
        case 'w':
 
@@ -174,7 +197,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
                        ret = stream_blob(&oid);
                        goto cleanup;
                }
-               buf = read_object_file(&oid, &type, &size);
+               buf = repo_read_object_file(the_repository, &oid, &type,
+                                           &size);
                if (!buf)
                        die("Cannot read object %s", obj_name);
 
@@ -194,8 +218,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
                if (exp_type_id == OBJ_BLOB) {
                        struct object_id blob_oid;
                        if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
-                               char *buffer = read_object_file(&oid, &type,
-                                                               &size);
+                               char *buffer = repo_read_object_file(the_repository,
+                                                                    &oid,
+                                                                    &type,
+                                                                    &size);
                                const char *target;
                                if (!skip_prefix(buffer, "object ", &target) ||
                                    get_oid_hex(target, &blob_oid))
@@ -370,9 +396,10 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
                                if (!textconv_object(the_repository,
                                                     data->rest, 0100644, oid,
                                                     1, &contents, &size))
-                                       contents = read_object_file(oid,
-                                                                   &type,
-                                                                   &size);
+                                       contents = repo_read_object_file(the_repository,
+                                                                        oid,
+                                                                        &type,
+                                                                        &size);
                                if (!contents)
                                        die("could not convert '%s' %s",
                                            oid_to_hex(oid), data->rest);
@@ -389,7 +416,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
                unsigned long size;
                void *contents;
 
-               contents = read_object_file(oid, &type, &size);
+               contents = repo_read_object_file(the_repository, oid, &type,
+                                                &size);
 
                if (use_mailmap) {
                        size_t s = size;
@@ -431,6 +459,9 @@ static void batch_object_write(const char *obj_name,
        if (!data->skip_object_info) {
                int ret;
 
+               if (use_mailmap)
+                       data->info.typep = &data->type;
+
                if (pack)
                        ret = packed_object_info(the_repository, pack, offset,
                                                 &data->info);
@@ -444,6 +475,18 @@ static void batch_object_write(const char *obj_name,
                        fflush(stdout);
                        return;
                }
+
+               if (use_mailmap && (data->type == OBJ_COMMIT || data->type == OBJ_TAG)) {
+                       size_t s = data->size;
+                       char *buf = NULL;
+
+                       buf = repo_read_object_file(the_repository, &data->oid, &data->type,
+                                                   &data->size);
+                       buf = replace_idents_using_mailmap(buf, &s);
+                       data->size = cast_size_t_to_ulong(s);
+
+                       free(buf);
+               }
        }
 
        strbuf_reset(scratch);
@@ -531,7 +574,7 @@ static int batch_object_cb(const struct object_id *oid, void *vdata)
 }
 
 static int collect_loose_object(const struct object_id *oid,
-                               const char *path,
+                               const char *path UNUSED,
                                void *data)
 {
        oid_array_append(data, oid);
@@ -539,8 +582,8 @@ static int collect_loose_object(const struct object_id *oid,
 }
 
 static int collect_packed_object(const struct object_id *oid,
-                                struct packed_git *pack,
-                                uint32_t pos,
+                                struct packed_git *pack UNUSED,
+                                uint32_t pos UNUSED,
                                 void *data)
 {
        oid_array_append(data, oid);
@@ -563,7 +606,7 @@ static int batch_unordered_object(const struct object_id *oid,
 }
 
 static int batch_unordered_loose(const struct object_id *oid,
-                                const char *path,
+                                const char *path UNUSED,
                                 void *data)
 {
        return batch_unordered_object(oid, NULL, 0, data);
@@ -759,7 +802,7 @@ static int batch_objects(struct batch_options *opt)
                if (!memcmp(&data.info, &empty, sizeof(empty)))
                        data.skip_object_info = 1;
 
-               if (has_promisor_remote())
+               if (repo_has_promisor_remote(the_repository))
                        warning("This repository uses promisor remotes. Some objects may not be loaded.");
 
                read_replace_refs = 0;