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

Re: [PATCH] Make Git accept absolute path names for files within the work tree

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 29, 2007, 00:37 UTC
Message-ID
<7vwss1zy26.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1196205847-22968-1-git-send-email-robin.rosenberg@dewire.com>
Robin Rosenberg <robin.rosenberg@dewire.com> writes:
Show 10 quoted lines
> diff --git a/setup.c b/setup.c
> index f512ea0..ffc30bf 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -7,6 +7,25 @@ static int inside_work_tree = -1;
>  const char *prefix_path(const char *prefix, int len, const char *path)
>  {
>  	const char *orig = path;
> +	const char *work_tree = get_git_work_tree();
> +	if (is_absolute_path(path) && work_tree) {

Could you structure this part to read like this, into a separate function:

static const char *strip_work_tree_path(const char *prefix, int len, const char *path)
{
	...
}
const char *prefix_path(const char *prefix, int len, const char *path)
{
	const char *orig = path;
	if (is_absolute_path(path))
		path = strip_work_tree_path(prefix, len, path);
	...

About the part that would be moved out of line with such a restructuring,

Show 14 quoted lines
> +		int n = strlen(work_tree);
> +		if (!strncmp(path, work_tree, n) && (path[n] == '/' || !path[n])) {
> +			if (path[n])
> +				path += n + 1;
> +			else
> +				path += n;
> +
> +			if (prefix && !strncmp(path, prefix, len - 1)) {
> +				if (path[len - 1] == '/')
> +					path += len;
> +				else
> +					if (!path[len - 1])
> +						path += len - 1;
> +			}

This makes me wonder what happens if after stripping the worktree path path does not match the prefix.

Previous: Junio C HamanoNext: Johannes Sixt
Message 8 of 10 in “Make Git accept absolute path names for files within the work tree”
  1. Make Git accept absolute path names for files within the work treeRobin Rosenberg, Nov 26, 2007
  2. Junio C HamanoNov 27, 2007
  3. Robin RosenbergNov 27, 2007
  4. Make Git accept absolute path names for files within the work treeRobin Rosenberg, Nov 27, 2007
  5. Junio C HamanoNov 28, 2007
  6. Robin RosenbergNov 29, 2007
  7. Junio C HamanoNov 29, 2007
  8. Junio C HamanoNov 29, 2007
  9. Johannes SixtNov 27, 2007
  10. Robin RosenbergNov 27, 2007

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.