@@ -595,6 +595,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
595595 struct object_context unused ;
596596 struct strbuf buf = STRBUF_INIT ;
597597 const int hexsz = the_hash_algo -> hexsz ;
598+ int seen_end_of_options = 0 ;
598599
599600 if (argc > 1 && !strcmp ("--parseopt" , argv [1 ]))
600601 return cmd_parseopt (argc - 1 , argv + 1 , prefix );
@@ -622,21 +623,29 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
622623 for (i = 1 ; i < argc ; i ++ ) {
623624 const char * arg = argv [i ];
624625
625- if (!strcmp (arg , "--local-env-vars" )) {
626- int i ;
627- for (i = 0 ; local_repo_env [i ]; i ++ )
628- printf ("%s\n" , local_repo_env [i ]);
626+ if (as_is ) {
627+ if (show_file (arg , output_prefix ) && as_is < 2 )
628+ verify_filename (prefix , arg , 0 );
629629 continue ;
630630 }
631- if (!strcmp (arg , "--resolve-git-dir" )) {
632- const char * gitdir = argv [++ i ];
633- if (!gitdir )
634- die ("--resolve-git-dir requires an argument" );
635- gitdir = resolve_gitdir (gitdir );
636- if (!gitdir )
637- die ("not a gitdir '%s'" , argv [i ]);
638- puts (gitdir );
639- continue ;
631+
632+ if (!seen_end_of_options ) {
633+ if (!strcmp (arg , "--local-env-vars" )) {
634+ int i ;
635+ for (i = 0 ; local_repo_env [i ]; i ++ )
636+ printf ("%s\n" , local_repo_env [i ]);
637+ continue ;
638+ }
639+ if (!strcmp (arg , "--resolve-git-dir" )) {
640+ const char * gitdir = argv [++ i ];
641+ if (!gitdir )
642+ die ("--resolve-git-dir requires an argument" );
643+ gitdir = resolve_gitdir (gitdir );
644+ if (!gitdir )
645+ die ("not a gitdir '%s'" , argv [i ]);
646+ puts (gitdir );
647+ continue ;
648+ }
640649 }
641650
642651 /* The rest of the options require a git repository. */
@@ -646,41 +655,36 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
646655 did_repo_setup = 1 ;
647656 }
648657
649- if (!strcmp (arg , "--git-path" )) {
650- if (!argv [i + 1 ])
651- die ("--git-path requires an argument" );
652- strbuf_reset (& buf );
653- puts (relative_path (git_path ("%s" , argv [i + 1 ]),
654- prefix , & buf ));
655- i ++ ;
656- continue ;
657- }
658- if (as_is ) {
659- if (show_file (arg , output_prefix ) && as_is < 2 )
660- verify_filename (prefix , arg , 0 );
661- continue ;
662- }
663- if (!strcmp (arg ,"-n" )) {
664- if (++ i >= argc )
665- die ("-n requires an argument" );
666- if ((filter & DO_FLAGS ) && (filter & DO_REVS )) {
667- show (arg );
668- show (argv [i ]);
669- }
670- continue ;
671- }
672- if (starts_with (arg , "-n" )) {
673- if ((filter & DO_FLAGS ) && (filter & DO_REVS ))
674- show (arg );
658+ if (!strcmp (arg , "--" )) {
659+ as_is = 2 ;
660+ /* Pass on the "--" if we show anything but files.. */
661+ if (filter & (DO_FLAGS | DO_REVS ))
662+ show_file (arg , 0 );
675663 continue ;
676664 }
677665
678- if (* arg == '-' ) {
679- if (!strcmp (arg , "--" )) {
680- as_is = 2 ;
681- /* Pass on the "--" if we show anything but files.. */
682- if (filter & (DO_FLAGS | DO_REVS ))
683- show_file (arg , 0 );
666+ if (!seen_end_of_options && * arg == '-' ) {
667+ if (!strcmp (arg , "--git-path" )) {
668+ if (!argv [i + 1 ])
669+ die ("--git-path requires an argument" );
670+ strbuf_reset (& buf );
671+ puts (relative_path (git_path ("%s" , argv [i + 1 ]),
672+ prefix , & buf ));
673+ i ++ ;
674+ continue ;
675+ }
676+ if (!strcmp (arg ,"-n" )) {
677+ if (++ i >= argc )
678+ die ("-n requires an argument" );
679+ if ((filter & DO_FLAGS ) && (filter & DO_REVS )) {
680+ show (arg );
681+ show (argv [i ]);
682+ }
683+ continue ;
684+ }
685+ if (starts_with (arg , "-n" )) {
686+ if ((filter & DO_FLAGS ) && (filter & DO_REVS ))
687+ show (arg );
684688 continue ;
685689 }
686690 if (!strcmp (arg , "--default" )) {
@@ -937,6 +941,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
937941 puts (the_hash_algo -> name );
938942 continue ;
939943 }
944+ if (!strcmp (arg , "--end-of-options" )) {
945+ seen_end_of_options = 1 ;
946+ if (filter & (DO_FLAGS | DO_REVS ))
947+ show_file (arg , 0 );
948+ continue ;
949+ }
940950 if (show_flag (arg ) && verify )
941951 die_no_single_rev (quiet );
942952 continue ;
0 commit comments