sha1-name.c: remove implicit dependency on the_index
[gitweb.git] / builtin / cat-file.c
index 0f6b692df6bfc5704fd853e7d5ee6222a352d71e..7622c502f0090ddec9c094514eed93b5b1c81e53 100644 (file)
@@ -50,6 +50,13 @@ static int filter_object(const char *path, unsigned mode,
        return 0;
 }
 
+static int stream_blob(const struct object_id *oid)
+{
+       if (stream_blob_to_fd(1, oid, NULL, 0))
+               die("unable to stream %s to stdout", oid_to_hex(oid));
+       return 0;
+}
+
 static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
                        int unknown_type)
 {
@@ -66,7 +73,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
        if (unknown_type)
                flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
 
-       if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
+       if (get_oid_with_context(the_repository, obj_name,
+                                GET_OID_RECORD_PATH,
                                 &oid, &obj_context))
                die("Not a valid object name %s", obj_name);
 
@@ -92,7 +100,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
                oi.sizep = &size;
                if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
                        die("git cat-file: could not get object info");
-               printf("%lu\n", size);
+               printf("%"PRIuMAX"\n", (uintmax_t)size);
                return 0;
 
        case 'e':
@@ -132,7 +140,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
                }
 
                if (type == OBJ_BLOB)
-                       return stream_blob_to_fd(1, &oid, NULL, 0);
+                       return stream_blob(&oid);
                buf = read_object_file(&oid, &type, &size);
                if (!buf)
                        die("Cannot read object %s", obj_name);
@@ -155,7 +163,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
                                oidcpy(&blob_oid, &oid);
 
                        if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB)
-                               return stream_blob_to_fd(1, &blob_oid, NULL, 0);
+                               return stream_blob(&blob_oid);
                        /*
                         * we attempted to dereference a tag to a blob
                         * and failed; there may be new dereference
@@ -238,7 +246,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
                if (data->mark_query)
                        data->info.sizep = &data->size;
                else
-                       strbuf_addf(sb, "%lu", data->size);
+                       strbuf_addf(sb, "%"PRIuMAX , (uintmax_t)data->size);
        } else if (is_atom("objectsize:disk", atom, len)) {
                if (data->mark_query)
                        data->info.disk_sizep = &data->disk_size;
@@ -319,8 +327,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
                                BUG("invalid cmdmode: %c", opt->cmdmode);
                        batch_write(opt, contents, size);
                        free(contents);
-               } else if (stream_blob_to_fd(1, oid, NULL, 0) < 0)
-                       die("unable to stream %s to stdout", oid_to_hex(oid));
+               } else {
+                       stream_blob(oid);
+               }
        }
        else {
                enum object_type type;
@@ -374,7 +383,8 @@ static void batch_one_object(const char *obj_name,
        int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
        enum follow_symlinks_result result;
 
-       result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
+       result = get_oid_with_context(the_repository, obj_name,
+                                     flags, &data->oid, &ctx);
        if (result != FOUND) {
                switch (result) {
                case MISSING_OBJECT:
@@ -595,6 +605,8 @@ static int batch_option_callback(const struct option *opt,
 {
        struct batch_options *bo = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (bo->enabled) {
                return error(_("only one batch option may be specified"));
        }