Re: [PATCH 3/4] Teach builtin-add to pass multiple paths to git-add--interactive
- From
Jeff King <peff@peff.net>
- Date
- Nov 22, 2007, 09:08 UTC
- Message-ID
- <20071122090828.GC7153@sigill.intra.peff.net>
- In-Reply-To
- <1195689773-28601-4-git-send-email-win@wincent.com>
On Thu, Nov 22, 2007 at 01:02:52AM +0100, Wincent Colaiuta wrote:
Show 10 quoted lines
> -int interactive_add(const char *path)
> +int interactive_add(const char **argv, int argc)
> {
> - const char *argv[3] = { "add--interactive", path, NULL };
> -
> - return run_command_v_opt(argv, RUN_GIT_CMD);
> + int status;
> + const char **args = xmalloc(sizeof(const char *) * (argc + 1));
> + args[0] = "add--interactive";
> + memcpy((void *)args + sizeof(const char *), argv, sizeof(const char *) * argc);The source for the memcpy (argv) is sometimes NULL. The standard forbids this, even when the size field is 0. I have no idea if any reasonable implementations actually care.
But...
Show 5 quoted lines
> + if (argc > 0) > + exit(interactive_add(argv, argc)); > else > - exit(interactive_add(NULL)); > + exit(interactive_add(NULL, 0));
There really is no reason to pass NULL at all (since the argc limits us anyway), so we can just get rid of the conditional and simplify to:
exit(interactive_add(argv, argc));
for both cases.
-Peff