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.