aboutsummaryrefslogtreecommitdiff
path: root/argv-array.c
Commit message (Collapse)AuthorAge
* argv-array: fix bogus cast when freeing arrayJeff King2012-09-02
| | | | | | | | | | | | | | Since the array struct stores a "const char **" argv member (for compatibility with most of our argv-taking functions), we have to cast away the const-ness when freeing its elements. However, we used the wrong type when doing so. It doesn't make a difference since free() take a void pointer anyway, but it can be slightly confusing to a reader. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* argv-array: add pop functionJeff King2012-09-02
| | | | | | | | | | | | | | Sometimes we build a set of similar command lines, differing only in the final arguments (e.g., "fetch --multiple"). To use argv_array for this, you have to either push the same set of elements repeatedly, or break the abstraction by manually manipulating the array's internal members. Instead, let's provide a sanctioned "pop" function to remove elements from the end. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* argv-array: add a new "pushl" methodJeff King2012-04-18
| | | | | | | | | It can be convenient to push many strings in a single line (e.g., if you are initializing an array with defaults). This patch provides a convenience wrapper to allow this. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* argv-array: refactor empty_argv initializationJeff King2012-04-18
| | | | | | | | | | | | | | | | | | | | An empty argv-array is initialized to point to a static empty NULL-terminated array. The original implementation separates the actual storage of the NULL-terminator from the pointer to the list. This makes the exposed type a "const char **", which nicely matches the type stored by the argv-array. However, this indirection means that one cannot use empty_argv to initialize a static variable, since it is not a constant. Instead, we can expose empty_argv directly, as an array of pointers. The only place we use it is in the ARGV_ARRAY_INIT initializer, and it decays to a pointer appropriately there. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* refactor argv_array into generic codeJeff King2011-09-14
The submodule code recently grew generic code to build a dynamic argv array. Many other parts of the code can reuse this, too, so let's make it generically available. There are two enhancements not found in the original code: 1. We now handle the NULL-termination invariant properly, even when no strings have been pushed (before, you could have an empty, NULL argv). This was not a problem for the submodule code, which always pushed at least one argument, but was not sufficiently safe for generic code. 2. There is a formatted variant of the "push" function. This is a convenience function which was not needed by the submodule code, but will make it easier to port other users to the new code. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>