add: Rewrite run_add_interactive to use struct argv_array
PATCH 1/1 add: Rewrite run_add_interactive to use struct argv_array
Origin code are code with own realisation argv array editing. It was changed, and code modified for using unified argv-array realisation from argv-array.h.
Commit for Google Summer of Code 2014
--- builtin/add.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
builtin/add.c +10 -11
@@ -15,6 +15,7 @@#include "diffcore.h" #include "revision.h" #include "bulk-checkin.h" +#include "argv-array.h" static const char *const builtin_add_usage[] = {N_ ("git add [options] [--] <pathspec>..." ),
@@ -141,23 +142,21 @@ static void refresh(int verbose, const struct pathspec *pathspec)int run_add_interactive (const char *revision,const char *patch_mode,const struct pathspec *pathspec) { -int status, ac, i; -const char **args; +int status, i; +struct argv_array *argv =ARGV_ARRAY_INIT ; - args =xcalloc (sizeof (const char *), (pathspec->nr +6 )); - ac =0 ; - args[ac++] ="add--interactive" ; +argv_array_push (argv,"add--interactive" );if (patch_mode) - args[ac++] = patch_mode; +argv_array_push (argv, patch_mode);if (revision) - args[ac++] = revision; - args[ac++] ="--" ; +argv_array_push (argv, revision); +argv_array_push (argv,"--" );for (i =0 ; i < pathspec->nr; i++)/* pass original pathspec, to be re-parsed */ - args[ac++] = pathspec->items[i].original; +argv_array_push (argv, pathspec->items[i].original); - status =run_command_v_opt (args,RUN_GIT_CMD ); -free (args); + status =run_command_v_opt (argv->argv,RUN_GIT_CMD ); +argv_array_clear (argv);return status; }
Signature · 1 line
1.7.10.4
Quoted 7 lines · Movchan Pavel
Origin code are code with own realisation argv array editing. It was changed, and code modified for using unified argv-array realisation from
argv-array.h.
Commit for Google Summer of Code 2014Signed-off-by Movchan Pavel <[email protected]>---
Thanks. "Commit for ..." is not something we would want to see in "git log" output, though.
Quoted 16 lines
builtin/add.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)builtin/add.c +1
-0@@ -15,6 +15,7 @@#include "diffcore.h" #include "revision.h" #include "bulk-checkin.h" +#include "argv-array.h" static const char *const builtin_add_usage[] = {N_ ("git add [options] [--] <pathspec>..." ),
builtin/add.c static void refresh(int verbose, const struct pathspec *pathspec) · line 146
Quoted 7 lines
builtin/add.c +2
-2@@ -141,23 +142,21 @@ static void refresh(int verbose, const struct pathspec *pathspec)int run_add_interactive (const char *revision,const char *patch_mode,const struct pathspec *pathspec) { -int status, ac, i; -const char **args; +int status, i; +struct argv_array *argv =ARGV_ARRAY_INIT ;
Where does that pointer point at and who allocated the piece of memory used by it?
See http://thread.gmane.org/gmane.comp.version-control.git/244151
for an example solution.
Quoted 24 lines
builtin/add.c +7
-9- args =xcalloc (sizeof (const char *), (pathspec->nr +6 )); - ac =0 ; - args[ac++] ="add--interactive" ; +argv_array_push (argv,"add--interactive" );if (patch_mode) - args[ac++] = patch_mode; +argv_array_push (argv, patch_mode);if (revision) - args[ac++] = revision; - args[ac++] ="--" ; +argv_array_push (argv, revision); +argv_array_push (argv,"--" );for (i =0 ; i < pathspec->nr; i++)/* pass original pathspec, to be re-parsed */ - args[ac++] = pathspec->items[i].original; +argv_array_push (argv, pathspec->items[i].original); - status =run_command_v_opt (args,RUN_GIT_CMD ); -free (args); + status =run_command_v_opt (argv->argv,RUN_GIT_CMD ); +argv_array_clear (argv);return status; }