remote: add promisor and partial clone config to the doc
[gitweb.git] / builtin / cat-file.c
index 0520cecc9a1d963841b384de6173d752e6d78fb7..85ae10bf0b81bf2bb536548528dc177517f3fb49 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
@@ -14,6 +15,7 @@
 #include "sha1-array.h"
 #include "packfile.h"
 #include "object-store.h"
+#include "promisor-remote.h"
 
 struct batch_options {
        int enabled;
@@ -73,7 +75,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);
 
@@ -99,7 +102,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':
@@ -120,7 +123,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 */
 
@@ -208,14 +212,14 @@ struct expand_data {
 
        /*
         * After a mark_query run, this object_info is set up to be
-        * passed to sha1_object_info_extended. It will point to the data
+        * passed to oid_object_info_extended. It will point to the data
         * elements above, so you can retrieve the response from there.
         */
        struct object_info info;
 
        /*
         * This flag will be true if the requested batch format and options
-        * don't require us to call sha1_object_info, which can then be
+        * don't require us to call oid_object_info, which can then be
         * optimized out.
         */
        unsigned skip_object_info : 1;
@@ -244,7 +248,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;
@@ -312,7 +316,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,
@@ -378,14 +383,18 @@ static void batch_one_object(const char *obj_name,
 {
        struct object_context ctx;
        int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
-       enum follow_symlinks_result result;
+       enum get_oid_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:
                        printf("%s missing\n", obj_name);
                        break;
+               case SHORT_NAME_AMBIGUOUS:
+                       printf("%s ambiguous\n", obj_name);
+                       break;
                case DANGLING_SYMLINK:
                        printf("dangling %"PRIuMAX"\n%s\n",
                               (uintmax_t)strlen(obj_name), obj_name);
@@ -488,7 +497,7 @@ static int batch_objects(struct batch_options *opt)
 
        /*
         * Expand once with our special mark_query flag, which will prime the
-        * object_info to be handed to sha1_object_info_extended for each
+        * object_info to be handed to oid_object_info_extended for each
         * object.
         */
        memset(&data, 0, sizeof(data));
@@ -515,8 +524,8 @@ static int batch_objects(struct batch_options *opt)
        if (opt->all_objects) {
                struct object_cb_data cb;
 
-               if (repository_format_partial_clone)
-                       warning("This repository has extensions.partialClone set. Some objects may not be loaded.");
+               if (has_promisor_remote())
+                       warning("This repository uses promisor remotes. Some objects may not be loaded.");
 
                cb.opt = opt;
                cb.expand = &data;
@@ -601,8 +610,10 @@ static int batch_option_callback(const struct option *opt,
 {
        struct batch_options *bo = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (bo->enabled) {
-               return 1;
+               return error(_("only one batch option may be specified"));
        }
 
        bo->enabled = 1;
@@ -637,10 +648,12 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "buffer", &batch.buffer_output, N_("buffer --batch output")),
                { OPTION_CALLBACK, 0, "batch", &batch, "format",
                        N_("show info and content of objects fed from the standard input"),
-                       PARSE_OPT_OPTARG, batch_option_callback },
+                       PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
+                       batch_option_callback },
                { OPTION_CALLBACK, 0, "batch-check", &batch, "format",
                        N_("show info about objects fed from the standard input"),
-                       PARSE_OPT_OPTARG, batch_option_callback },
+                       PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
+                       batch_option_callback },
                OPT_BOOL(0, "follow-symlinks", &batch.follow_symlinks,
                         N_("follow in-tree symlinks (used with --batch or --batch-check)")),
                OPT_BOOL(0, "batch-all-objects", &batch.all_objects,