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

Re: [PATCHv2] submodule: Port resolve_relative_url from shell to C

From
Jeff King <peff@peff.net>
Date
Dec 18, 2015, 03:27 UTC
Message-ID
<20151218032708.GA8530@sigill.intra.peff.net>
In-Reply-To
<5673052F.7050000@kdbg.org>
On Thu, Dec 17, 2015 at 07:55:43PM +0100, Johannes Sixt wrote:
Show 23 quoted lines
> -static int has_same_dir_prefix(const char *str, const char **out)
> +static int starts_with_dot_slash(const char *str)
>  {
> -#ifdef GIT_WINDOWS_NATIVE
> -	return skip_prefix(str, "./", out)
> -		|| skip_prefix(str, ".\\", out);
> -#else
> -	return skip_prefix(str, "./", out);
> -#endif
> +	return str[0] == '.' && is_dir_sep(str[1]);
>  }
>  
> -static int has_upper_dir_prefix(const char *str, const char **out)
> +static int starts_with_dot_dot_slash(const char *str)
>  {
> -#ifdef GIT_WINDOWS_NATIVE
> -	return skip_prefix(str, "../", out)
> -		|| skip_prefix(str, "..\\", out);
> -#else
> -	return skip_prefix(str, "../", out);
> -#endif
> +	return str[0] == '.' && str[1] == '.' && is_dir_sep(str[2]);
>  }

As the set of prefixes you are looking is probably bounded, it may not be worth generalizing this. But I wondered if something like:

  /*
   * Like skip_prefix, but consider any "/" in the prefix as a
   * directory separator for the platform.
   */
  int skip_prefix_fs(const char *str, const char *prefix, const char **out)
  {
	while (1) {
		if (!*prefix) {
			*out = str;
			return 1;
		} else if (*prefix == '/') {
			if (!is_dir_sep(*str))
				return 0;
		} else {
			if (*str != *prefix)
				return 0;
		}
		str++;
		prefix++;
	}
  }
  ...
  /* works on all platforms! */
  if (skip_prefix_fs(foo, "./", &out))
	...

would be helpful. I don't know if there are other opportunities in the code base that could make use of this. If it's just these two sites, it's probably not worth it.

-Peff
Previous: Johannes SixtNext: Stefan Beller
Message 9 of 11 in “submodule: Port resolve_relative_url from shell to C”
  1. submodule: Port resolve_relative_url from shell to CStefan Beller, Dec 10, 2015
  2. Johannes SixtDec 10, 2015
  3. Stefan BellerDec 16, 2015
  4. [PATCHv2] Porting resolve_relative_url from shell to CStefan Beller, Dec 17, 2015
  5. [PATCHv2] submodule: Port resolve_relative_url from shell to CStefan Beller, Dec 17, 2015
  6. Eric SunshineDec 17, 2015
  7. Johannes SixtDec 17, 2015
  8. Johannes SixtDec 17, 2015
  9. Jeff KingDec 18, 2015
  10. Stefan BellerJan 11, 2016
  11. Torsten BögershausenDec 17, 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.