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
,
76 enum object_type type
;
79 struct object_context obj_context
;
80 struct object_info oi
= OBJECT_INFO_INIT
;
81 struct strbuf sb
= STRBUF_INIT
;
82 unsigned flags
= OBJECT_INFO_LOOKUP_REPLACE
;
83 unsigned get_oid_flags
= GET_OID_RECORD_PATH
| GET_OID_ONLY_TO_DIE
;
84 const char *path
= force_path
;
85 const int opt_cw
= (opt
== 'c' || opt
== 'w');
87 get_oid_flags
|= GET_OID_REQUIRE_PATH
;
90 flags
|= OBJECT_INFO_ALLOW_UNKNOWN_TYPE
;
92 if (get_oid_with_context(the_repository
, obj_name
, get_oid_flags
, &oid
,
94 die("Not a valid object name %s", obj_name
);
97 path
= obj_context
.path
;
98 if (obj_context
.mode
== S_IFINVALID
)
99 obj_context
.mode
= 0100644;
105 if (oid_object_info_extended(the_repository
, &oid
, &oi
, flags
) < 0)
106 die("git cat-file: could not get object info");
108 printf("%s\n", sb
.buf
);
117 if (oid_object_info_extended(the_repository
, &oid
, &oi
, flags
) < 0)
118 die("git cat-file: could not get object info");
119 printf("%"PRIuMAX
"\n", (uintmax_t)size
);
124 return !has_object_file(&oid
);
128 if (filter_object(path
, obj_context
.mode
,
129 &oid
, &buf
, &size
)) {
136 if (textconv_object(the_repository
, path
, obj_context
.mode
,
137 &oid
, 1, &buf
, &size
))
139 /* else fallthrough */
142 type
= oid_object_info(the_repository
, &oid
, NULL
);
144 die("Not a valid object name %s", obj_name
);
146 /* custom pretty-print here */
147 if (type
== OBJ_TREE
) {
148 const char *ls_args
[3] = { NULL
};
149 ls_args
[0] = "ls-tree";
150 ls_args
[1] = obj_name
;
151 ret
= cmd_ls_tree(2, ls_args
, NULL
);
155 if (type
== OBJ_BLOB
) {
156 ret
= stream_blob(&oid
);
159 buf
= read_object_file(&oid
, &type
, &size
);
161 die("Cannot read object %s", obj_name
);
163 /* otherwise just spit out the data */
168 enum object_type exp_type_id
= type_from_string(exp_type
);
170 if (exp_type_id
== OBJ_BLOB
) {
171 struct object_id blob_oid
;
172 if (oid_object_info(the_repository
, &oid
, NULL
) == OBJ_TAG
) {
173 char *buffer
= read_object_file(&oid
, &type
,
176 if (!skip_prefix(buffer
, "object ", &target
) ||
177 get_oid_hex(target
, &blob_oid
))
178 die("%s not a valid tag", oid_to_hex(&oid
));
181 oidcpy(&blob_oid
, &oid
);
183 if (oid_object_info(the_repository
, &blob_oid
, NULL
) == OBJ_BLOB
) {
184 ret
= stream_blob(&blob_oid
);
188 * we attempted to dereference a tag to a blob
189 * and failed; there may be new dereference
190 * mechanisms this code is not aware of.
191 * fall-back to the usual case.
194 buf
= read_object_with_reference(the_repository
, &oid
,
195 exp_type_id
, &size
, NULL
);
199 die("git cat-file: unknown option: %s", exp_type
);
203 die("git cat-file %s: bad file", obj_name
);
205 write_or_die(1, buf
, size
);
209 free(obj_context
.path
);
214 struct object_id oid
;
215 enum object_type type
;
219 struct object_id delta_base_oid
;
222 * If mark_query is true, we do not expand anything, but rather
223 * just mark the object_info with items we wish to query.
228 * Whether to split the input on whitespace before feeding it to
229 * get_sha1; this is decided during the mark_query phase based on
230 * whether we have a %(rest) token in our format.
232 int split_on_whitespace
;
235 * After a mark_query run, this object_info is set up to be
236 * passed to oid_object_info_extended. It will point to the data
237 * elements above, so you can retrieve the response from there.
239 struct object_info info
;
242 * This flag will be true if the requested batch format and options
243 * don't require us to call oid_object_info, which can then be
246 unsigned skip_object_info
: 1;
249 static int is_atom(const char *atom
, const char *s
, int slen
)
251 int alen
= strlen(atom
);
252 return alen
== slen
&& !memcmp(atom
, s
, alen
);
255 static void expand_atom(struct strbuf
*sb
, const char *atom
, int len
,
258 struct expand_data
*data
= vdata
;
260 if (is_atom("objectname", atom
, len
)) {
261 if (!data
->mark_query
)
262 strbuf_addstr(sb
, oid_to_hex(&data
->oid
));
263 } else if (is_atom("objecttype", atom
, len
)) {
264 if (data
->mark_query
)
265 data
->info
.typep
= &data
->type
;
267 strbuf_addstr(sb
, type_name(data
->type
));
268 } else if (is_atom("objectsize", atom
, len
)) {
269 if (data
->mark_query
)
270 data
->info
.sizep
= &data
->size
;
272 strbuf_addf(sb
, "%"PRIuMAX
, (uintmax_t)data
->size
);
273 } else if (is_atom("objectsize:disk", atom
, len
)) {
274 if (data
->mark_query
)
275 data
->info
.disk_sizep
= &data
->disk_size
;
277 strbuf_addf(sb
, "%"PRIuMAX
, (uintmax_t)data
->disk_size
);
278 } else if (is_atom("rest", atom
, len
)) {
279 if (data
->mark_query
)
280 data
->split_on_whitespace
= 1;
282 strbuf_addstr(sb
, data
->rest
);
283 } else if (is_atom("deltabase", atom
, len
)) {
284 if (data
->mark_query
)
285 data
->info
.delta_base_oid
= &data
->delta_base_oid
;
288 oid_to_hex(&data
->delta_base_oid
));
290 die("unknown format element: %.*s", len
, atom
);
293 static size_t expand_format(struct strbuf
*sb
, const char *start
, void *data
)
299 end
= strchr(start
+ 1, ')');
301 die("format element '%s' does not end in ')'", start
);
303 expand_atom(sb
, start
+ 1, end
- start
- 1, data
);
305 return end
- start
+ 1;
308 static void batch_write(struct batch_options
*opt
, const void *data
, int len
)
310 if (opt
->buffer_output
) {
311 if (fwrite(data
, 1, len
, stdout
) != len
)
312 die_errno("unable to write to stdout");
314 write_or_die(1, data
, len
);
317 static void print_object_or_die(struct batch_options
*opt
, struct expand_data
*data
)
319 const struct object_id
*oid
= &data
->oid
;
321 assert(data
->info
.typep
);
323 if (data
->type
== OBJ_BLOB
) {
324 if (opt
->buffer_output
)
326 if (opt
->transform_mode
) {
331 die("missing path for '%s'", oid_to_hex(oid
));
333 if (opt
->transform_mode
== 'w') {
334 if (filter_object(data
->rest
, 0100644, oid
,
336 die("could not convert '%s' %s",
337 oid_to_hex(oid
), data
->rest
);
338 } else if (opt
->transform_mode
== 'c') {
339 enum object_type type
;
340 if (!textconv_object(the_repository
,
341 data
->rest
, 0100644, oid
,
342 1, &contents
, &size
))
343 contents
= read_object_file(oid
,
347 die("could not convert '%s' %s",
348 oid_to_hex(oid
), data
->rest
);
350 BUG("invalid transform_mode: %c", opt
->transform_mode
);
351 batch_write(opt
, contents
, size
);
358 enum object_type type
;
362 contents
= read_object_file(oid
, &type
, &size
);
364 die("object %s disappeared", oid_to_hex(oid
));
365 if (type
!= data
->type
)
366 die("object %s changed type!?", oid_to_hex(oid
));
367 if (data
->info
.sizep
&& size
!= data
->size
)
368 die("object %s changed size!?", oid_to_hex(oid
));
370 batch_write(opt
, contents
, size
);
375 static void print_default_format(struct strbuf
*scratch
, struct expand_data
*data
)
377 strbuf_addf(scratch
, "%s %s %"PRIuMAX
"\n", oid_to_hex(&data
->oid
),
378 type_name(data
->type
),
379 (uintmax_t)data
->size
);
383 * If "pack" is non-NULL, then "offset" is the byte offset within the pack from
384 * which the object may be accessed (though note that we may also rely on
385 * data->oid, too). If "pack" is NULL, then offset is ignored.
387 static void batch_object_write(const char *obj_name
,
388 struct strbuf
*scratch
,
389 struct batch_options
*opt
,
390 struct expand_data
*data
,
391 struct packed_git
*pack
,
394 if (!data
->skip_object_info
) {
398 ret
= packed_object_info(the_repository
, pack
, offset
,
401 ret
= oid_object_info_extended(the_repository
,
402 &data
->oid
, &data
->info
,
403 OBJECT_INFO_LOOKUP_REPLACE
);
405 printf("%s missing\n",
406 obj_name
? obj_name
: oid_to_hex(&data
->oid
));
412 strbuf_reset(scratch
);
415 print_default_format(scratch
, data
);
417 strbuf_expand(scratch
, opt
->format
, expand_format
, data
);
418 strbuf_addch(scratch
, '\n');
421 batch_write(opt
, scratch
->buf
, scratch
->len
);
423 if (opt
->batch_mode
== BATCH_MODE_CONTENTS
) {
424 print_object_or_die(opt
, data
);
425 batch_write(opt
, "\n", 1);
429 static void batch_one_object(const char *obj_name
,
430 struct strbuf
*scratch
,
431 struct batch_options
*opt
,
432 struct expand_data
*data
)
434 struct object_context ctx
;
435 int flags
= opt
->follow_symlinks
? GET_OID_FOLLOW_SYMLINKS
: 0;
436 enum get_oid_result result
;
438 result
= get_oid_with_context(the_repository
, obj_name
,
439 flags
, &data
->oid
, &ctx
);
440 if (result
!= FOUND
) {
443 printf("%s missing\n", obj_name
);
445 case SHORT_NAME_AMBIGUOUS
:
446 printf("%s ambiguous\n", obj_name
);
448 case DANGLING_SYMLINK
:
449 printf("dangling %"PRIuMAX
"\n%s\n",
450 (uintmax_t)strlen(obj_name
), obj_name
);
453 printf("loop %"PRIuMAX
"\n%s\n",
454 (uintmax_t)strlen(obj_name
), obj_name
);
457 printf("notdir %"PRIuMAX
"\n%s\n",
458 (uintmax_t)strlen(obj_name
), obj_name
);
461 BUG("unknown get_sha1_with_context result %d\n",
470 printf("symlink %"PRIuMAX
"\n%s\n",
471 (uintmax_t)ctx
.symlink_path
.len
,
472 ctx
.symlink_path
.buf
);
477 batch_object_write(obj_name
, scratch
, opt
, data
, NULL
, 0);
480 struct object_cb_data
{
481 struct batch_options
*opt
;
482 struct expand_data
*expand
;
484 struct strbuf
*scratch
;
487 static int batch_object_cb(const struct object_id
*oid
, void *vdata
)
489 struct object_cb_data
*data
= vdata
;
490 oidcpy(&data
->expand
->oid
, oid
);
491 batch_object_write(NULL
, data
->scratch
, data
->opt
, data
->expand
,
496 static int collect_loose_object(const struct object_id
*oid
,
500 oid_array_append(data
, oid
);
504 static int collect_packed_object(const struct object_id
*oid
,
505 struct packed_git
*pack
,
509 oid_array_append(data
, oid
);
513 static int batch_unordered_object(const struct object_id
*oid
,
514 struct packed_git
*pack
, off_t offset
,
517 struct object_cb_data
*data
= vdata
;
519 if (oidset_insert(data
->seen
, oid
))
522 oidcpy(&data
->expand
->oid
, oid
);
523 batch_object_write(NULL
, data
->scratch
, data
->opt
, data
->expand
,
528 static int batch_unordered_loose(const struct object_id
*oid
,
532 return batch_unordered_object(oid
, NULL
, 0, data
);
535 static int batch_unordered_packed(const struct object_id
*oid
,
536 struct packed_git
*pack
,
540 return batch_unordered_object(oid
, pack
,
541 nth_packed_object_offset(pack
, pos
),
545 typedef void (*parse_cmd_fn_t
)(struct batch_options
*, const char *,
546 struct strbuf
*, struct expand_data
*);
553 static void parse_cmd_contents(struct batch_options
*opt
,
555 struct strbuf
*output
,
556 struct expand_data
*data
)
558 opt
->batch_mode
= BATCH_MODE_CONTENTS
;
559 batch_one_object(line
, output
, opt
, data
);
562 static void parse_cmd_info(struct batch_options
*opt
,
564 struct strbuf
*output
,
565 struct expand_data
*data
)
567 opt
->batch_mode
= BATCH_MODE_INFO
;
568 batch_one_object(line
, output
, opt
, data
);
571 static void dispatch_calls(struct batch_options
*opt
,
572 struct strbuf
*output
,
573 struct expand_data
*data
,
574 struct queued_cmd
*cmd
,
579 if (!opt
->buffer_output
)
580 die(_("flush is only for --buffer mode"));
582 for (i
= 0; i
< nr
; i
++)
583 cmd
[i
].fn(opt
, cmd
[i
].line
, output
, data
);
588 static void free_cmds(struct queued_cmd
*cmd
, size_t *nr
)
592 for (i
= 0; i
< *nr
; i
++)
593 FREE_AND_NULL(cmd
[i
].line
);
599 static const struct parse_cmd
{
604 { "contents", parse_cmd_contents
, 1},
605 { "info", parse_cmd_info
, 1},
609 static void batch_objects_command(struct batch_options
*opt
,
610 struct strbuf
*output
,
611 struct expand_data
*data
)
613 struct strbuf input
= STRBUF_INIT
;
614 struct queued_cmd
*queued_cmd
= NULL
;
615 size_t alloc
= 0, nr
= 0;
617 while (!strbuf_getline(&input
, stdin
)) {
619 const struct parse_cmd
*cmd
= NULL
;
620 const char *p
= NULL
, *cmd_end
;
621 struct queued_cmd call
= {0};
624 die(_("empty command in input"));
625 if (isspace(*input
.buf
))
626 die(_("whitespace before command: '%s'"), input
.buf
);
628 for (i
= 0; i
< ARRAY_SIZE(commands
); i
++) {
629 if (!skip_prefix(input
.buf
, commands
[i
].name
, &cmd_end
))
633 if (cmd
->takes_args
) {
635 die(_("%s requires arguments"),
639 } else if (*cmd_end
) {
640 die(_("%s takes no arguments"),
648 die(_("unknown command: '%s'"), input
.buf
);
650 if (!strcmp(cmd
->name
, "flush")) {
651 dispatch_calls(opt
, output
, data
, queued_cmd
, nr
);
652 free_cmds(queued_cmd
, &nr
);
653 } else if (!opt
->buffer_output
) {
654 cmd
->fn(opt
, p
, output
, data
);
656 ALLOC_GROW(queued_cmd
, nr
+ 1, alloc
);
658 call
.line
= xstrdup_or_null(p
);
659 queued_cmd
[nr
++] = call
;
663 if (opt
->buffer_output
&&
665 !git_env_bool("GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT", 0)) {
666 dispatch_calls(opt
, output
, data
, queued_cmd
, nr
);
667 free_cmds(queued_cmd
, &nr
);
670 free_cmds(queued_cmd
, &nr
);
672 strbuf_release(&input
);
675 #define DEFAULT_FORMAT "%(objectname) %(objecttype) %(objectsize)"
677 static int batch_objects(struct batch_options
*opt
)
679 struct strbuf input
= STRBUF_INIT
;
680 struct strbuf output
= STRBUF_INIT
;
681 struct expand_data data
;
686 * Expand once with our special mark_query flag, which will prime the
687 * object_info to be handed to oid_object_info_extended for each
690 memset(&data
, 0, sizeof(data
));
692 strbuf_expand(&output
,
693 opt
->format
? opt
->format
: DEFAULT_FORMAT
,
697 strbuf_release(&output
);
698 if (opt
->transform_mode
)
699 data
.split_on_whitespace
= 1;
701 if (opt
->format
&& !strcmp(opt
->format
, DEFAULT_FORMAT
))
704 * If we are printing out the object, then always fill in the type,
705 * since we will want to decide whether or not to stream.
707 if (opt
->batch_mode
== BATCH_MODE_CONTENTS
)
708 data
.info
.typep
= &data
.type
;
710 if (opt
->all_objects
) {
711 struct object_cb_data cb
;
712 struct object_info empty
= OBJECT_INFO_INIT
;
714 if (!memcmp(&data
.info
, &empty
, sizeof(empty
)))
715 data
.skip_object_info
= 1;
717 if (has_promisor_remote())
718 warning("This repository uses promisor remotes. Some objects may not be loaded.");
720 read_replace_refs
= 0;
724 cb
.scratch
= &output
;
726 if (opt
->unordered
) {
727 struct oidset seen
= OIDSET_INIT
;
731 for_each_loose_object(batch_unordered_loose
, &cb
, 0);
732 for_each_packed_object(batch_unordered_packed
, &cb
,
733 FOR_EACH_OBJECT_PACK_ORDER
);
737 struct oid_array sa
= OID_ARRAY_INIT
;
739 for_each_loose_object(collect_loose_object
, &sa
, 0);
740 for_each_packed_object(collect_packed_object
, &sa
, 0);
742 oid_array_for_each_unique(&sa
, batch_object_cb
, &cb
);
744 oid_array_clear(&sa
);
747 strbuf_release(&output
);
752 * We are going to call get_sha1 on a potentially very large number of
753 * objects. In most large cases, these will be actual object sha1s. The
754 * cost to double-check that each one is not also a ref (just so we can
755 * warn) ends up dwarfing the actual cost of the object lookups
756 * themselves. We can work around it by just turning off the warning.
758 save_warning
= warn_on_object_refname_ambiguity
;
759 warn_on_object_refname_ambiguity
= 0;
761 if (opt
->batch_mode
== BATCH_MODE_QUEUE_AND_DISPATCH
) {
762 batch_objects_command(opt
, &output
, &data
);
766 while (strbuf_getline(&input
, stdin
) != EOF
) {
767 if (data
.split_on_whitespace
) {
769 * Split at first whitespace, tying off the beginning
770 * of the string and saving the remainder (or NULL) in
773 char *p
= strpbrk(input
.buf
, " \t");
775 while (*p
&& strchr(" \t", *p
))
781 batch_one_object(input
.buf
, &output
, opt
, &data
);
785 strbuf_release(&input
);
786 strbuf_release(&output
);
787 warn_on_object_refname_ambiguity
= save_warning
;
791 static int git_cat_file_config(const char *var
, const char *value
, void *cb
)
793 if (userdiff_config(var
, value
) < 0)
796 return git_default_config(var
, value
, cb
);
799 static int batch_option_callback(const struct option
*opt
,
803 struct batch_options
*bo
= opt
->value
;
805 BUG_ON_OPT_NEG(unset
);
808 return error(_("only one batch option may be specified"));
813 if (!strcmp(opt
->long_name
, "batch"))
814 bo
->batch_mode
= BATCH_MODE_CONTENTS
;
815 else if (!strcmp(opt
->long_name
, "batch-check"))
816 bo
->batch_mode
= BATCH_MODE_INFO
;
817 else if (!strcmp(opt
->long_name
, "batch-command"))
818 bo
->batch_mode
= BATCH_MODE_QUEUE_AND_DISPATCH
;
820 BUG("%s given to batch-option-callback", opt
->long_name
);
827 int cmd_cat_file(int argc
, const char **argv
, const char *prefix
)
832 const char *exp_type
= NULL
, *obj_name
= NULL
;
833 struct batch_options batch
= {0};
834 int unknown_type
= 0;
836 const char * const usage
[] = {
837 N_("git cat-file <type> <object>"),
838 N_("git cat-file (-e | -p) <object>"),
839 N_("git cat-file (-t | -s) [--allow-unknown-type] <object>"),
840 N_("git cat-file (--batch | --batch-check | --batch-command) [--batch-all-objects]\n"
841 " [--buffer] [--follow-symlinks] [--unordered]\n"
842 " [--textconv | --filters]"),
843 N_("git cat-file (--textconv | --filters)\n"
844 " [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]"),
847 const struct option options
[] = {
849 OPT_GROUP(N_("Check object existence or emit object contents")),
850 OPT_CMDMODE('e', NULL
, &opt
,
851 N_("check if <object> exists"), 'e'),
852 OPT_CMDMODE('p', NULL
, &opt
, N_("pretty-print <object> content"), 'p'),
854 OPT_GROUP(N_("Emit [broken] object attributes")),
855 OPT_CMDMODE('t', NULL
, &opt
, N_("show object type (one of 'blob', 'tree', 'commit', 'tag', ...)"), 't'),
856 OPT_CMDMODE('s', NULL
, &opt
, N_("show object size"), 's'),
857 OPT_BOOL(0, "allow-unknown-type", &unknown_type
,
858 N_("allow -s and -t to work with broken/corrupt objects")),
860 OPT_GROUP(N_("Batch objects requested on stdin (or --batch-all-objects)")),
861 OPT_CALLBACK_F(0, "batch", &batch
, N_("format"),
862 N_("show full <object> or <rev> contents"),
863 PARSE_OPT_OPTARG
| PARSE_OPT_NONEG
,
864 batch_option_callback
),
865 OPT_CALLBACK_F(0, "batch-check", &batch
, N_("format"),
866 N_("like --batch, but don't emit <contents>"),
867 PARSE_OPT_OPTARG
| PARSE_OPT_NONEG
,
868 batch_option_callback
),
869 OPT_CALLBACK_F(0, "batch-command", &batch
, N_("format"),
870 N_("read commands from stdin"),
871 PARSE_OPT_OPTARG
| PARSE_OPT_NONEG
,
872 batch_option_callback
),
873 OPT_CMDMODE(0, "batch-all-objects", &opt
,
874 N_("with --batch[-check]: ignores stdin, batches all known objects"), 'b'),
875 /* Batch-specific options */
876 OPT_GROUP(N_("Change or optimize batch output")),
877 OPT_BOOL(0, "buffer", &batch
.buffer_output
, N_("buffer --batch output")),
878 OPT_BOOL(0, "follow-symlinks", &batch
.follow_symlinks
,
879 N_("follow in-tree symlinks")),
880 OPT_BOOL(0, "unordered", &batch
.unordered
,
881 N_("do not order objects before emitting them")),
882 /* Textconv options, stand-ole*/
883 OPT_GROUP(N_("Emit object (blob or tree) with conversion or filter (stand-alone, or with batch)")),
884 OPT_CMDMODE(0, "textconv", &opt
,
885 N_("run textconv on object's content"), 'c'),
886 OPT_CMDMODE(0, "filters", &opt
,
887 N_("run filters on object's content"), 'w'),
888 OPT_STRING(0, "path", &force_path
, N_("blob|tree"),
889 N_("use a <path> for (--textconv | --filters); Not with 'batch'")),
893 git_config(git_cat_file_config
, NULL
);
895 batch
.buffer_output
= -1;
897 argc
= parse_options(argc
, argv
, prefix
, options
, usage
, 0);
898 opt_cw
= (opt
== 'c' || opt
== 'w');
899 opt_epts
= (opt
== 'e' || opt
== 'p' || opt
== 't' || opt
== 's');
901 /* --batch-all-objects? */
903 batch
.all_objects
= 1;
905 /* Option compatibility */
906 if (force_path
&& !opt_cw
)
907 usage_msg_optf(_("'%s=<%s>' needs '%s' or '%s'"),
909 "--path", _("path|tree-ish"), "--filters",
912 /* Option compatibility with batch mode */
915 else if (batch
.follow_symlinks
)
916 usage_msg_optf(_("'%s' requires a batch mode"), usage
, options
,
917 "--follow-symlinks");
918 else if (batch
.buffer_output
>= 0)
919 usage_msg_optf(_("'%s' requires a batch mode"), usage
, options
,
921 else if (batch
.all_objects
)
922 usage_msg_optf(_("'%s' requires a batch mode"), usage
, options
,
923 "--batch-all-objects");
926 if (batch
.buffer_output
< 0)
927 batch
.buffer_output
= batch
.all_objects
;
929 /* Return early if we're in batch mode? */
932 batch
.transform_mode
= opt
;
933 else if (opt
&& opt
!= 'b')
934 usage_msg_optf(_("'-%c' is incompatible with batch mode"),
935 usage
, options
, opt
);
937 usage_msg_opt(_("batch modes take no arguments"), usage
,
940 return batch_objects(&batch
);
944 if (!argc
&& opt
== 'c')
945 usage_msg_optf(_("<rev> required with '%s'"),
946 usage
, options
, "--textconv");
947 else if (!argc
&& opt
== 'w')
948 usage_msg_optf(_("<rev> required with '%s'"),
949 usage
, options
, "--filters");
950 else if (!argc
&& opt_epts
)
951 usage_msg_optf(_("<object> required with '-%c'"),
952 usage
, options
, opt
);
956 usage_msg_opt(_("too many arguments"), usage
, options
);
958 usage_with_options(usage
, options
);
959 } else if (argc
!= 2) {
960 usage_msg_optf(_("only two arguments allowed in <type> <object> mode, not %d"),
961 usage
, options
, argc
);
967 if (unknown_type
&& opt
!= 't' && opt
!= 's')
968 die("git cat-file --allow-unknown-type: use with -s or -t");
969 return cat_one_file(opt
, exp_type
, obj_name
, unknown_type
);