Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2020-07-29strvec: rename files from argv-array to strvecJeff King
This requires updating #include lines across the code-base, but that's all fairly mechanical, and was done with: git ls-files '*.c' '*.h' | xargs perl -i -pe 's/argv-array.h/strvec.h/' Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-29argv-array: rename to strvecJeff King
The name "argv-array" isn't very good, because it describes what the data type can be used for (program argument arrays), not what it actually is (a dynamically-growing string array that maintains a NULL-terminator invariant). This leads to people being hesitant to use it for other cases where it would actually be a good fit. The existing name is also clunky to use. It's overly long, and the name often leads to saying things like "argv.argv" (i.e., the field names overlap with variable names, since they're describing the use, not the type). Let's give it a more neutral name. I settled on "strvec" because "vector" is the name for a dynamic array type in many programming languages. "strarray" would work, too, but it's longer and a bit more awkward to say (and don't we all say these things in our mind as we type them?). A more extreme direction would be a generic data structure which stores a NULL-terminated of _any_ type. That would be easy to do with void pointers, but we'd lose some type safety for the existing cases. Plus it raises questions about memory allocation and ownership. So I limited myself here to changing names only, and not semantics. If we do find a use for that more generic data type, we could perhaps implement it at a lower level and then provide type-safe wrappers around it for strings. But that can come later. This patch does the minimum to convert the struct and function names in the header and implementation, leaving a few things for follow-on patches: - files retain their original names for now - struct field names are retained for now - there's a preprocessor compat layer that lets most users remain the same for now. The exception is headers which made a manual forward declaration of the struct. I've converted them (and their dependent function declarations) here. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-29argv-array: use size_t for count and allocJeff King
On most 64-bit platforms, "int" is significantly smaller than a size_t, which could lead to integer overflow and under-allocation of the array. It's probably impossible to trigger in practice, as it would imply on the order of 2^32 individual allocations. Even if was possible to grow an array in that way (and we typically only use it for sets of strings, like command line options), each allocation needs a pointer, malloc overhead, etc. You'd quite likely run out of RAM before succeeding in such an overflow. But all that hand-waving aside, it's easy enough to use the correct type, so let's do so. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-11-18argv-array: move doc to argv-array.hHeba Waly
Move the documentation from Documentation/technical/api-argv-array.txt to argv-array.h as it's easier for the developers to find the usage information beside the code instead of looking for it in another doc file. Also documentation/technical/api-argv-array.txt is removed because the information it has is now redundant and it'll be hard to keep it up to date and synchronized with the documentation in the header file. Signed-off-by: Heba Waly <heba.waly@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-05-30Merge branch 'ma/unpack-trees-free-msgs'Junio C Hamano
Leak plugging. * ma/unpack-trees-free-msgs: unpack_trees_options: free messages when done argv-array: return the pushed string from argv_push*() merge-recursive: provide pair of `unpack_trees_{start,finish}()` merge: setup `opts` later in `checkout_fast_forward()`
2018-05-22argv-array: return the pushed string from argv_push*()Junio C Hamano
Such an API change allows us to use an argv_array this way: struct argv_array to_free = ARGV_ARRAY_INIT; const char *msg; if (some condition) { msg = "constant string message"; ... other logic ... } else { msg = argv_array_pushf(&to_free, "format %s", var); } ... use "msg" ... ... do other things ... argv_array_clear(&to_free); Note that argv_array_pushl() and argv_array_pushv() are used to push one or more strings with a single call, so we do not return any one of these strings from these two functions in order to reduce the chance to misuse the API. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Martin Ă…gren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-04-26argv_array: offer to split a string by whitespaceJohannes Schindelin
This is a simple function that will interpret a string as a whitespace delimited list of values, and add those values into the array. Note: this function does not (yet) offer to split by arbitrary delimiters, or keep empty values in case of runs of whitespace, or de-quote Unix shell style. All fo this functionality can be added later, when and if needed. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-02-23argv-array: add detach functionJeff King
The usual pattern for an argv array is to initialize it, push in some strings, and then clear it when done. Very occasionally, though, we must do other exotic things with the memory, like freeing the list but keeping the strings. Let's provide a detach function so that callers can make use of our API to build up the array, and then take ownership of it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-15argv-array: implement argv_array_pushv()Paul Tan
When we have a null-terminated array, it would be useful to convert it or append it to an argv_array for further manipulation. Implement argv_array_pushv() which will push a null-terminated array of strings on to an argv_array. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-05-15argv-array: drop "detach" codeJeff King
The argv_array_detach function (and associated free() function) was really only useful for transferring ownership of the memory to a "struct child_process". Now that we have an internal argv_array in that struct, there are no callers left. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-19Add the LAST_ARG_MUST_BE_NULL macroRamsay Jones
The sentinel function attribute is not understood by versions of the gcc compiler prior to v4.0. At present, for earlier versions of gcc, the build issues 108 warnings related to the unknown attribute. In order to suppress the warnings, we conditionally define the LAST_ARG_MUST_BE_NULL macro to provide the sentinel attribute for gcc v4.0 and newer. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-10use "sentinel" function attribute for variadic listsJeff King
This attribute can help gcc notice when callers forget to add a NULL sentinel to the end of the function. This is our first use of the sentinel attribute, but we shouldn't need to #ifdef for other compilers, as __attribute__ is already a no-op on non-gcc-compatible compilers. Suggested-by: Bert Wesarg <bert.wesarg@googlemail.com> More-Spots-Found-By: Matt Kraai <kraai@ftbfs.org> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-10-25Merge branch 'fa/remote-svn'Jeff King
A GSoC project. * fa/remote-svn: Add a test script for remote-svn remote-svn: add marks-file regeneration Add a svnrdump-simulator replaying a dump file for testing remote-svn: add incremental import remote-svn: Activate import/export-marks for fast-import Create a note for every imported commit containing svn metadata vcs-svn: add fast_export_note to create notes Allow reading svn dumps from files via file:// urls remote-svn, vcs-svn: Enable fetching to private refs When debug==1, start fast-import with "--stats" instead of "--quiet" Add documentation for the 'bidi-import' capability of remote-helpers Connect fast-import to the remote-helper via pipe, adding 'bidi-import' capability Add argv_array_detach and argv_array_free_detached Add svndump_init_fd to allow reading dumps from arbitrary FDs Add git-remote-testsvn to Makefile Implement a remote helper for svn in C
2012-10-08Add argv_array_detach and argv_array_free_detachedFlorian Achleitner
Allow detaching of ownership of the argv_array's contents and add a function to free those detached argv_arrays later. This makes it possible to use argv_array efficiently with the exiting struct child_process which only contains a member char **argv. Add to documentation. Signed-off-by: Florian Achleitner <florian.achleitner.2.6.31@gmail.com> Acked-by: David Michael Barr <b@rr-dav.id.au> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-03argv-array: add pop functionJeff King
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>
2012-04-19argv-array: add a new "pushl" methodJeff King
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>
2012-04-19argv-array: refactor empty_argv initializationJeff King
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>
2011-09-14refactor argv_array into generic codeJeff King
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>