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

Re: [PATCH] Teach "git apply" to prepend a prefix with "--root=<root>"

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 1, 2008, 09:21 UTC
Message-ID
<7vvdzqnemk.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.DEB.1.00.0807010043440.9925@racer>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> With "git apply --root=<root>", all file names in the patch are prepended
> with <root>.  If a "-p" value was given, the paths are stripped _before_
> prepending <root>.
Show 8 quoted lines
> @@ -182,6 +182,10 @@ behavior:
>  	by inspecting the patch (e.g. after editing the patch without
>  	adjusting the hunk headers appropriately).
>  
> +--root=<root>::
> +	Prepend <root> to all filenames.  If a "-p" argument was passed, too,
> +	it is applied before prepending the new root.
> +

I looked for precedence of this concept outside git but did not find anything that exactly matched.

The -p<num> came from patch where it is also called --strip=num. This new option --root is about the reverse operation and it is about inserting at the beginning --- it is rerooting, in other words, but then --root is good enough and shorter. mkisofs uses the word "graft" when it allows tree shifting (enabled with --graft-points), but the word "graft" means a totally different thing to us, so we would not want to use that word.

I am not complaining (--root is fine by me), but just thinking aloud, hoping somebody's brainwave is provoked while reading this babbling and comes up with a better wording ;-).

Show 10 quoted lines
> diff --git a/builtin-apply.c b/builtin-apply.c
> index 9fcfe39..d56d913 100644
> --- a/builtin-apply.c
> +++ b/builtin-apply.c
> @@ -58,6 +58,8 @@ static int whitespace_error;
> @@ -3240,6 +3252,18 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
>  			options |= RECOUNT;
>  			continue;
>  		}
> +		if (!strncmp(arg, "--root=", strlen("--root="))) {
prefixcmp()?
> +			arg += strlen("--root=");
> +			root_len = strlen(arg);
> +			if (root_len && arg[root_len + 1] != '/') {

Ah, being nice not to force trailing slash on users --- how unlike you ;-) but I think you meant "arg[root_len - 1]" there...

Other than that, the change looks fine.  Thanks.
Previous: Johannes SchindelinNext: H. Peter Anvin
Message 2 of 8 in “Teach "git apply" to prepend a prefix with "--root=<root>"”
  1. Teach "git apply" to prepend a prefix with "--root=<root>"Johannes Schindelin, Jun 30, 2008
  2. Junio C HamanoJul 1, 2008
  3. H. Peter AnvinJul 1, 2008
  4. Johannes SchindelinJul 1, 2008
  5. H. Peter AnvinJul 1, 2008
  6. Raimund BauerJul 1, 2008
  7. H. Peter AnvinJul 1, 2008
  8. Johannes SchindelinJul 1, 2008

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.