1. 25 3月, 2017 2 次提交
    • Æ
      ref-filter: add --no-contains option to tag/branch/for-each-ref · ac3f5a34
      Ævar Arnfjörð Bjarmason 提交于
      Change the tag, branch & for-each-ref commands to have a --no-contains
      option in addition to their longstanding --contains options.
      
      This allows for finding the last-good rollout tag given a known-bad
      <commit>. Given a hypothetically bad commit cf5c7253, the git
      version to revert to can be found with this hacky two-liner:
      
          (git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253 'v[0-9]*') |
              sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10
      
      With this new --no-contains option the same can be achieved with:
      
          git tag -l --no-contains cf5c7253 'v[0-9]*' | sort | tail -n 10
      
      As the filtering machinery is shared between the tag, branch &
      for-each-ref commands, implement this for those commands too. A
      practical use for this with "branch" is e.g. finding branches which
      were branched off between v2.8.0 and v2.10.0:
      
          git branch --contains v2.8.0 --no-contains v2.10.0
      
      The "describe" command also has a --contains option, but its semantics
      are unrelated to what tag/branch/for-each-ref use --contains for. A
      --no-contains option for "describe" wouldn't make any sense, other
      than being exactly equivalent to not supplying --contains at all,
      which would be confusing at best.
      
      Add a --without option to "tag" as an alias for --no-contains, for
      consistency with --with and --contains.  The --with option is
      undocumented, and possibly the only user of it is
      Junio (<xmqqefy71iej.fsf@gitster.mtv.corp.google.com>). But it's
      trivial to support, so let's do that.
      
      The additions to the the test suite are inverse copies of the
      corresponding --contains tests. With this change --no-contains for
      tag, branch & for-each-ref is just as well tested as the existing
      --contains option.
      
      In addition to those tests, add a test for "tag" which asserts that
      --no-contains won't find tree/blob tags, which is slightly
      unintuitive, but consistent with how --contains works & is documented.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ac3f5a34
    • Æ
      parse-options: add OPT_NONEG to the "contains" option · eab98ee5
      Ævar Arnfjörð Bjarmason 提交于
      Add the OPT_NONEG flag to the "contains" option and its hidden synonym
      "with". Since this was added in commit 694a5775 ("git-branch
      --contains=commit", 2007-11-07) giving --no-{contains,with} hasn't
      been an error, but has emitted the help output since
      filter.with_commit wouldn't get set.
      
      Now git will emit "error: unknown option `no-{contains,with}'" at the
      top of the help output.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      eab98ee5
  2. 20 9月, 2016 1 次提交
  3. 07 7月, 2016 1 次提交
    • J
      parse_options: allocate a new array when concatenating · 023ff39b
      Jeff King 提交于
      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: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      023ff39b
  4. 20 11月, 2015 1 次提交
  5. 04 8月, 2015 3 次提交
  6. 30 7月, 2015 1 次提交
  7. 23 6月, 2015 1 次提交
    • C
      parse-options: move unsigned long option parsing out of pack-objects.c · 2a514ed8
      Charles Bailey 提交于
      The unsigned long option parsing (including 'k'/'m'/'g' suffix
      parsing) is more widely applicable.  Add support for OPT_MAGNITUDE
      to parse-options.h and change pack-objects.c use this support.
      
      The error behavior on parse errors follows that of OPT_INTEGER.  The
      name of the option that failed to parse is reported with a brief
      message describing the expect format for the option argument and
      then the full usage message for the command invoked.
      
      This differs from the previous behavior for OPT_ULONG used in
      pack-objects for --max-pack-size and --window-memory which used to
      display the value supplied in the error message and did not display
      the full usage message.
      Signed-off-by: NCharles Bailey <cbailey32@bloomberg.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2a514ed8
  8. 16 6月, 2015 2 次提交
  9. 30 3月, 2015 1 次提交
  10. 07 5月, 2014 2 次提交
    • J
      let clang use the constant-return error() macro · ff0a80af
      Jeff King 提交于
      Commit e208f9cc converted error() into a macro to make its
      constant return value more apparent to calling code.  Commit
      5ded807f prevents us using this macro with clang, since
      clang's -Wunused-value is smart enough to realize that the
      constant "-1" is useless in some contexts.
      
      However, since the last commit puts the constant behind an
      inline function call, this is enough to prevent the
      -Wunused-value warning on both modern gcc and clang. So we
      can now re-enable the macro when compiling with clang.
      
      Tested with clang 3.3, 3.4, and 3.5.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ff0a80af
    • J
      inline constant return from error() function · 87fe5df3
      Jeff King 提交于
      Commit e208f9cc introduced a macro to turn error() calls
      into:
      
        (error(), -1)
      
      to make the constant return value more visible to the
      calling code (and thus let the compiler make better
      decisions about the code).
      
      This works well for code like:
      
        return error(...);
      
      but the "-1" is superfluous in code that just calls error()
      without caring about the return value. In older versions of
      gcc, that was fine, but gcc 4.9 complains with -Wunused-value.
      
      We can work around this by encapsulating the constant return
      value in a static inline function, as gcc specifically
      avoids complaining about unused function returns unless the
      function has been specifically marked with the
      warn_unused_result attribute.
      
      We also use the same trick for config_error_nonbool and
      opterror, which learned the same error technique in a469a101.
      Reported-by: NFelipe Contreras <felipe.contreras@gmail.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      87fe5df3
  11. 01 4月, 2014 2 次提交
  12. 25 3月, 2014 1 次提交
    • J
      parse-options: multi-word argh should use dash to separate words · e703d711
      Junio C Hamano 提交于
      "When you need to use space, use dash" is a strange way to say that
      you must not use a space.  Because it is more common for the command
      line descriptions to use dashed-multi-words, you do not even want to
      use spaces in these places.  Rephrase the documentation to avoid
      this strangeness.
      
      Fix a few existing multi-word argument help strings, i.e.
      
       - GPG key-ids given to -S/--gpg-sign are "key-id";
       - Refs used for storing notes are "notes-ref"; and
       - Expiry timestamps given to --expire are "expiry-date".
      
      and update the corresponding documentation pages.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e703d711
  13. 10 12月, 2013 1 次提交
  14. 10 8月, 2013 1 次提交
    • E
      parse-options: fix clang opterror() -Wunused-value warning · a3bc3d07
      Eric Sunshine 提交于
      a469a101 (silence some -Wuninitialized false positives;
      2012-12-15) triggered "unused value" warnings when the return value of
      opterror() and several other error-related functions was not used.
      5ded807f (fix clang -Wunused-value warnings for error functions;
      2013-01-16) applied a fix by adding #if !defined(__clang__) in cache.h
      and git-compat-util.h, but misspelled it as #if !defined(clang) in
      parse-options.h. Fix this.
      
      This mistake went unnoticed because existing callers of opterror()
      utilize its return value.  11588263 (parse-options: add
      OPT_CMDMODE(); 2013-07-30), however, adds a new invocation of opterror()
      which ignores the return value, thus triggering the "unused value"
      warning.
      Signed-off-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a3bc3d07
  15. 06 8月, 2013 1 次提交
    • S
      Remove deprecated OPTION_BOOLEAN for parsing arguments · 4741edd5
      Stefan Beller 提交于
      As of b04ba2bb OPTION_BOOLEAN was deprecated.
      This commit removes all occurrences of OPTION_BOOLEAN.
      In b04ba2bb Junio suggested to replace it with either
      OPTION_SET_INT or OPTION_COUNTUP instead. However a pattern, which
      occurred often with the OPTION_BOOLEAN was a hidden boolean parameter.
      So I defined OPT_HIDDEN_BOOL as an additional possible parse option
      in parse-options.h to make life easy.
      
      The OPT_HIDDEN_BOOL was used in checkout, clone, commit, show-ref.
      The only exception, where there was need to fiddle with OPTION_SET_INT
      was log and notes. However in these two files there is also a pattern,
      so we could think of introducing OPT_NONEG_BOOL.
      Signed-off-by: NStefan Beller <stefanbeller@googlemail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4741edd5
  16. 31 7月, 2013 1 次提交
  17. 26 4月, 2013 1 次提交
    • J
      prune: introduce OPT_EXPIRY_DATE() and use it · 27ec394a
      Junio C Hamano 提交于
      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: NJunio C Hamano <gitster@pobox.com>
      27ec394a
  18. 17 1月, 2013 1 次提交
    • M
      fix clang -Wunused-value warnings for error functions · 5ded807f
      Max Horn 提交于
      Commit a469a101 wraps some error calls in macros to give the
      compiler a chance to do more static analysis on their
      constant -1 return value.  We limit the use of these macros
      to __GNUC__, since gcc is the primary beneficiary of the new
      information, and because we use GNU features for handling
      variadic macros.
      
      However, clang also defines __GNUC__, but generates warnings
      with -Wunused-value when these macros are used in a void
      context, because the constant "-1" ends up being useless.
      Gcc does not complain about this case (though it is unclear
      if it is because it is smart enough to see what we are
      doing, or too dumb to realize that the -1 is unused).  We
      can squelch the warning by just disabling these macros when
      clang is in use.
      Signed-off-by: NMax Horn <max@quendi.de>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5ded807f
  19. 16 12月, 2012 1 次提交
    • J
      silence some -Wuninitialized false positives · a469a101
      Jeff King 提交于
      There are a few error functions that simply wrap error() and
      provide a standardized message text. Like error(), they
      always return -1; knowing that can help the compiler silence
      some false positive -Wuninitialized warnings.
      
      One strategy would be to just declare these as inline in the
      header file so that the compiler can see that they always
      return -1. However, gcc does not always inline them (e.g.,
      it will not inline opterror, even with -O3), which renders
      our change pointless.
      
      Instead, let's follow the same route we did with error() in
      the last patch, and define a macro that makes the constant
      return value obvious to the compiler.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a469a101
  20. 21 8月, 2012 1 次提交
  21. 09 5月, 2012 1 次提交
  22. 28 4月, 2012 1 次提交
    • N
      Add column layout skeleton and git-column · 7e29b825
      Nguyễn Thái Ngọc Duy 提交于
      A column option string consists of many token separated by either
      a space or a  comma. A token belongs to one of three groups:
      
       - enabling: always, never and auto
       - layout mode: currently plain (which does not layout at all)
       - other future tuning flags
      
      git-column can be used to pipe output to from a command that wants
      column layout, but not to mess with its own output code. Simpler output
      code can be changed to use column layout code directly.
      
      Thanks-to: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7e29b825
  23. 29 2月, 2012 1 次提交
  24. 29 9月, 2011 1 次提交
  25. 28 9月, 2011 1 次提交
    • J
      parse-options: deprecate OPT_BOOLEAN · b04ba2bb
      Junio C Hamano 提交于
      It is natural to expect that an option defined with OPT_BOOLEAN() could be
      used in this way:
      
      	int option = -1; /* unspecified */
      
      	struct option options[] = {
      		OPT_BOOLEAN(0, "option", &option, "set option"),
                      OPT_END()
      	};
      	parse_options(ac, av, prefix, options, usage, 0);
      
              if (option < 0)
              	... do the default thing ...
      	else if (!option)
      		... --no-option was given ...
      	else
      		... --option was given ...
      
      to easily tell three cases apart:
      
       - There is no mention of the `--option` on the command line;
       - The variable is positively set with `--option`; or
       - The variable is explicitly negated with `--no-option`.
      
      Unfortunately, this is not the case. OPT_BOOLEAN() increments the variable
      every time `--option` is given, and resets it to zero when `--no-option`
      is given.
      
      As a first step to remedy this, introduce a true boolean OPT_BOOL(), and
      rename OPT_BOOLEAN() to OPT_COUNTUP(). To help transitioning, OPT_BOOLEAN
      and OPTION_BOOLEAN are defined as deprecated synonyms to OPT_COUNTUP and
      OPTION_COUNTUP respectively.
      
      This is what db7244bd (parse-options new features., 2007-11-07) from four
      years ago started by marking OPTION_BOOLEAN as "INCR would have been a
      better name".
      
      Some existing users do depend on the count-up semantics; for example,
      users of OPT__VERBOSE() could use it to raise the verbosity level with
      repeated use of `-v` on the command line, but they probably should be
      rewritten to use OPT__VERBOSITY() instead these days.  I suspect that some
      users of OPT__FORCE() may also use it to implement different level of
      forcibleness but I didn't check.
      
      On top of this patch, here are the remaining clean-up tasks that other
      people can help:
      
       - Look at each hit in "git grep -e OPT_BOOLEAN"; trace all uses of the
         value that is set to the underlying variable, and if it can proven that
         the variable is only used as a boolean, replace it with OPT_BOOL(). If
         the caller does depend on the count-up semantics, replace it with
         OPT_COUNTUP() instead.
      
       - Same for OPTION_BOOLEAN; replace it with OPTION_SET_INT and arrange to
         set 1 to the variable for a true boolean, and otherwise replace it with
         OPTION_COUNTUP.
      
       - Look at each hit in "git grep -e OPT__VERBOSE -e OPT__QUIET" and see if
         they can be replaced with OPT__VERBOSITY().
      
      I'll follow this message up with a separate patch as an example.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b04ba2bb
  26. 12 8月, 2011 1 次提交
  27. 23 6月, 2011 1 次提交
  28. 16 2月, 2011 1 次提交
  29. 08 12月, 2010 2 次提交
    • J
      parse-options: make resuming easier after PARSE_OPT_STOP_AT_NON_OPTION · 979240fe
      Jonathan Nieder 提交于
      Introduce a PARSE_OPT_NON_OPTION state, so parse_option_step()
      callers can easily distinguish between non-options and other
      reasons for option parsing termination (like "--").
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      979240fe
    • J
      parse-options: allow git commands to invent new option types · b0b3a8b6
      Jonathan Nieder 提交于
      parse-options provides a variety of option behaviors, including
      OPTION_CALLBACK, which should take care of just about any sane
      behavior.  All supported behaviors obey the following constraint:
      
       A --foo option can only accept (and base its behavior on)
       one argument, which would be the following command-line
       argument in the "unsticked" form.
      
      Alas, some existing git commands have options that do not obey that
      constraint.  For example, update-index --cacheinfo takes three
      arguments, and update-index --resolve takes all later parameters as
      arguments.
      
      Introduces an OPTION_LOWLEVEL_CALLBACK backdoor to parse-options so
      such option types can be supported without tempting inventors of other
      commands through mention in the public API.  Commands can set the
      callback field to a function accepting three arguments: the option
      parsing context, the option itself, and a flag indicating whether the
      the option was negated.  When the option is encountered, that function
      is called to take over from get_value().  The return value should be
      zero for success, -1 for usage errors.
      
      Thanks to Stephen Boyd for API guidance.
      Improved-by: NStephen Boyd <bebarino@gmail.com>
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b0b3a8b6
  30. 07 12月, 2010 1 次提交
  31. 16 11月, 2010 3 次提交