1. 20 11月, 2015 2 次提交
  2. 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
  3. 23 2月, 2015 1 次提交
  4. 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
  5. 08 10月, 2014 1 次提交
  6. 19 9月, 2014 1 次提交
  7. 09 9月, 2014 1 次提交
  8. 30 8月, 2014 1 次提交
  9. 28 8月, 2014 1 次提交
    • J
      commit: provide a function to find a header in a buffer · fe6eb7f2
      Jeff King 提交于
      Usually when we parse a commit, we read it line by line and
      handle each individual line (e.g., parse_commit and
      parse_commit_header).  Sometimes, however, we only care
      about extracting a single header. Code in this situation is
      stuck doing an ad-hoc parse of the commit buffer.
      
      Let's provide a reusable function to locate a header within
      the commit.  The code is modeled after pretty.c's
      get_header, which is used to extract the encoding.
      
      Since some callers may not have the "struct commit" to go
      along with the buffer, we drop that parameter.  The only
      thing lost is a warning for truncated commits, but that's
      OK.  This shouldn't happen in practice, and even if it does,
      there's no particular reason that this function needs to
      complain about it. It either finds the header it was asked
      for, or it doesn't (and in the latter case, the caller will
      typically complain).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fe6eb7f2
  10. 05 8月, 2014 1 次提交
  11. 31 7月, 2014 2 次提交
    • J
      pretty: make empty userformats truly empty · b9c7d6e4
      Jeff King 提交于
      If the user provides an empty format with "--format=", we
      end up putting in extra whitespace that the user cannot
      prevent. This comes from two places:
      
        1. If the format is missing a terminating newline, we add
           one automatically. This makes sense for --format=%h, but
           not for a truly empty format.
      
        2. We add an extra newline between the pretty-printed
           format and a diff or diffstat. If the format is empty,
           there's no point in doing so if there's nothing to
           separate.
      
      With this patch, one can get a diff with no other cruft out
      of "diff-tree --format= $commit".
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b9c7d6e4
    • J
      pretty: treat "--format=" as an empty userformat · c75e7ad2
      Jeff King 提交于
      Until now, we treated "--pretty=" or "--format=" as "give me
      the default format". This was not planned nor documented,
      but only what happened to work due to our parsing of
      "--pretty" (which should give the default format).
      
      Let's instead let these be an actual empty userformat.
      Otherwise one must write out the annoyingly long
      "--pretty=tformat:" to get the same behavior.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c75e7ad2
  12. 18 7月, 2014 1 次提交
  13. 11 7月, 2014 1 次提交
  14. 03 7月, 2014 1 次提交
  15. 24 6月, 2014 1 次提交
  16. 21 6月, 2014 1 次提交
    • J
      use skip_prefix to avoid repeating strings · 95b567c7
      Jeff King 提交于
      It's a common idiom to match a prefix and then skip past it
      with strlen, like:
      
        if (starts_with(foo, "bar"))
      	  foo += strlen("bar");
      
      This avoids magic numbers, but means we have to repeat the
      string (and there is no compiler check that we didn't make a
      typo in one of the strings).
      
      We can use skip_prefix to handle this case without repeating
      ourselves.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      95b567c7
  17. 18 6月, 2014 1 次提交
    • J
      pretty: avoid reading past end-of-string with "%G" · aa4b78d4
      Jeff King 提交于
      If the user asks for --format=%G with nothing else, we
      correctly realize that "%G" is not a valid placeholder (it
      should be "%G?", "%GK", etc). But we still tell the
      strbuf_expand code that we consumed 2 characters, causing it
      to jump over the trailing NUL and output garbage.
      
      This also fixes the case where "%GX" would be consumed (and
      produce no output). In other cases, we pass unrecognized
      placeholders through to the final string.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      aa4b78d4
  18. 14 6月, 2014 2 次提交
    • J
      commit: record buffer length in cache · 8597ea3a
      Jeff King 提交于
      Most callsites which use the commit buffer try to use the
      cached version attached to the commit, rather than
      re-reading from disk. Unfortunately, that interface provides
      only a pointer to the NUL-terminated buffer, with no
      indication of the original length.
      
      For the most part, this doesn't matter. People do not put
      NULs in their commit messages, and the log code is happy to
      treat it all as a NUL-terminated string. However, some code
      paths do care. For example, when checking signatures, we
      want to be very careful that we verify all the bytes to
      avoid malicious trickery.
      
      This patch just adds an optional "size" out-pointer to
      get_commit_buffer and friends. The existing callers all pass
      NULL (there did not seem to be any obvious sites where we
      could avoid an immediate strlen() call, though perhaps with
      some further refactoring we could).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8597ea3a
    • J
      convert logmsg_reencode to get_commit_buffer · b66103c3
      Jeff King 提交于
      Like the callsites in the previous commit, logmsg_reencode
      already falls back to read_sha1_file when necessary.
      However, I split its conversion out into its own commit
      because it's a bit more complex.
      
      We return either:
      
        1. The original commit->buffer
      
        2. A newly allocated buffer from read_sha1_file
      
        3. A reencoded buffer (based on either 1 or 2 above).
      
      while trying to do as few extra reads/allocations as
      possible. Callers currently free the result with
      logmsg_free, but we can simplify this by pointing them
      straight to unuse_commit_buffer. This is a slight layering
      violation, in that we may be passing a buffer from (3).
      However, since the end result is to free() anything except
      (1), which is unlikely to change, and because this makes the
      interface much simpler, it's a reasonable bending of the
      rules.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b66103c3
  19. 13 6月, 2014 1 次提交
    • J
      logmsg_reencode: return const buffer · b000c59b
      Jeff King 提交于
      The return value from logmsg_reencode may be either a newly
      allocated buffer or a pointer to the existing commit->buffer.
      We would not want the caller to accidentally free() or
      modify the latter, so let's mark it as const.  We can cast
      away the constness in logmsg_free, but only once we have
      determined that it is a free-able buffer.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b000c59b
  20. 22 5月, 2014 1 次提交
    • A
      pretty.c: format string with truncate respects logOutputEncoding · 7d509878
      Alexey Shumkin 提交于
      Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given
      length with an appropriate padding. This works for non-ASCII texts when
      i18n.logOutputEncoding is UTF-8 only (independently of a printed commit
      message encoding) but does not work when i18n.logOutputEncoding is NOT
      UTF-8.
      
      In 7e77df39 (pretty: two phase conversion for non utf-8 commits, 2013-04-19)
      'format_commit_item' function assumes commit message to be in UTF-8.
      And that was so until ecaee805 (pretty: --format output should honor
      logOutputEncoding, 2013-06-26) where conversion to logOutputEncoding was
      added before calling 'format_commit_message'.
      
      Correct this by converting a commit message to UTF-8 first (as it
      assumed in 7e77df39 (pretty: two phase conversion for non utf-8 commits,
      2013-04-19)). Only after that convert a commit message to an actual
      logOutputEncoding.
      Signed-off-by: NAlexey Shumkin <Alex.Crezoff@gmail.com>
      Reviewed-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7d509878
  21. 03 5月, 2014 1 次提交
  22. 10 3月, 2014 1 次提交
  23. 08 3月, 2014 1 次提交
    • J
      show_ident_date: fix tz range check · 3f419d45
      Jeff King 提交于
      Commit 1dca155f (log: handle integer overflow in
      timestamps, 2014-02-24) tried to catch integer overflow
      coming from strtol() on the timezone field by comparing against
      LONG_MIN/LONG_MAX. However, the intermediate "tz" variable
      is an "int", which means it can never be LONG_MAX on LP64
      systems; we would truncate the output from strtol before the
      comparison.
      
      Clang's -Wtautological-constant-out-of-range-compare notices
      this and rightly complains.
      
      Let's instead store the result of strtol in a long, and then
      compare it against INT_MIN/INT_MAX. This will catch overflow
      from strtol, and also overflow when we pass the result as an
      int to show_date.
      Reported-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3f419d45
  24. 25 2月, 2014 1 次提交
    • J
      log: handle integer overflow in timestamps · 1dca155f
      Jeff King 提交于
      If an ident line has a ridiculous date value like (2^64)+1,
      we currently just pass ULONG_MAX along to the date code,
      which can produce nonsensical dates.
      
      On systems with a signed long time_t (e.g., 64-bit glibc
      systems), this actually doesn't end up too bad. The
      ULONG_MAX is converted to -1, we apply the timezone field to
      that, and the result ends up somewhere between Dec 31, 1969
      and Jan 1, 1970.
      
      However, there is still a few good reasons to detect the
      overflow explicitly:
      
        1. On systems where "unsigned long" is smaller than
           time_t, we get a nonsensical date in the future.
      
        2. Even where it would produce "Dec 31, 1969", it's easier
           to recognize "midnight Jan 1" as a consistent sentinel
           value for "we could not parse this".
      
        3.  Values which do not overflow strtoul but do overflow a
            signed time_t produce nonsensical values in the past.
            For example, on a 64-bit system with a signed long
            time_t, a timestamp of 18446744073000000000 produces a
            date in 1947.
      
      We also recognize overflow in the timezone field, which
      could produce nonsensical results. In this case we show the
      parsed date, but in UTC.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1dca155f
  25. 06 12月, 2013 1 次提交
    • C
      replace {pre,suf}fixcmp() with {starts,ends}_with() · 59556548
      Christian Couder 提交于
      Leaving only the function definitions and declarations so that any
      new topic in flight can still make use of the old functions, replace
      existing uses of the prefixcmp() and suffixcmp() with new API
      functions.
      
      The change can be recreated by mechanically applying this:
      
          $ git grep -l -e prefixcmp -e suffixcmp -- \*.c |
            grep -v strbuf\\.c |
            xargs perl -pi -e '
              s|!prefixcmp\(|starts_with\(|g;
              s|prefixcmp\(|!starts_with\(|g;
              s|!suffixcmp\(|ends_with\(|g;
              s|suffixcmp\(|!ends_with\(|g;
            '
      
      on the result of preparatory changes in this series.
      Signed-off-by: NChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      59556548
  26. 01 11月, 2013 1 次提交
  27. 21 9月, 2013 1 次提交
    • J
      format-patch: print in-body "From" only when needed · 662cc30c
      Jeff King 提交于
      Commit a9080475 taught format-patch the "--from" option,
      which places the author ident into an in-body from header,
      and uses the committer ident in the rfc822 from header.  The
      documentation claims that it will omit the in-body header
      when it is the same as the rfc822 header, but the code never
      implemented that behavior.
      
      This patch completes the feature by comparing the two idents
      and doing nothing when they are the same (this is the same
      as simply omitting the in-body header, as the two are by
      definition indistinguishable in this case). This makes it
      reasonable to turn on "--from" all the time (if it matches
      your particular workflow), rather than only using it when
      exporting other people's patches.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      662cc30c
  28. 04 7月, 2013 2 次提交
    • J
      teach format-patch to place other authors into in-body "From" · a9080475
      Jeff King 提交于
      Format-patch generates emails with the "From" address set to the
      author of each patch. If you are going to send the emails, however,
      you would want to replace the author identity with yours (if they
      are not the same), and bump the author identity to an in-body
      header.
      
      Normally this is handled by git-send-email, which does the
      transformation before sending out the emails. However, some
      workflows may not use send-email (e.g., imap-send, or a custom
      script which feeds the mbox to a non-git MUA). They could each
      implement this feature themselves, but getting it right is
      non-trivial (one must canonicalize the identities by reversing any
      RFC2047 encoding or RFC822 quoting of the headers, which has caused
      many bugs in send-email over the years).
      
      This patch takes a different approach: it teaches format-patch a
      "--from" option which handles the ident check and in-body header
      while it is writing out the email.  It's much simpler to do at this
      level (because we haven't done any quoting yet), and any workflow
      based on format-patch can easily turn it on.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a9080475
    • J
      pretty.c: drop const-ness from pretty_print_context · 10f2fbff
      Jeff King 提交于
      In the current code, callers are expected to fill in the
      pretty_print_context, and then the pretty.c functions simply
      read from it. This leaves no room for the pretty.c functions
      to communicate with each other by manipulating the context
      (e.g., data seen while printing the header may impact how we
      print the body).
      
      Rather than introduce a new struct to hold modifiable data,
      let's just drop the const-ness of the existing context
      struct.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      10f2fbff
  29. 26 4月, 2013 3 次提交
  30. 19 4月, 2013 5 次提交