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

Re: [PATCH 3/4] option-strings: use OPT_PATH

From
Jeff King <peff@peff.net>
Date
Feb 23, 2015, 21:12 UTC
Message-ID
<20150223211228.GA6658@peff.net>
In-Reply-To
<xmqqd250s5fi.fsf@gitster.dls.corp.google.com>
On Mon, Feb 23, 2015 at 01:07:13PM -0800, Junio C Hamano wrote:
Show 26 quoted lines
> >> -	OPT_STRING(0, "template", &option_template, N_("template-directory"),
> >> +	OPT_PATH(0, "template", &option_template, N_("template-directory"),
> >>  		   N_("directory from which templates will be used")),
> >>  	OPT_CALLBACK(0 , "reference", &option_reference, N_("repo"),
> >>  		     N_("reference repository"), &opt_parse_reference),
> >
> > I'm not sure if this one is doing anything. Clone cannot use SETUP_GIT
> > for obvious reasons, so we should have a NULL prefix here. But that also
> > means we should be doing the right thing already.
> 
> I somehow thought that OPT_FILENAME already used expand_user_path()
> but apparently it does not.  It may want to.
> 
> And then this change will start to matter, as a good enhancement.
> 
> Of course, if OPT_PATH() is introduced in such a way that the
> program that uses the API can ask for "existing" and/or "directory",
> 
>     git clone --template=existing-file $URL
>     git clone --template=no-such-directory $URL
> 
> can be diagnosed as an error without the program having to code very
> much.
> 
> So, I agree that this change does not do anything in the current
> codebase, but it goes in a right direction.

Oh, I agree that annotating the option with more meaning is not a bad thing. It may help readability, and as you note, we may grow new features on those annotations over time. I mostly just got tired of writing things along those lines by the time I finished with the OPT_FILENAME patch (I guess OPT_PATH is the one more likely to grow new features, though).

The one exception here is the thing I mentioned in parse_archive_args: that one can be controlled by a remote caller and we would not want to leak any information about which files exist, where the user's home directory is, etc.

-Peff
Previous: Junio C HamanoNext: Michael J Gruber
Message 16 of 18 in “checkout: --to requires directory”
  1. checkout: --to requires directoryMichael J Gruber, Feb 23, 2015
  2. Jeff KingFeb 23, 2015
  3. Michael J GruberFeb 23, 2015
  4. 0/4 OPT_{FILENAME,PATH}Michael J Gruber, Feb 23, 2015
  5. 1/4 parse-options: introduce OPT_PATHMichael J Gruber, Feb 23, 2015
  6. Junio C HamanoFeb 23, 2015
  7. Michael J GruberFeb 24, 2015
  8. Philip OakleyFeb 23, 2015
  9. 2/4 option-strings: use OPT_FILENAMEMichael J Gruber, Feb 23, 2015
  10. Jeff KingFeb 23, 2015
  11. Junio C HamanoFeb 23, 2015
  12. Junio C HamanoFeb 23, 2015
  13. 3/4 option-strings: use OPT_PATHMichael J Gruber, Feb 23, 2015
  14. Jeff KingFeb 23, 2015
  15. Junio C HamanoFeb 23, 2015
  16. Jeff KingFeb 23, 2015
  17. 4/4 checkout: --to requires directoryMichael J Gruber, Feb 23, 2015
  18. Duy NguyenFeb 24, 2015

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.