1. 21 Mar, 2019 1 commit
    • Jeff King's avatar
      parse_opt_ref_sorting: always use with NONEG flag · 95be717c
      Jeff King authored
      The "--sort" parameter of for-each-ref, etc, does not handle negation,
      and instead returns an error to the parse-options code. But neither
      piece of code prints anything for the user, which may leave them
        $ git for-each-ref --no-sort
        $ echo $?
      As the comment in the callback function notes, this probably should
      clear the list, which would make it consistent with other list-like
      options (i.e., anything that uses OPT_STRING_LIST currently).
      Unfortunately that's a bit tricky due to the way the ref-filter code
      works. But in the meantime, let's at least make the error a little less
        - switch to using PARSE_OPT_NONEG in the option definition, which will
          cause the options code to produce a useful message
        - since this was cut-and-pasted to four different spots, let's define
          a single OPT_REF_SORT() macro that we can use everywhere
        - the callback can use BUG_ON_OPT_NEG() to make sure the correct flags
          are used (incidentally, this also satisfies -Wunused-parameters,
          since we're now looking at "unset")
        - expand the comment into a NEEDSWORK to make it clear that the
          direction is right, but the details need to be worked out
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  2. 08 Apr, 2018 2 commits
  3. 29 Mar, 2018 1 commit
    • Olga Telezhnaya's avatar
      ref-filter: start adding strbufs with errors · 3019eca9
      Olga Telezhnaya authored
      This is a first step in removing die() calls from ref-filter
      formatting logic, so that it could be used by other commands
      that do not want to die during formatting process.
      die() calls related to bugs in code will not be touched in this patch.
      Everything would be the same for show_ref_array_item() users.
      But, if you want to deal with errors by your own, you could invoke
      format_ref_array_item(). It means that you need to print everything
      (the result and errors) on your side.
      This commit changes signature of format_ref_array_item() by adding
      return value and strbuf parameter for errors, and adjusts
      its callers. While at it, reduce the scope of the out-variable.
      Signed-off-by: Olga Telezhnaya's avatarOlga Telezhnaia <olyatelezhnaya@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  4. 13 Jul, 2017 5 commits
    • Jeff King's avatar
      ref-filter: consult want_color() before emitting colors · 11b087ad
      Jeff King authored
      When color placeholders like %(color:red) are used in a
      ref-filter format, we unconditionally output the colors,
      even if the user has asked us for no colors. This usually
      isn't a problem when the user is constructing a --format on
      the command line, but it means we may do the wrong thing
      when the format is fed from a script or alias. For example:
         $ git config alias.b 'branch --format=%(color:green)%(refname)'
         $ git b --no-color
      should probably omit the green color. Likewise, running:
         $ git b >branches
      should probably also omit the color, just as we would for
      all baked-in coloring (and as we recently started to do for
      user-specified colors in --pretty formats).
      This commit makes both of those cases work by teaching
      the ref-filter code to consult want_color() before
      outputting any color. The color flag in ref_format defaults
      to "-1", which means we'll consult color.ui, which in turn
      defaults to the usual isatty() check on stdout. However,
      callers like git-branch which support their own color config
      (and command-line options) can override that.
      The new tests independently cover all three of the callers
      of ref-filter (for-each-ref, tag, and branch). Even though
      these seem redundant, it confirms that we've correctly
      plumbed through all of the necessary config to make colors
      work by default.
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    • Jeff King's avatar
      ref-filter: make parse_ref_filter_atom a private function · aa8a5d14
      Jeff King authored
      The parse_ref_filter_atom() function really shouldn't be
      exposed outside of ref-filter.c; its return value is an
      integer index into an array that is private in that file.
      Since the previous commit removed the sole external caller
      (and replaced it with a public function at a more
      appropriately level), we can just make this static.
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    • Jeff King's avatar
      ref-filter: provide a function for parsing sort options · 18a25650
      Jeff King authored
      The ref-filter module currently provides a callback suitable
      for parsing command-line --sort options. But since git-tag
      also supports the tag.sort config option, it needs a
      function whose implementation is quite similar, but with a
      slightly different interface. The end result is that
      builtin/tag.c has a copy-paste of parse_opt_ref_sorting().
      Instead, let's provide a function to parse an arbitrary
      sort string, which we can then trivially wrap to make the
      parse_opt variant.
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    • Jeff King's avatar
      ref-filter: move need_color_reset_at_eol into ref_format · bf285ae6
      Jeff King authored
      Calling verify_ref_format() doesn't just confirm that the
      format is sane; it actually sets some global variables that
      will be used later when formatting the refs. These logically
      should belong to the ref_format, which would make it
      possible to use multiple formats within a single program
      Let's move one such flag into the ref_format struct. There
      are still others that would need to be moved before it would
      be safe to use multiple formats, but this commit gives a
      blueprint for how that should look.
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    • Jeff King's avatar
      ref-filter: abstract ref format into its own struct · 4a68e36d
      Jeff King authored
      The ref-filter module provides routines for formatting a ref
      for output. The fundamental interface for the format is a
      "const char *" containing the format, and any additional
      options need to be passed to each invocation of
      Instead, let's make a ref_format struct that holds the
      format, along with any associated format options. That will
      make some enhancements easier in the future:
        1. new formatting options can be added without disrupting
           existing callers
        2. some state can be carried in the struct rather than as
           global variables
      For now this just has the text format itself along with the
      quote_style option, but we'll add more fields in future patches.
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  5. 08 May, 2017 1 commit
  6. 31 Mar, 2017 1 commit
    • brian m. carlson's avatar
      Rename sha1_array to oid_array · 910650d2
      brian m. carlson authored
      Since this structure handles an array of object IDs, rename it to struct
      oid_array.  Also rename the accessor functions and the initialization
      This commit was produced mechanically by providing non-Documentation
      files to the following Perl one-liners:
          perl -pi -E 's/struct sha1_array/struct oid_array/g'
          perl -pi -E 's/\bsha1_array_/oid_array_/g'
          perl -pi -E 's/SHA1_ARRAY_INIT/OID_ARRAY_INIT/g'
      Signed-off-by: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  7. 24 Mar, 2017 1 commit
    • Ævar Arnfjörð Bjarmason's avatar
      ref-filter: add --no-contains option to tag/branch/for-each-ref · ac3f5a34
      Ævar Arnfjörð Bjarmason authored
      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: Ævar Arnfjörð Bjarmason's avatarÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  8. 10 Mar, 2017 1 commit
  9. 31 Jan, 2017 1 commit
  10. 18 Jan, 2017 1 commit
  11. 10 Jan, 2017 2 commits
  12. 05 Dec, 2016 1 commit
    • Duy Nguyen's avatar
      tag, branch, for-each-ref: add --ignore-case for sorting and filtering · 3bb16a8b
      Duy Nguyen authored
      This options makes sorting ignore case, which is great when you have
      branches named bug-12-do-something, Bug-12-do-some-more and
      BUG-12-do-what and want to group them together. Sorting externally may
      not be an option because we lose coloring and column layout from
      git-branch and git-tag.
      The same could be said for filtering, but it's probably less important
      because you can always go with the ugly pattern [bB][uU][gG]-* if you're
      You can't have case-sensitive filtering and case-insensitive sorting (or
      the other way around) with this though. For branch and tag, that should
      be no problem. for-each-ref, as a plumbing, might want finer control.
      But we can always add --{filter,sort}-ignore-case when there is a need
      for it.
      Signed-off-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  13. 25 Sep, 2015 2 commits
    • karthik nayak's avatar
      branch.c: use 'ref-filter' APIs · aedcb7dc
      karthik nayak authored
      Make 'branch.c' use 'ref-filter' APIs for iterating through refs
      sorting. This removes most of the code used in 'branch.c' replacing it
      with calls to the 'ref-filter' library.
      Make 'branch.c' use the 'filter_refs()' function provided by 'ref-filter'
      to filter out tags based on the options set.
      We provide a sorting option provided for 'branch.c' by using the
      sorting options provided by 'ref-filter'. Also by default, we sort by
      'refname'.  Since 'HEAD' is alphabatically before 'refs/...' we end up
      with an array consisting of the 'HEAD' ref then the local branches and
      finally the remote-tracking branches.
      Also remove the 'ignore' variable from ref_array_item as it was
      previously used for the '--merged' option and now that is handled by
      Modify some of the tests in t1430 to check the stderr for a warning
      regarding the broken ref. This is done as ref-filter throws a warning
      for broken refs rather than directly printing them.
      Add tests and documentation for the same.
      Mentored-by: Christian Couder's avatarChristian Couder <christian.couder@gmail.com>
      Mentored-by: Matthieu Moy's avatarMatthieu Moy <matthieu.moy@grenoble-inp.fr>
      Signed-off-by: karthik nayak's avatarKarthik Nayak <karthik.188@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    • karthik nayak's avatar
      branch.c: use 'ref-filter' data structures · 1511b22d
      karthik nayak authored
      Make 'branch.c' use 'ref-filter' data structures and make changes to
      support the new data structures. This is a part of the process of
      porting 'branch.c' to use 'ref-filter' APIs.
      This is a temporary step before porting 'branch.c' to use 'ref-filter'
      completely. As this is a temporary step, most of the code introduced
      here will be removed when 'branch.c' is ported over to use
      'ref-filter' APIs.
      Mentored-by: Christian Couder's avatarChristian Couder <christian.couder@gmail.com>
      Mentored-by: Matthieu Moy's avatarMatthieu Moy <matthieu.moy@grenoble-inp.fr>
      Signed-off-by: karthik nayak's avatarKarthik Nayak <karthik.188@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  14. 17 Sep, 2015 5 commits
  15. 03 Aug, 2015 6 commits
  16. 15 Jun, 2015 1 commit