1. 24 Mar, 2019 1 commit
  2. 28 Jan, 2019 3 commits
  3. 12 Nov, 2018 1 commit
    • Duy Nguyen's avatar
      parse-options: replace opterror() with optname() · 9440b831
      Duy Nguyen authored
      Introduce optname() that does the early half of original opterror() to
      come up with the name of the option reported back to the user, and use
      it to kill opterror().  The callers of opterror() now directly call
      error() using the string returned by opterror() instead.
      
      There are a few issues with opterror()
      
      - it tries to assemble an English sentence from pieces. This is not
        great for translators because we give them pieces instead of a full
        sentence.
      
      - It's a wrapper around error() and needs some hack to let the
        compiler know it always returns -1.
      
      - Since it takes a string instead of printf format, one call site has
        to assemble the string manually before passing to it.
      
      Using error() directly solves the second and third problems.
      
      It kind helps the first problem as well because "%s does foo" does
      give a translator a full sentence in a sense and let them reorder if
      needed. But it has limitations, if the subject part has to change
      based on the rest of the sentence, that language is screwed. This is
      also why I try to avoid calling optname() when 'flags' is known in
      advance.
      
      Mark of these strings for translation as well while at there.
      Signed-off-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      9440b831
  4. 06 Nov, 2018 2 commits
    • Jeff King's avatar
      assert NOARG/NONEG behavior of parse-options callbacks · 517fe807
      Jeff King authored
      When we define a parse-options callback, the flags we put in the option
      struct must match what the callback expects. For example, a callback
      which does not handle the "unset" parameter should only be used with
      PARSE_OPT_NONEG. But since the callback and the option struct are not
      defined next to each other, it's easy to get this wrong (as earlier
      patches in this series show).
      
      Fortunately, the compiler can help us here: compiling with
      -Wunused-parameters can show us which callbacks ignore their "unset"
      parameters (and likewise, ones that ignore "arg" expect to be triggered
      with PARSE_OPT_NOARG).
      
      But after we've inspected a callback and determined that all of its
      callers use the right flags, what do we do next? We'd like to silence
      the compiler warning, but do so in a way that will catch any wrong calls
      in the future.
      
      We can do that by actually checking those variables and asserting that
      they match our expectations. Because this is such a common pattern,
      we'll introduce some helper macros. The resulting messages aren't
      as descriptive as we could make them, but the file/line information from
      BUG() is enough to identify the problem (and anyway, the point is that
      these should never be seen).
      
      Each of the annotated callbacks in this patch triggers
      -Wunused-parameters, and was manually inspected to make sure all callers
      use the correct options (so none of these BUGs should be triggerable).
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      517fe807
    • Jeff King's avatar
      parse-options: drop OPT_DATE() · 0a8a16ad
      Jeff King authored
      There are no users of OPT_DATE except for test-parse-options; its
      only caller went away in 27ec394a (prune: introduce OPT_EXPIRY_DATE()
      and use it, 2013-04-25).
      
      It also has a bug: it does not specify PARSE_OPT_NONEG, but its callback
      does not respect the "unset" flag, and will feed NULL to approxidate()
      and segfault. Probably this should be marked with NONEG, or the callback
      should set the timestamp to some sentinel value (e.g,. "0", or
      "(time_t)-1").
      
      But since there are no callers, deleting it means we don't even have to
      think about what the right behavior should be.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      0a8a16ad
  5. 29 Jun, 2018 1 commit
  6. 23 Apr, 2018 1 commit
    • Junio C Hamano's avatar
      parseopt: handle malformed --expire arguments more nicely · 8ab5aa4b
      Junio C Hamano authored
      A few commands that parse --expire=<time> command line option behave
      sillily when given nonsense input.  For example
      
          $ git prune --no-expire
          Segmentation falut
          $ git prune --expire=npw; echo $?
          129
      
      Both come from parse_opt_expiry_date_cb().
      
      The former is because the function is not prepared to see arg==NULL
      (for "--no-expire", it is a norm; "--expire" at the end of the
      command line could be made to pass NULL, if it is told that the
      argument is optional, but we don't so we do not have to worry about
      that case).
      
      The latter is because it does not check the value returned from the
      underlying parse_expiry_date().
      
      This seems to be a recent regression introduced while we attempted
      to avoid spewing the entire usage message when given a correct
      option but with an invalid value at 3bb0923f ("parse-options: do not
      show usage upon invalid option value", 2018-03-22).  Before that, we
      didn't fail silently but showed a full usage help (which arguably is
      not all that better).
      
      Also catch this error early when "git gc --prune=<expiration>" is
      misspelled by doing a dummy parsing before the main body of "gc"
      that is time consuming even begins.  Otherwise, we'd spend time to
      pack objects and then later have "git prune" first notice the error.
      Aborting "gc" in the middle that way is not harmful but is ugly and
      can be avoided.
      Helped-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      8ab5aa4b
  7. 08 May, 2017 2 commits
    • brian m. carlson's avatar
      Convert lookup_commit* to struct object_id · bc83266a
      brian m. carlson authored
      Convert lookup_commit, lookup_commit_or_die,
      lookup_commit_reference, and lookup_commit_reference_gently to take
      struct object_id arguments.
      
      Introduce a temporary in parse_object buffer in order to convert this
      function.  This is required since in order to convert parse_object and
      parse_object_buffer, lookup_commit_reference_gently and
      lookup_commit_or_die would need to be converted.  Not introducing a
      temporary would therefore require that lookup_commit_or_die take a
      struct object_id *, but lookup_commit would take unsigned char *,
      leaving a confusing and hard-to-use interface.
      
      parse_object_buffer will lose this temporary in a later patch.
      
      This commit was created with manual changes to commit.c, commit.h, and
      object.c, plus the following semantic patch:
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_reference_gently(E1.hash, E2)
      + lookup_commit_reference_gently(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_reference_gently(E1->hash, E2)
      + lookup_commit_reference_gently(E1, E2)
      
      @@
      expression E1;
      @@
      - lookup_commit_reference(E1.hash)
      + lookup_commit_reference(&E1)
      
      @@
      expression E1;
      @@
      - lookup_commit_reference(E1->hash)
      + lookup_commit_reference(E1)
      
      @@
      expression E1;
      @@
      - lookup_commit(E1.hash)
      + lookup_commit(&E1)
      
      @@
      expression E1;
      @@
      - lookup_commit(E1->hash)
      + lookup_commit(E1)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_or_die(E1.hash, E2)
      + lookup_commit_or_die(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_or_die(E1->hash, E2)
      + lookup_commit_or_die(E1, E2)
      Signed-off-by: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      bc83266a
    • brian m. carlson's avatar
      parse-options-cb: convert to struct object_id · 9e31eafe
      brian m. carlson authored
      This is a caller of lookup_commit_reference, which we will soon convert.
      Signed-off-by: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      9e31eafe
  8. 27 Apr, 2017 1 commit
    • Johannes Schindelin's avatar
      timestamp_t: a new data type for timestamps · dddbad72
      Johannes Schindelin authored
      Git's source code assumes that unsigned long is at least as precise as
      time_t. Which is incorrect, and causes a lot of problems, in particular
      where unsigned long is only 32-bit (notably on Windows, even in 64-bit
      versions).
      
      So let's just use a more appropriate data type instead. In preparation
      for this, we introduce the new `timestamp_t` data type.
      
      By necessity, this is a very, very large patch, as it has to replace all
      timestamps' data type in one go.
      
      As we will use a data type that is not necessarily identical to `time_t`,
      we need to be very careful to use `time_t` whenever we interact with the
      system functions, and `timestamp_t` everywhere else.
      Signed-off-by: Johannes Schindelin's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      dddbad72
  9. 31 Mar, 2017 2 commits
  10. 28 Mar, 2017 1 commit
  11. 10 Oct, 2016 1 commit
  12. 19 Sep, 2016 1 commit
  13. 06 Jul, 2016 1 commit
    • Jeff King's avatar
      parse_options: allocate a new array when concatenating · 023ff39b
      Jeff King authored
      In exactly one callers (builtin/revert.c), we build up the
      options list dynamically from multiple arrays. We do so by
      manually inserting "filler" entries into one array, and then
      copying the other array into the allocated space.
      
      This is tedious and error-prone, as you have to adjust the
      filler any time the second array is modified (although we do
      at least check and die() when the counts do not match up).
      
      Instead, let's just allocate a new array.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      023ff39b
  14. 13 Jun, 2016 1 commit
    • Jeff King's avatar
      parse_opt_string_list: stop allocating new strings · 7a7a517a
      Jeff King authored
      The parse_opt_string_list callback is basically a thin
      wrapper to string_list_append() any string options we get.
      However, it calls:
      
        string_list_append(v, xstrdup(arg));
      
      which duplicates the option value. This is wrong for two
      reasons:
      
        1. If the string list has strdup_strings set, then we are
           making an extra copy, which is simply leaked.
      
        2. If the string list does not have strdup_strings set,
           then we pass memory ownership to the string list, but
           it does not realize this. If we later call
           string_list_clear(), which can happen if "--no-foo" is
           passed, then we will leak all of the existing entries.
      
      Instead, we should just pass the argument straight to
      string_list_append, and it can decide whether to copy or not
      based on its strdup_strings flag.
      
      It's possible that some (buggy) caller could be relying on
      this extra copy (e.g., because it parses some options from
      an allocated argv array and then frees the array), but it's
      not likely. For one, we generally only use parse_options on
      the argv given to us in main(). And two, such a caller is
      broken anyway, because other option types like OPT_STRING()
      do not make such a copy.  This patch brings us in line with
      them.
      Noticed-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      7a7a517a
  15. 03 Aug, 2015 2 commits
  16. 15 Jun, 2015 2 commits
  17. 25 Apr, 2013 1 commit
    • Junio C Hamano's avatar
      prune: introduce OPT_EXPIRY_DATE() and use it · 27ec394a
      Junio C Hamano authored
      Earlier we added support for --expire=all (or --expire=now) that
      considers all crufts, regardless of their age, as eligible for
      garbage collection by turning command argument parsers that use
      approxidate() to use parse_expiry_date(), but "git prune" used a
      built-in parse-options facility OPT_DATE() and did not benefit from
      the new function.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      27ec394a
  18. 28 Sep, 2011 1 commit
  19. 11 Aug, 2011 1 commit
    • Dmitry Ivankov's avatar
      Reduce parse-options.o dependencies · 06876284
      Dmitry Ivankov authored
      Currently parse-options.o pulls quite a big bunch of dependencies.
      his complicates it's usage in contrib/ because it pulls external
      dependencies and it also increases executables size.
      
      Split off less generic and more internal to git part of
      parse-options.c to parse-options-cb.c.
      
      Move prefix_filename function from setup.c to abspath.c. abspath.o
      and wrapper.o pull each other, so it's unlikely to increase the
      dependencies. It was a dependency of parse-options.o that pulled
      many others.
      
      Now parse-options.o pulls just abspath.o, ctype.o, strbuf.o, usage.o,
      wrapper.o, libc directly and strlcpy.o indirectly.
      Signed-off-by: default avatarDmitry Ivankov <divanorama@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      06876284