1. 22 May, 2018 1 commit
    • Junio C Hamano's avatar
      argv-array: return the pushed string from argv_push*() · 342c513a
      Junio C Hamano authored
      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: 's avatarJunio C Hamano <gitster@pobox.com>
      Signed-off-by: 's avatarMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      342c513a
  2. 26 Apr, 2018 1 commit
  3. 22 Feb, 2016 1 commit
    • Jeff King's avatar
      argv-array: add detach function · b992657e
      Jeff King authored
      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: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      b992657e
  4. 15 Jun, 2015 1 commit
  5. 15 May, 2014 1 commit
  6. 19 Jul, 2013 1 commit
  7. 10 Jul, 2013 1 commit
  8. 07 Oct, 2012 1 commit
  9. 03 Sep, 2012 1 commit
    • Jeff King's avatar
      argv-array: add pop function · fe4a0a28
      Jeff King authored
      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: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      fe4a0a28
  10. 18 Apr, 2012 2 commits
    • Jeff King's avatar
      argv-array: add a new "pushl" method · d15bbe13
      Jeff King authored
      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: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      d15bbe13
    • Jeff King's avatar
      argv-array: refactor empty_argv initialization · fd93d2e6
      Jeff King authored
      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: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      fd93d2e6
  11. 14 Sep, 2011 1 commit
    • Jeff King's avatar
      refactor argv_array into generic code · c1189cae
      Jeff King authored
      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: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      c1189cae