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

Re: [PATCH] get_sha1: support relative path "<obj>:<sth>" syntax

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Nov 10, 2010, 17:17 UTC
Message-ID
<vpq39r9m729.fsf@bauges.imag.fr>
In-Reply-To
<1289407021-30287-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
Show 6 quoted lines
> Currently :path and ref:path can be used to refer to a specific object
> in index or ref respectively. "path" component is absolute path. This
> patch allows "path" to be written as "./path" or "../path", which is
> relative to user's original cwd.
>
> This does not work in commands that startup_info is NULL
Grammar: shouldn't it be "commands for which startup_info is NULL"?
> (i.e. non-builtin ones).

Does that include "git show"? That's probably the most common use-case for the <object>:<path> syntax, perhaps worth mentionning here.

Also, what happens when it doesn't work? I guess it falls back to the previous behavior, which tries to do a detailed diagnosis and provides a general error message. But probably the error messages should be reworded to include "syntax not supported by this command" or so, 'cause it's really weird for a user to be able to say HEAD:./foo in some places and not in others.

>  The idea is old although I don't remember if anybody has made any
>  attempt to realize it: use './' and '../' to specify the given path
>  is relative, not absolute.

I gave it a try, but I was not aware of the startup_info thing, and tried passing more arguments to get_sha1*, and you can guess I quickly gave up ;-).

> +			if (startup_info && cp[0] == '.' &&
> +			    (cp[1] == '/' || (cp[1] == '.' && cp[2] == '/'))) {

Nothing performance-critical here, so I'd rather have something more readable, like

startup_info && (!prefixcmp(cp, "./") || !prefixcmp(cp, "../"))
> +				new_path = prefix_path(startup_info->prefix,
> +						       strlen(startup_info->prefix),
> +						       cp);
free(cp); here?
> +				cp = new_path;
> +			}
> +		}
Show 13 quoted lines
> @@ -1122,6 +1134,17 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
>  		}
>  		if (!get_sha1_1(name, cp-name, tree_sha1)) {
>  			const char *filename = cp+1;
> +			char *new_filename = NULL;
> +
> +			if (startup_info &&
> +			    filename[0] == '.' &&
> +			    (filename[1] == '/' ||
> +			     (filename[1] == '.' && filename[2] == '/'))) {
> +				new_filename = prefix_path(startup_info->prefix,
> +							   strlen(startup_info->prefix),
> +							   filename);
Same 2 questions as above.
Also, that would be nice is this came with a testcase :-)
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Nguyễn Thái Ngọc DuyNext: Jonathan Nieder
Message 11 of 21 in “Re: [RFC] Using gitrevisions :/search style with other operators”
  1. Yann DirsonNov 9, 2010
  2. Kevin BallardNov 9, 2010
  3. Yann DirsonNov 9, 2010
  4. Junio C HamanoNov 10, 2010
  5. Kevin BallardNov 10, 2010
  6. Yann DirsonNov 10, 2010
  7. Kevin BallardNov 10, 2010
  8. Yann DirsonNov 10, 2010
  9. Jakub NarebskiNov 10, 2010
  10. get_sha1: support relative path "<obj>:<sth>" syntaxNguyễn Thái Ngọc Duy, Nov 10, 2010
  11. Matthieu MoyNov 10, 2010
  12. Jonathan NiederNov 10, 2010
  13. Nguyen Thai Ngoc DuyNov 11, 2010
  14. Junio C HamanoNov 10, 2010
  15. Nguyen Thai Ngoc DuyNov 11, 2010
  16. Junio C HamanoDec 9, 2010
  17. Junio C HamanoDec 9, 2010
  18. Nguyen Thai Ngoc DuyDec 10, 2010
  19. Junio C HamanoNov 10, 2010
  20. Jakub NarebskiNov 10, 2010
  21. Jeff KingNov 9, 2010

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.