1. 14 7月, 2017 2 次提交
    • J
      for-each-ref: load config earlier · d8b68686
      Jeff King 提交于
      In most commands we load config before parsing command line
      options, since it lets the latter override the former with a
      simple variable assignment. In the case of for-each-ref,
      though, we do it in the reverse order. This is OK with
      the current code, since there's no interaction between the
      config and command-line options.
      
      However, as the ref-filter code starts to care about config
      during verify_ref_format(), we'll want to make sure the
      config is loaded. Let's bump the config to the usual spot
      near the top of the function.
      
      We can drop the comment there; it's impossible to keep a
      "why we load the config" comment like this up to date with
      every config option we might be interested in. And indeed,
      it's already stale; we'd care about core.abbrev, for
      instance, when %(objectname:short) is used.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d8b68686
    • J
      ref-filter: abstract ref format into its own struct · 4a68e36d
      Jeff King 提交于
      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
      show_ref_array_item.
      
      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: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4a68e36d
  2. 16 6月, 2017 1 次提交
  3. 25 3月, 2017 1 次提交
    • Æ
      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
  4. 24 3月, 2017 1 次提交
  5. 06 12月, 2016 1 次提交
    • N
      tag, branch, for-each-ref: add --ignore-case for sorting and filtering · 3bb16a8b
      Nguyễn Thái Ngọc Duy 提交于
      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
      desperate.
      
      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: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3bb16a8b
  6. 18 9月, 2015 1 次提交
  7. 04 8月, 2015 5 次提交
  8. 30 6月, 2015 1 次提交
    • J
      convert "enum date_mode" into a struct · a5481a6c
      Jeff King 提交于
      In preparation for adding date modes that may carry extra
      information beyond the mode itself, this patch converts the
      date_mode enum into a struct.
      
      Most of the conversion is fairly straightforward; we pass
      the struct as a pointer and dereference the type field where
      necessary. Locations that declare a date_mode can use a "{}"
      constructor.  However, the tricky case is where we use the
      enum labels as constants, like:
      
        show_date(t, tz, DATE_NORMAL);
      
      Ideally we could say:
      
        show_date(t, tz, &{ DATE_NORMAL });
      
      but of course C does not allow that. Likewise, we cannot
      cast the constant to a struct, because we need to pass an
      actual address. Our options are basically:
      
        1. Manually add a "struct date_mode d = { DATE_NORMAL }"
           definition to each caller, and pass "&d". This makes
           the callers uglier, because they sometimes do not even
           have their own scope (e.g., they are inside a switch
           statement).
      
        2. Provide a pre-made global "date_normal" struct that can
           be passed by address. We'd also need "date_rfc2822",
           "date_iso8601", and so forth. But at least the ugliness
           is defined in one place.
      
        3. Provide a wrapper that generates the correct struct on
           the fly. The big downside is that we end up pointing to
           a single global, which makes our wrapper non-reentrant.
           But show_date is already not reentrant, so it does not
           matter.
      
      This patch implements 3, along with a minor macro to keep
      the size of the callers sane.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a5481a6c
  9. 16 6月, 2015 8 次提交
  10. 03 6月, 2015 1 次提交
    • M
      for-each-ref: report broken references correctly · 8afc493d
      Michael Haggerty 提交于
      If there is a loose reference file with invalid contents, "git
      for-each-ref" incorrectly reports the problem as being a missing
      object with name NULL_SHA1:
      
          $ echo '12345678' >.git/refs/heads/nonsense
          $ git for-each-ref
          fatal: missing object 0000000000000000000000000000000000000000 for refs/heads/nonsense
      
      With an explicit "--format" string, it can even report that the
      reference validly points at NULL_SHA1:
      
          $ git for-each-ref --format='%(objectname) %(refname)'
          0000000000000000000000000000000000000000 refs/heads/nonsense
          $ echo $?
          0
      
      This has been broken since
      
          b7dd2d20 for-each-ref: Do not lookup objects when they will not be used (2009-05-27)
      
      , which changed for-each-ref from using for_each_ref() to using
      git_for_each_rawref() in order to avoid looking up the referred-to
      objects unnecessarily. (When "git for-each-ref" is given a "--format"
      string that doesn't include information about the pointed-to object,
      it does not look up the object at all, which makes it considerably
      faster. Iterating with DO_FOR_EACH_INCLUDE_BROKEN is essential to this
      optimization because otherwise for_each_ref() would itself need to
      check whether the object exists as part of its brokenness test.)
      
      But for_each_rawref() includes broken references in the iteration, and
      "git for-each-ref" doesn't itself reject references with REF_ISBROKEN.
      The result is that broken references are processed *as if* they had
      the value NULL_SHA1, which is the value stored in entries for broken
      references.
      
      Change "git for-each-ref" to emit warnings for references that are
      REF_ISBROKEN but to otherwise skip them.
      Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8afc493d
  11. 26 5月, 2015 2 次提交
  12. 23 5月, 2015 3 次提交
    • J
      for-each-ref: accept "%(push)" format · 29bc8850
      Jeff King 提交于
      Just as we have "%(upstream)" to report the "@{upstream}"
      for each ref, this patch adds "%(push)" to match "@{push}".
      It supports the same tracking format modifiers as upstream
      (because you may want to know, for example, which branches
      have commits to push).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      29bc8850
    • J
      for-each-ref: use skip_prefix instead of starts_with · 3dbe9db0
      Jeff King 提交于
      This saves us having to maintain a magic number to skip past
      the matched prefix.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3dbe9db0
    • J
      remote.c: return upstream name from stat_tracking_info · 979cb245
      Jeff King 提交于
      After calling stat_tracking_info, callers often want to
      print the name of the upstream branch (in addition to the
      tracking count). To do this, they have to access
      branch->merge->dst[0] themselves. This is not wrong, as the
      return value from stat_tracking_info tells us whether we
      have an upstream branch or not. But it is a bit leaky, as we
      make an assumption about how it calculated the upstream
      name.
      
      Instead, let's add an out-parameter that lets the caller
      know the upstream name we found.
      
      As a bonus, we can get rid of the unusual tri-state return
      from the function. We no longer need to use it to
      differentiate between "no tracking config" and "tracking ref
      does not exist" (since you can check the upstream_name for
      that), so we can just use the usual 0/-1 convention for
      success/error.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      979cb245
  13. 22 5月, 2015 2 次提交
    • J
      remote.c: report specific errors from branch_get_upstream · 3a429d0a
      Jeff King 提交于
      When the previous commit introduced the branch_get_upstream
      helper, there was one call-site that could not be converted:
      the one in sha1_name.c, which gives detailed error messages
      for each possible failure.
      
      Let's teach the helper to optionally report these specific
      errors. This lets us convert another callsite, and means we
      can use the helper in other locations that want to give the
      same error messages.
      
      The logic and error messages come straight from sha1_name.c,
      with the exception that we start each error with a lowercase
      letter, as is our usual style (note that a few tests need
      updated as a result).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3a429d0a
    • J
      remote.c: introduce branch_get_upstream helper · a9f9f8cc
      Jeff King 提交于
      All of the information needed to find the @{upstream} of a
      branch is included in the branch struct, but callers have to
      navigate a series of possible-NULL values to get there.
      Let's wrap that logic up in an easy-to-read helper.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a9f9f8cc
  14. 23 2月, 2015 1 次提交
  15. 15 1月, 2015 1 次提交
  16. 13 1月, 2015 1 次提交
    • R
      for-each-ref: always check stat_tracking_info()'s return value · b6160d95
      Raphael Kubo da Costa 提交于
      The code handling %(upstream:track) and %(upstream:trackshort)
      assumed that it always had a valid branch that had been sanitized
      earlier in populate_value(), and thus did not check the return value
      of the call to stat_tracking_info().
      
      While there is indeed some sanitization code that basically
      corresponds to stat_tracking_info() returning 0 (no base branch
      set), the function can also return -1 when the base branch did exist
      but has since then been deleted.
      
      In this case, num_ours and num_theirs had undefined values and a
      call to `git for-each-ref --format="%(upstream:track)"` could print
      spurious values such as
      
        [behind -111794512]
        [ahead 38881640, behind 5103867]
      
      even for repositories with one single commit.
      
      Verify stat_tracking_info()'s return value and do not print anything
      if it returns -1. This behavior also matches the documentation ("has
      no effect if the ref does not have tracking information associated
      with it").
      Helped-by: NEric Sunshine <sunshine@sunshineco.com>
      Helped-by: NJeff King <peff@peff.net>
      Signed-off-by: NRaphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b6160d95
  17. 01 12月, 2014 1 次提交
  18. 16 10月, 2014 2 次提交
  19. 15 10月, 2014 1 次提交
    • J
      color_parse: do not mention variable name in error message · f6c5a296
      Jeff King 提交于
      Originally the color-parsing function was used only for
      config variables. It made sense to pass the variable name so
      that the die() message could be something like:
      
        $ git -c color.branch.plain=bogus branch
        fatal: bad color value 'bogus' for variable 'color.branch.plain'
      
      These days we call it in other contexts, and the resulting
      error messages are a little confusing:
      
        $ git log --pretty='%C(bogus)'
        fatal: bad color value 'bogus' for variable '--pretty format'
      
        $ git config --get-color foo.bar bogus
        fatal: bad color value 'bogus' for variable 'command line'
      
      This patch teaches color_parse to complain only about the
      value, and then return an error code. Config callers can
      then propagate that up to the config parser, which mentions
      the variable name. Other callers can provide a custom
      message. After this patch these three cases now look like:
      
        $ git -c color.branch.plain=bogus branch
        error: invalid color value: bogus
        fatal: unable to parse 'color.branch.plain' from command-line config
      
        $ git log --pretty='%C(bogus)'
        error: invalid color value: bogus
        fatal: unable to parse --pretty format
      
        $ git config --get-color foo.bar bogus
        error: invalid color value: bogus
        fatal: unable to parse default color value
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f6c5a296
  20. 19 9月, 2014 1 次提交
  21. 04 9月, 2014 1 次提交
  22. 18 7月, 2014 1 次提交
  23. 10 6月, 2014 1 次提交