git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Revert "rev-parse: remove restrictions on some options"

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 26, 2016, 23:44 UTC
Message-ID
<xmqqbn73hwam.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160226233449.GA9622@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 51 quoted lines
> On Fri, Feb 26, 2016 at 06:29:57PM -0500, Jeff King wrote:
>
>> The best solution here would be to have a full parsing loop
>> that handles all options, but only calls setup_git_directory
>> as appropriate. Unfortunately, that's a bit complicated to
>> implement. We _have_ to handle each option in the order it
>> appears on the command line. If the caller asked for:
>> 
>>   git rev-parse --resolve-git-dir foo/.git --show-toplevel
>> 
>> then it must receive the two lines of output in the correct
>> to know which is which. But asking for:
>> 
>>   git rev-parse --show-toplevel --resolve-git-dir foo/.git
>> 
>> is weird; we have to setup_git_directory() for the first
>> option.
>> 
>> So any implementation would probably have to either:
>> 
>>   - make two passes over the options, first figuring out
>>     whether we need a git-dir, and then actually handling
>>     the options. That's possible, but it's probably not
>>     worth the trouble.
>> 
>>   - call setup_git_directory() on the fly when an option
>>     needs it; that requires annotating all of the options,
>>     and there are a considerable number of them.
>
> Having just sent this, of course, it occurs to me that a loop like:
>
>    setup_git_directory_gently(&nongit);
>    for (i = 0; i < argc; i++) {
>   	if (!strcmp(argv[i], "--local-env-vars"))
>   	... and other nongit-ok options ...
>   
>   	if (nongit)
>   		die("need a repo");
>   
>   	if (!strcmp(argv[i], "--git-dir"))
>   	... and other options ...
>    }
>
> would probably work. It does still leave things like --parseopt and
> --sq-quote as one-offs, though, because they consume the rest of the
> command line. And the fact remains that --local-repo-env isn't really
> suitable for use with other options.
>
> So I'm still tempted by this "lazy" approach.
>
> -Peff
Yup.

But why do you even need to run local-env-vars from outside a repository in the first place?

Previous: Jeff KingNext: Jeff King
Message 5 of 13 in “fix some rev-parse options in non-repos”
  1. 0/2 fix some rev-parse options in non-reposJeff King, Feb 26, 2016
  2. 1/2 t1515: add tests for rev-parse out-of-repo helpersJeff King, Feb 26, 2016
  3. 2/2 Revert "rev-parse: remove restrictions on some options"Jeff King, Feb 26, 2016
  4. Jeff KingFeb 26, 2016
  5. Junio C HamanoFeb 26, 2016
  6. Jeff KingFeb 27, 2016
  7. Jeff KingFeb 29, 2016
  8. Junio C HamanoFeb 29, 2016
  9. Jeff KingFeb 29, 2016
  10. John KeepingFeb 27, 2016
  11. Jeff KingFeb 29, 2016
  12. Eric SunshineFeb 28, 2016
  13. Jeff KingFeb 29, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.