2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_COMPATIBILITY_MACROS
11 #include "parse-options.h"
13 #include "streaming.h"
14 #include "tree-walk.h"
15 #include "oid-array.h"
17 #include "object-store.h"
18 #include "promisor-remote.h"
23 BATCH_MODE_QUEUE_AND_DISPATCH
,
26 struct batch_options
{
29 enum batch_mode batch_mode
;
33 int transform_mode
; /* may be 'w' or 'c' for --filters or --textconv */
37 static const char *force_path
;
39 static int filter_object(const char *path
, unsigned mode
,
40 const struct object_id
*oid
,
41 char **buf
, unsigned long *size
)
43 enum object_type type
;
45 *buf
= read_object_file(oid
, &type
, size
);
47 return error(_("cannot read object %s '%s'"),
48 oid_to_hex(oid
), path
);
49 if ((type
== OBJ_BLOB
) && S_ISREG(mode
)) {
50 struct strbuf strbuf
= STRBUF_INIT
;
51 struct checkout_metadata meta
;
53 init_checkout_metadata(&meta
, NULL
, NULL
, oid
);
54 if (convert_to_working_tree(&the_index
, path
, *buf
, *size
, &strbuf
, &meta
)) {
57 *buf
= strbuf_detach(&strbuf
, NULL
);
64 static int stream_blob(const struct object_id
*oid
)
66 if (stream_blob_to_fd(1, oid
, NULL
, 0))
67 die("unable to stream %s to stdout", oid_to_hex(oid
));
71 static int cat_one_file(int opt
, const char *exp_type
, const char *obj_name
,
75 enum object_type type
;
78 struct object_context obj_context
;
79 struct object_info oi
= OBJECT_INFO_INIT
;
80 struct strbuf sb
= STRBUF_INIT
;
81 unsigned flags
= OBJECT_INFO_LOOKUP_REPLACE
;
82 unsigned get_oid_flags
= GET_OID_RECORD_PATH
| GET_OID_ONLY_TO_DIE
;
83 const char *path
= force_path
;
84 const int opt_cw
= (opt
== 'c' || opt
== 'w');
86 get_oid_flags
|= GET_OID_REQUIRE_PATH
;
89 flags
|= OBJECT_INFO_ALLOW_UNKNOWN_TYPE
;
91 if (get_oid_with_context(the_repository
, obj_name
, get_oid_flags
, &oid
,
93 die("Not a valid object name %s", obj_name
);
96 path
= obj_context
.path
;
97 if (obj_context
.mode
== S_IFINVALID
)
98 obj_context
.mode
= 0100644;
104 if (oid_object_info_extended(the_repository
, &oid
, &oi
, flags
) < 0)
105 die("git cat-file: could not get object info");
107 printf("%s\n", sb
.buf
);
115 if (oid_object_info_extended(the_repository
, &oid
, &oi
, flags
) < 0)
116 die("git cat-file: could not get object info");
117 printf("%"PRIuMAX
"\n", (uintmax_t)size
);
121 return !has_object_file(&oid
);
125 if (filter_object(path
, obj_context
.mode
,
131 if (textconv_object(the_repository
, path
, obj_context
.mode
,
132 &oid
, 1, &buf
, &size
))
134 /* else fallthrough */
137 type
= oid_object_info(the_repository
, &oid
, NULL
);
139 die("Not a valid object name %s", obj_name
);
141 /* custom pretty-print here */
142 if (type
== OBJ_TREE
) {
143 const char *ls_args
[3] = { NULL
};
144 ls_args
[0] = "ls-tree";
145 ls_args
[1] = obj_name
;
146 return cmd_ls_tree(2, ls_args
, NULL
);
149 if (type
== OBJ_BLOB
)
150 return stream_blob(&oid
);
151 buf
= read_object_file(&oid
, &type
, &size
);
153 die("Cannot read object %s", obj_name
);
155 /* otherwise just spit out the data */
160 enum object_type exp_type_id
= type_from_string(exp_type
);
162 if (exp_type_id
== OBJ_BLOB
) {
163 struct object_id blob_oid
;
164 if (oid_object_info(the_repository
, &oid
, NULL
) == OBJ_TAG
) {
165 char *buffer
= read_object_file(&oid
, &type
,
168 if (!skip_prefix(buffer
, "object ", &target
) ||
169 get_oid_hex(target
, &blob_oid
))
170 die("%s not a valid tag", oid_to_hex(&oid
));
173 oidcpy(&blob_oid
, &oid
);
175 if (oid_object_info(the_repository
, &blob_oid
, NULL
) == OBJ_BLOB
)
176 return stream_blob(&blob_oid
);
178 * we attempted to dereference a tag to a blob
179 * and failed; there may be new dereference
180 * mechanisms this code is not aware of.
181 * fall-back to the usual case.
184 buf
= read_object_with_reference(the_repository
, &oid
,
185 exp_type_id
, &size
, NULL
);
189 die("git cat-file: unknown option: %s", exp_type
);
193 die("git cat-file %s: bad file", obj_name
);
195 write_or_die(1, buf
, size
);
197 free(obj_context
.path
);
202 struct object_id oid
;
203 enum object_type type
;
207 struct object_id delta_base_oid
;
210 * If mark_query is true, we do not expand anything, but rather
211 * just mark the object_info with items we wish to query.
216 * Whether to split the input on whitespace before feeding it to
217 * get_sha1; this is decided during the mark_query phase based on
218 * whether we have a %(rest) token in our format.
220 int split_on_whitespace
;
223 * After a mark_query run, this object_info is set up to be
224 * passed to oid_object_info_extended. It will point to the data
225 * elements above, so you can retrieve the response from there.
227 struct object_info info
;
230 * This flag will be true if the requested batch format and options
231 * don't require us to call oid_object_info, which can then be
234 unsigned skip_object_info
: 1;
237 static int is_atom(const char *atom
, const char *s
, int slen
)
239 int alen
= strlen(atom
);
240 return alen
== slen
&& !memcmp(atom
, s
, alen
);
243 static void expand_atom(struct strbuf
*sb
, const char *atom
, int len
,
246 struct expand_data
*data
= vdata
;
248 if (is_atom("objectname", atom
, len
)) {
249 if (!data
->mark_query
)
250 strbuf_addstr(sb
, oid_to_hex(&data
->oid
));
251 } else if (is_atom("objecttype", atom
, len
)) {
252 if (data
->mark_query
)
253 data
->info
.typep
= &data
->type
;
255 strbuf_addstr(sb
, type_name(data
->type
));
256 } else if (is_atom("objectsize", atom
, len
)) {
257 if (data
->mark_query
)
258 data
->info
.sizep
= &data
->size
;
260 strbuf_addf(sb
, "%"PRIuMAX
, (uintmax_t)data
->size
);
261 } else if (is_atom("objectsize:disk", atom
, len
)) {
262 if (data
->mark_query
)
263 data
->info
.disk_sizep
= &data
->disk_size
;
265 strbuf_addf(sb
, "%"PRIuMAX
, (uintmax_t)data
->disk_size
);
266 } else if (is_atom("rest", atom
, len
)) {
267 if (data
->mark_query
)
268 data
->split_on_whitespace
= 1;
270 strbuf_addstr(sb
, data
->rest
);
271 } else if (is_atom("deltabase", atom
, len
)) {
272 if (data
->mark_query
)
273 data
->info
.delta_base_oid
= &data
->delta_base_oid
;
276 oid_to_hex(&data
->delta_base_oid
));
278 die("unknown format element: %.*s", len
, atom
);
281 static size_t expand_format(struct strbuf
*sb
, const char *start
, void *data
)
287 end
= strchr(start
+ 1, ')');
289 die("format element '%s' does not end in ')'", start
);
291 expand_atom(sb
, start
+ 1, end
- start
- 1, data
);
293 return end
- start
+ 1;
296 static void batch_write(struct batch_options
*opt
, const void *data
, int len
)
298 if (opt
->buffer_output
) {
299 if (fwrite(data
, 1, len
, stdout
) != len
)
300 die_errno("unable to write to stdout");
302 write_or_die(1, data
, len
);
305 static void print_object_or_die(struct batch_options
*opt
, struct expand_data
*data
)
307 const struct object_id
*oid
= &data
->oid
;
309 assert(data
->info
.typep
);
311 if (data
->type
== OBJ_BLOB
) {
312 if (opt
->buffer_output
)
314 if (opt
->transform_mode
) {
319 die("missing path for '%s'", oid_to_hex(oid
));
321 if (opt
->transform_mode
== 'w') {
322 if (filter_object(data
->rest
, 0100644, oid
,
324 die("could not convert '%s' %s",
325 oid_to_hex(oid
), data
->rest
);
326 } else if (opt
->transform_mode
== 'c') {
327 enum object_type type
;
328 if (!textconv_object(the_repository
,
329 data
->rest
, 0100644, oid
,
330 1, &contents
, &size
))
331 contents
= read_object_file(oid
,
335 die("could not convert '%s' %s",
336 oid_to_hex(oid
), data
->rest
);
338 BUG("invalid transform_mode: %c", opt
->transform_mode
);
339 batch_write(opt
, contents
, size
);
346 enum object_type type
;
350 contents
= read_object_file(oid
, &type
, &size
);
352 die("object %s disappeared", oid_to_hex(oid
));
353 if (type
!= data
->type
)
354 die("object %s changed type!?", oid_to_hex(oid
));
355 if (data
->info
.sizep
&& size
!= data
->size
)
356 die("object %s changed size!?", oid_to_hex(oid
));
358 batch_write(opt
, contents
, size
);
363 static void print_default_format(struct strbuf
*scratch
, struct expand_data
*data
)
365 strbuf_addf(scratch
, "%s %s %"PRIuMAX
"\n", oid_to_hex(&data
->oid
),
366 type_name(data
->type
),
367 (uintmax_t)data
->size
);
371 * If "pack" is non-NULL, then "offset" is the byte offset within the pack from
372 * which the object may be accessed (though note that we may also rely on
373 * data->oid, too). If "pack" is NULL, then offset is ignored.
375 static void batch_object_write(const char *obj_name
,
376 struct strbuf
*scratch
,
377 struct batch_options
*opt
,
378 struct expand_data
*data
,
379 struct packed_git
*pack
,
382 if (!data
->skip_object_info
) {
386 ret
= packed_object_info(the_repository
, pack
, offset
,
389 ret
= oid_object_info_extended(the_repository
,
390 &data
->oid
, &data
->info
,
391 OBJECT_INFO_LOOKUP_REPLACE
);
393 printf("%s missing\n",
394 obj_name
? obj_name
: oid_to_hex(&data
->oid
));
400 strbuf_reset(scratch
);
403 print_default_format(scratch
, data
);
405 strbuf_expand(scratch
, opt
->format
, expand_format
, data
);
406 strbuf_addch(scratch
, '\n');
409 batch_write(opt
, scratch
->buf
, scratch
->len
);
411 if (opt
->batch_mode
== BATCH_MODE_CONTENTS
) {
412 print_object_or_die(opt
, data
);
413 batch_write(opt
, "\n", 1);
417 static void batch_one_object(const char *obj_name
,
418 struct strbuf
*scratch
,
419 struct batch_options
*opt
,
420 struct expand_data
*data
)
422 struct object_context ctx
;
423 int flags
= opt
->follow_symlinks
? GET_OID_FOLLOW_SYMLINKS
: 0;
424 enum get_oid_result result
;
426 result
= get_oid_with_context(the_repository
, obj_name
,
427 flags
, &data
->oid
, &ctx
);
428 if (result
!= FOUND
) {
431 printf("%s missing\n", obj_name
);
433 case SHORT_NAME_AMBIGUOUS
:
434 printf("%s ambiguous\n", obj_name
);
436 case DANGLING_SYMLINK
:
437 printf("dangling %"PRIuMAX
"\n%s\n",
438 (uintmax_t)strlen(obj_name
), obj_name
);
441 printf("loop %"PRIuMAX
"\n%s\n",
442 (uintmax_t)strlen(obj_name
), obj_name
);
445 printf("notdir %"PRIuMAX
"\n%s\n",
446 (uintmax_t)strlen(obj_name
), obj_name
);
449 BUG("unknown get_sha1_with_context result %d\n",
458 printf("symlink %"PRIuMAX
"\n%s\n",
459 (uintmax_t)ctx
.symlink_path
.len
,
460 ctx
.symlink_path
.buf
);
465 batch_object_write(obj_name
, scratch
, opt
, data
, NULL
, 0);
468 struct object_cb_data
{
469 struct batch_options
*opt
;
470 struct expand_data
*expand
;
472 struct strbuf
*scratch
;
475 static int batch_object_cb(const struct object_id
*oid
, void *vdata
)
477 struct object_cb_data
*data
= vdata
;
478 oidcpy(&data
->expand
->oid
, oid
);
479 batch_object_write(NULL
, data
->scratch
, data
->opt
, data
->expand
,
484 static int collect_loose_object(const struct object_id
*oid
,
488 oid_array_append(data
, oid
);
492 static int collect_packed_object(const struct object_id
*oid
,
493 struct packed_git
*pack
,
497 oid_array_append(data
, oid
);
501 static int batch_unordered_object(const struct object_id
*oid
,
502 struct packed_git
*pack
, off_t offset
,
505 struct object_cb_data
*data
= vdata
;
507 if (oidset_insert(data
->seen
, oid
))
510 oidcpy(&data
->expand
->oid
, oid
);
511 batch_object_write(NULL
, data
->scratch
, data
->opt
, data
->expand
,
516 static int batch_unordered_loose(const struct object_id
*oid
,
520 return batch_unordered_object(oid
, NULL
, 0, data
);
523 static int batch_unordered_packed(const struct object_id
*oid
,
524 struct packed_git
*pack
,
528 return batch_unordered_object(oid
, pack
,
529 nth_packed_object_offset(pack
, pos
),
533 typedef void (*parse_cmd_fn_t
)(struct batch_options
*, const char *,
534 struct strbuf
*, struct expand_data
*);
541 static void parse_cmd_contents(struct batch_options
*opt
,
543 struct strbuf
*output
,
544 struct expand_data
*data
)
546 opt
->batch_mode
= BATCH_MODE_CONTENTS
;
547 batch_one_object(line
, output
, opt
, data
);
550 static void parse_cmd_info(struct batch_options
*opt
,
552 struct strbuf
*output
,
553 struct expand_data
*data
)
555 opt
->batch_mode
= BATCH_MODE_INFO
;
556 batch_one_object(line
, output
, opt
, data
);
559 static void dispatch_calls(struct batch_options
*opt
,
560 struct strbuf
*output
,
561 struct expand_data
*data
,
562 struct queued_cmd
*cmd
,
567 if (!opt
->buffer_output
)
568 die(_("flush is only for --buffer mode"));
570 for (i
= 0; i
< nr
; i
++)
571 cmd
[i
].fn(opt
, cmd
[i
].line
, output
, data
);
576 static void free_cmds(struct queued_cmd
*cmd
, size_t *nr
)
580 for (i
= 0; i
< *nr
; i
++)
581 FREE_AND_NULL(cmd
[i
].line
);
587 static const struct parse_cmd
{
592 { "contents", parse_cmd_contents
, 1},
593 { "info", parse_cmd_info
, 1},
597 static void batch_objects_command(struct batch_options
*opt
,
598 struct strbuf
*output
,
599 struct expand_data
*data
)
601 struct strbuf input
= STRBUF_INIT
;
602 struct queued_cmd
*queued_cmd
= NULL
;
603 size_t alloc
= 0, nr
= 0;
605 while (!strbuf_getline(&input
, stdin
)) {
607 const struct parse_cmd
*cmd
= NULL
;
608 const char *p
= NULL
, *cmd_end
;
609 struct queued_cmd call
= {0};
612 die(_("empty command in input"));
613 if (isspace(*input
.buf
))
614 die(_("whitespace before command: '%s'"), input
.buf
);
616 for (i
= 0; i
< ARRAY_SIZE(commands
); i
++) {
617 if (!skip_prefix(input
.buf
, commands
[i
].name
, &cmd_end
))
621 if (cmd
->takes_args
) {
623 die(_("%s requires arguments"),
627 } else if (*cmd_end
) {
628 die(_("%s takes no arguments"),
636 die(_("unknown command: '%s'"), input
.buf
);
638 if (!strcmp(cmd
->name
, "flush")) {
639 dispatch_calls(opt
, output
, data
, queued_cmd
, nr
);
640 free_cmds(queued_cmd
, &nr
);
641 } else if (!opt
->buffer_output
) {
642 cmd
->fn(opt
, p
, output
, data
);
644 ALLOC_GROW(queued_cmd
, nr
+ 1, alloc
);
646 call
.line
= xstrdup_or_null(p
);
647 queued_cmd
[nr
++] = call
;
651 if (opt
->buffer_output
&&
653 !git_env_bool("GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT", 0)) {
654 dispatch_calls(opt
, output
, data
, queued_cmd
, nr
);
655 free_cmds(queued_cmd
, &nr
);
659 strbuf_release(&input
);
662 #define DEFAULT_FORMAT "%(objectname) %(objecttype) %(objectsize)"
664 static int batch_objects(struct batch_options
*opt
)
666 struct strbuf input
= STRBUF_INIT
;
667 struct strbuf output
= STRBUF_INIT
;
668 struct expand_data data
;
673 * Expand once with our special mark_query flag, which will prime the
674 * object_info to be handed to oid_object_info_extended for each
677 memset(&data
, 0, sizeof(data
));
679 strbuf_expand(&output
,
680 opt
->format
? opt
->format
: DEFAULT_FORMAT
,
684 strbuf_release(&output
);
685 if (opt
->transform_mode
)
686 data
.split_on_whitespace
= 1;
688 if (opt
->format
&& !strcmp(opt
->format
, DEFAULT_FORMAT
))
691 * If we are printing out the object, then always fill in the type,
692 * since we will want to decide whether or not to stream.
694 if (opt
->batch_mode
== BATCH_MODE_CONTENTS
)
695 data
.info
.typep
= &data
.type
;
697 if (opt
->all_objects
) {
698 struct object_cb_data cb
;
699 struct object_info empty
= OBJECT_INFO_INIT
;
701 if (!memcmp(&data
.info
, &empty
, sizeof(empty
)))
702 data
.skip_object_info
= 1;
704 if (has_promisor_remote())
705 warning("This repository uses promisor remotes. Some objects may not be loaded.");
707 read_replace_refs
= 0;
711 cb
.scratch
= &output
;
713 if (opt
->unordered
) {
714 struct oidset seen
= OIDSET_INIT
;
718 for_each_loose_object(batch_unordered_loose
, &cb
, 0);
719 for_each_packed_object(batch_unordered_packed
, &cb
,
720 FOR_EACH_OBJECT_PACK_ORDER
);
724 struct oid_array sa
= OID_ARRAY_INIT
;
726 for_each_loose_object(collect_loose_object
, &sa
, 0);
727 for_each_packed_object(collect_packed_object
, &sa
, 0);
729 oid_array_for_each_unique(&sa
, batch_object_cb
, &cb
);
731 oid_array_clear(&sa
);
734 strbuf_release(&output
);
739 * We are going to call get_sha1 on a potentially very large number of
740 * objects. In most large cases, these will be actual object sha1s. The
741 * cost to double-check that each one is not also a ref (just so we can
742 * warn) ends up dwarfing the actual cost of the object lookups
743 * themselves. We can work around it by just turning off the warning.
745 save_warning
= warn_on_object_refname_ambiguity
;
746 warn_on_object_refname_ambiguity
= 0;
748 if (opt
->batch_mode
== BATCH_MODE_QUEUE_AND_DISPATCH
) {
749 batch_objects_command(opt
, &output
, &data
);
753 while (strbuf_getline(&input
, stdin
) != EOF
) {
754 if (data
.split_on_whitespace
) {
756 * Split at first whitespace, tying off the beginning
757 * of the string and saving the remainder (or NULL) in
760 char *p
= strpbrk(input
.buf
, " \t");
762 while (*p
&& strchr(" \t", *p
))
768 batch_one_object(input
.buf
, &output
, opt
, &data
);
772 strbuf_release(&input
);
773 strbuf_release(&output
);
774 warn_on_object_refname_ambiguity
= save_warning
;
778 static int git_cat_file_config(const char *var
, const char *value
, void *cb
)
780 if (userdiff_config(var
, value
) < 0)
783 return git_default_config(var
, value
, cb
);
786 static int batch_option_callback(const struct option
*opt
,
790 struct batch_options
*bo
= opt
->value
;
792 BUG_ON_OPT_NEG(unset
);
795 return error(_("only one batch option may be specified"));
800 if (!strcmp(opt
->long_name
, "batch"))
801 bo
->batch_mode
= BATCH_MODE_CONTENTS
;
802 else if (!strcmp(opt
->long_name
, "batch-check"))
803 bo
->batch_mode
= BATCH_MODE_INFO
;
804 else if (!strcmp(opt
->long_name
, "batch-command"))
805 bo
->batch_mode
= BATCH_MODE_QUEUE_AND_DISPATCH
;
807 BUG("%s given to batch-option-callback", opt
->long_name
);
814 int cmd_cat_file(int argc
, const char **argv
, const char *prefix
)
819 const char *exp_type
= NULL
, *obj_name
= NULL
;
820 struct batch_options batch
= {0};
821 int unknown_type
= 0;
823 const char * const usage
[] = {
824 N_("git cat-file <type> <object>"),
825 N_("git cat-file (-e | -p) <object>"),
826 N_("git cat-file (-t | -s) [--allow-unknown-type] <object>"),
827 N_("git cat-file (--batch | --batch-check | --batch-command) [--batch-all-objects]\n"
828 " [--buffer] [--follow-symlinks] [--unordered]\n"
829 " [--textconv | --filters]"),
830 N_("git cat-file (--textconv | --filters)\n"
831 " [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]"),
834 const struct option options
[] = {
836 OPT_GROUP(N_("Check object existence or emit object contents")),
837 OPT_CMDMODE('e', NULL
, &opt
,
838 N_("check if <object> exists"), 'e'),
839 OPT_CMDMODE('p', NULL
, &opt
, N_("pretty-print <object> content"), 'p'),
841 OPT_GROUP(N_("Emit [broken] object attributes")),
842 OPT_CMDMODE('t', NULL
, &opt
, N_("show object type (one of 'blob', 'tree', 'commit', 'tag', ...)"), 't'),
843 OPT_CMDMODE('s', NULL
, &opt
, N_("show object size"), 's'),
844 OPT_BOOL(0, "allow-unknown-type", &unknown_type
,
845 N_("allow -s and -t to work with broken/corrupt objects")),
847 OPT_GROUP(N_("Batch objects requested on stdin (or --batch-all-objects)")),
848 OPT_CALLBACK_F(0, "batch", &batch
, N_("format"),
849 N_("show full <object> or <rev> contents"),
850 PARSE_OPT_OPTARG
| PARSE_OPT_NONEG
,
851 batch_option_callback
),
852 OPT_CALLBACK_F(0, "batch-check", &batch
, N_("format"),
853 N_("like --batch, but don't emit <contents>"),
854 PARSE_OPT_OPTARG
| PARSE_OPT_NONEG
,
855 batch_option_callback
),
856 OPT_CALLBACK_F(0, "batch-command", &batch
, N_("format"),
857 N_("read commands from stdin"),
858 PARSE_OPT_OPTARG
| PARSE_OPT_NONEG
,
859 batch_option_callback
),
860 OPT_CMDMODE(0, "batch-all-objects", &opt
,
861 N_("with --batch[-check]: ignores stdin, batches all known objects"), 'b'),
862 /* Batch-specific options */
863 OPT_GROUP(N_("Change or optimize batch output")),
864 OPT_BOOL(0, "buffer", &batch
.buffer_output
, N_("buffer --batch output")),
865 OPT_BOOL(0, "follow-symlinks", &batch
.follow_symlinks
,
866 N_("follow in-tree symlinks")),
867 OPT_BOOL(0, "unordered", &batch
.unordered
,
868 N_("do not order objects before emitting them")),
869 /* Textconv options, stand-ole*/
870 OPT_GROUP(N_("Emit object (blob or tree) with conversion or filter (stand-alone, or with batch)")),
871 OPT_CMDMODE(0, "textconv", &opt
,
872 N_("run textconv on object's content"), 'c'),
873 OPT_CMDMODE(0, "filters", &opt
,
874 N_("run filters on object's content"), 'w'),
875 OPT_STRING(0, "path", &force_path
, N_("blob|tree"),
876 N_("use a <path> for (--textconv | --filters); Not with 'batch'")),
880 git_config(git_cat_file_config
, NULL
);
882 batch
.buffer_output
= -1;
884 argc
= parse_options(argc
, argv
, prefix
, options
, usage
, 0);
885 opt_cw
= (opt
== 'c' || opt
== 'w');
886 opt_epts
= (opt
== 'e' || opt
== 'p' || opt
== 't' || opt
== 's');
888 /* --batch-all-objects? */
890 batch
.all_objects
= 1;
892 /* Option compatibility */
893 if (force_path
&& !opt_cw
)
894 usage_msg_optf(_("'%s=<%s>' needs '%s' or '%s'"),
896 "--path", _("path|tree-ish"), "--filters",
899 /* Option compatibility with batch mode */
902 else if (batch
.follow_symlinks
)
903 usage_msg_optf(_("'%s' requires a batch mode"), usage
, options
,
904 "--follow-symlinks");
905 else if (batch
.buffer_output
>= 0)
906 usage_msg_optf(_("'%s' requires a batch mode"), usage
, options
,
908 else if (batch
.all_objects
)
909 usage_msg_optf(_("'%s' requires a batch mode"), usage
, options
,
910 "--batch-all-objects");
913 if (batch
.buffer_output
< 0)
914 batch
.buffer_output
= batch
.all_objects
;
916 /* Return early if we're in batch mode? */
919 batch
.transform_mode
= opt
;
920 else if (opt
&& opt
!= 'b')
921 usage_msg_optf(_("'-%c' is incompatible with batch mode"),
922 usage
, options
, opt
);
924 usage_msg_opt(_("batch modes take no arguments"), usage
,
927 return batch_objects(&batch
);
931 if (!argc
&& opt
== 'c')
932 usage_msg_optf(_("<rev> required with '%s'"),
933 usage
, options
, "--textconv");
934 else if (!argc
&& opt
== 'w')
935 usage_msg_optf(_("<rev> required with '%s'"),
936 usage
, options
, "--filters");
937 else if (!argc
&& opt_epts
)
938 usage_msg_optf(_("<object> required with '-%c'"),
939 usage
, options
, opt
);
943 usage_msg_opt(_("too many arguments"), usage
, options
);
945 usage_with_options(usage
, options
);
946 } else if (argc
!= 2) {
947 usage_msg_optf(_("only two arguments allowed in <type> <object> mode, not %d"),
948 usage
, options
, argc
);
954 if (unknown_type
&& opt
!= 't' && opt
!= 's')
955 die("git cat-file --allow-unknown-type: use with -s or -t");
956 return cat_one_file(opt
, exp_type
, obj_name
, unknown_type
);