On Sat, Feb 20, 2016 at 3:57 AM, Jeff King <peff@xxxxxxxx> wrote: > On Sat, Feb 20, 2016 at 03:39:36AM -0500, Eric Sunshine wrote: >> I also had made the strbuf_detach() analogy in my response but deleted >> it before sending; I do think it's a reasonable API template to mirror >> via new argv_array_detach(). > > That would look like this, which I think is not too bad (on top of my > series for now; I'd do the API function as a separate patch at the > beginning and then use it immediately). Looks reasonable. > diff --git a/argv-array.c b/argv-array.c > index eaed477..5d370fa 100644 > --- a/argv-array.c > +++ b/argv-array.c > @@ -74,3 +74,14 @@ void argv_array_clear(struct argv_array *array) > } > argv_array_init(array); > } > + > +const char **argv_array_detach(struct argv_array *array) > +{ > + if (array->argv == empty_argv) > + return xcalloc(1, sizeof(const char *)); > + else { > + const char **ret = array->argv; > + argv_array_init(array); > + return ret; > + } > +} > diff --git a/argv-array.h b/argv-array.h > index a2fa0aa..29056e4 100644 > --- a/argv-array.h > +++ b/argv-array.h > @@ -20,5 +20,6 @@ void argv_array_pushl(struct argv_array *, ...); > void argv_array_pushv(struct argv_array *, const char **); > void argv_array_pop(struct argv_array *); > void argv_array_clear(struct argv_array *); > +const char **argv_array_detach(struct argv_array *); > > #endif /* ARGV_ARRAY_H */ > diff --git a/line-log.c b/line-log.c > index fa095b9..bbe31ed 100644 > --- a/line-log.c > +++ b/line-log.c > @@ -748,15 +748,17 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list > > if (!rev->diffopt.detect_rename) { > struct line_log_data *r; > - struct argv_array paths = ARGV_ARRAY_INIT; > + struct argv_array array = ARGV_ARRAY_INIT; > + const char **paths; > > for (r = range; r; r = r->next) > - argv_array_push(&paths, r->path); > + argv_array_push(&array, r->path); > + paths = argv_array_detach(&array); > + > parse_pathspec(&rev->diffopt.pathspec, 0, > - PATHSPEC_PREFER_FULL, "", paths.argv); > - /* argv strings are now owned by pathspec */ > - paths.argc = 0; > - argv_array_clear(&paths); > + PATHSPEC_PREFER_FULL, "", paths); > + /* strings are now owned by pathspec */ > + free(paths); > } > } -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html