648
int cmd_cat_file(int argc, const char **argv, const char *prefix)
649
{
650
int opt = 0;
651
+ int opt_cw = 0;
652
+ int opt_epts = 0;
653
const char *exp_type = NULL, *obj_name = NULL;
654
struct batch_options batch = {0};
655
int unknown_type = 0;
703
batch.buffer_output = -1;
704
705
argc = parse_options(argc, argv, prefix, options, usage, 0);
704
- if (argc && batch.enabled)
705
- usage_with_options(usage, options);
706
- if (opt == 'b') {
707
- batch.all_objects = 1;
708
- } else if (opt) {
709
- if (batch.enabled && (opt == 'c' || opt == 'w'))
710
- batch.cmdmode = opt;
711
- else if (argc == 1)
712
- obj_name = argv[0];
713
- else
714
- usage_with_options(usage, options);
715
- } else if (!opt && !batch.enabled) {
716
- if (argc == 2) {
717
- exp_type = argv[0];
718
- obj_name = argv[1];
719
- } else
720
- usage_with_options(usage, options);
721
- } else if (batch.enabled && batch.cmdmode != opt)
722
- usage_with_options(usage, options);
706
+ opt_cw = (opt == 'c' || opt == 'w');
707
+ opt_epts = (opt == 'e' || opt == 'p' || opt == 't' || opt == 's');
708
724
- if ((batch.follow_symlinks || batch.all_objects) && !batch.enabled) {
725
- usage_with_options(usage, options);
726
- }
727
-
728
- if (force_path && opt != 'c' && opt != 'w') {
729
- error("--path=<path> needs --textconv or --filters");
730
- usage_with_options(usage, options);
731
- }
709
+ /* --batch-all-objects? */
710
+ if (opt == 'b')
711
+ batch.all_objects = 1;
712
733
- if (force_path && batch.enabled) {
734
- error("--path=<path> incompatible with --batch");
735
- usage_with_options(usage, options);
736
- }
713
+ /* Option compatibility */
714
+ if (force_path && !opt_cw)
715
+ usage_msg_optf(_("'%s=<%s>' needs '%s' or '%s'"),
716
+ usage, options,
717
+ "--path", _("path|tree-ish"), "--filters",
718
+ "--textconv");
719
720
+ /* Option compatibility with batch mode */
721
+ if (batch.enabled)
722
+ ;
723
+ else if (batch.follow_symlinks)
724
+ usage_msg_optf(_("'%s' requires a batch mode"), usage, options,
725
+ "--follow_symlinks");
726
+ else if (batch.buffer_output >= 0)
727
+ usage_msg_optf(_("'%s' requires a batch mode"), usage, options,
728
+ "--buffer");
729
+ else if (batch.all_objects)
730
+ usage_msg_optf(_("'%s' requires a batch mode"), usage, options,
731
+ "--batch-all-objects");
732
+
733
+ /* Batch defaults */
734
if (batch.buffer_output < 0)
735
batch.buffer_output = batch.all_objects;
736
741
- if (batch.enabled)
737
+ /* Return early if we're in batch mode? */
738
+ if (batch.enabled) {
739
+ if (opt_cw)
740
+ batch.cmdmode = opt;
741
+ else if (opt && opt != 'b')
742
+ usage_msg_optf(_("'-%c' is incompatible with batch mode"),
743
+ usage, options, opt);
744
+ else if (argc)
745
+ usage_msg_opt(_("batch modes take no arguments"), usage,
746
+ options);
747
+
748
return batch_objects(&batch);
749
+ }
750
+
751
+ if (opt) {
752
+ if (!argc && opt == 'c')
753
+ usage_msg_optf(_("<rev> required with '%s'"),
754
+ usage, options, "--textconv");
755
+ else if (!argc && opt == 'w')
756
+ usage_msg_optf(_("<rev> required with '%s'"),
757
+ usage, options, "--filters");
758
+ else if (!argc && opt_epts)
759
+ usage_msg_optf(_("<object> required with '-%c'"),
760
+ usage, options, opt);
761
+ else if (argc == 1)
762
+ obj_name = argv[0];
763
+ else
764
+ usage_msg_opt(_("too many arguments"), usage, options);
765
+ } else if (!argc) {
766
+ usage_with_options(usage, options);
767
+ } else if (argc != 2) {
768
+ usage_msg_optf(_("only two arguments allowed in <type> <object> mode, not %d"),
769
+ usage, options, argc);
770
+ } else if (argc) {
771
+ exp_type = argv[0];
772
+ obj_name = argv[1];
773
+ }
774
775
if (unknown_type && opt != 't' && opt != 's')
776
die("git cat-file --allow-unknown-type: use with -s or -t");