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

Re: lstat() call in rev-parse.c

From
Linus Torvalds <torvalds@osdl.org>
Date
Apr 26, 2006, 15:43 UTC
Message-ID
<Pine.LNX.4.64.0604260832240.3701@g5.osdl.org>
In-Reply-To
<E1FYlwn-0005mf-CL@moooo.ath.cx>
On Wed, 26 Apr 2006, Matthias Lederhofer wrote:
Show 8 quoted lines
> > So the rule is: if you don't give that "--", then we have to be able 
> > to confirm that the filenames are really files. Not a misspelled 
> > revision name, or a revision name that was correctly spelled, but for 
> > the wrong project, because you were in the wrong subdirectory ;)
> 
> Shouldn't git rev-parse try to stat the file (additionally?) in the 
> current directory instead of the top git directory? git (diff|log|..) 
> seem to fail everytime in a subdirectory without --.

Good point. However, the reason for that is that it actually _does_ stat the file in the current directory, but it has done the

	revs->prefix = setup_git_directory();

in the init path (and it does need to do that, since that's what figures out where the .git directory is, so that we can parse the revisions correctly).

And that "setup_git_directory()" will chdir() to the root of the project.

So the "lstat()" should probably take "revs->prefix" into account, the way get_pathspec() does. Ie we should probably use

	char *name = argv[i];
	if (rev->prefix)
		name = prefix_filename(rev->prefix, strlen(rev->prefix), name);
	if (lstat(name, ..) < 0)
		die(...)
instead of just a plain lstat().

Probably worth doing as a small helper funtion of its own (and get rid of the current "die_badfile()" - and do all of that inside the helper function).

Somebody?
		Linus
Previous: Matthias LederhoferNext: Linus Torvalds
Message 5 of 8 in “lstat() call in rev-parse.c”
  1. Paul MackerrasApr 23, 2006
  2. Linus TorvaldsApr 23, 2006
  3. Paul MackerrasApr 24, 2006
  4. Matthias LederhoferApr 26, 2006
  5. Linus TorvaldsApr 26, 2006
  6. Fix filename verification when in a subdirectoryLinus Torvalds, Apr 26, 2006
  7. Timo HirvonenApr 26, 2006
  8. Linus TorvaldsApr 26, 2006

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.