1. 29 6月, 2016 1 次提交
    • J
      diff: do not color output when --color=auto and --output=<file> is given · afc676f2
      Johannes Schindelin 提交于
      "git diff --output=<file> --color=auto" used to show the ANSI color
      sequence in the resulting file when the standard output is connected
      to a terminal, because --color=auto check always checks the standard
      output, not the actual file that receives the output.
      
      We could correct this by using freopen(3) to redirect the standard
      output to the specified file, which is in like with how format-patch
      used to match the world order, but following the same reasoning as
      the earlier "format-patch: explicitly switch off color when writing
      to files", let's be more strict by bypassing the "auto" check when
      the --output=<file> option is in use.
      
      Strictly speaking, this is a backwards-incompatible change, but
      it is highly unlikely that any user would want to see ANSI color
      sequences in a file.
      
      The reason this was not caught earlier is most likely that either
      --output=<file> is not used, or only when stdout is redirected
      anyway.
      
      Users can still give --color=always if they want a colored diff in
      the resulting file.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      afc676f2
  2. 11 6月, 2016 1 次提交
    • J
      diff: disable compaction heuristic for now · 5580b271
      Junio C Hamano 提交于
      http://lkml.kernel.org/g/20160610075043.GA13411@sigill.intra.peff.net
      reports that a change to add a new "function" with common ending
      with the existing one at the end of the file is shown like this:
      
          def foo
            do_foo_stuff()
      
         +  common_ending()
         +end
         +
         +def bar
         +  do_bar_stuff()
         +
            common_ending()
          end
      
      when the new heuristic is in use.  In reality, the change is to add
      the blank line before "def bar" and everything below, which is what
      the code without the new heuristic shows.
      
      Disable the heuristics by default, and resurrect the documentation
      for the option and the configuration variables, while clearly
      marking the feature as still experimental.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5580b271
  3. 20 4月, 2016 1 次提交
    • S
      xdiff: implement empty line chunk heuristic · d634d61e
      Stefan Beller 提交于
      In order to produce the smallest possible diff and combine several diff
      hunks together, we implement a heuristic from GNU Diff which moves diff
      hunks forward as far as possible when we find common context above and
      below a diff hunk. This sometimes produces less readable diffs when
      writing C, Shell, or other programming languages, ie:
      
      ...
       /*
      + *
      + *
      + */
      +
      +/*
      ...
      
      instead of the more readable equivalent of
      
      ...
      +/*
      + *
      + *
      + */
      +
       /*
      ...
      
      Implement the following heuristic to (optionally) produce the desired
      output.
      
        If there are diff chunks which can be shifted around, shift each hunk
        such that the last common empty line is below the chunk with the rest
        of the context above.
      
      This heuristic appears to resolve the above example and several other
      common issues without producing significantly weird results. However, as
      with any heuristic it is not really known whether this will always be
      more optimal. Thus, it can be disabled via diff.compactionHeuristic.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d634d61e
  4. 26 2月, 2016 1 次提交
    • M
      diff: activate diff.renames by default · 5404c116
      Matthieu Moy 提交于
      Rename detection is a very convenient feature, and new users shouldn't
      have to dig in the documentation to benefit from it.
      
      Potential objections to activating rename detection are that it
      sometimes fail, and it is sometimes slow. But rename detection is
      already activated by default in several cases like "git status" and "git
      merge", so activating diff.renames does not fundamentally change the
      situation. When the rename detection fails, it now fails consistently
      between "git diff" and "git status".
      
      This setting does not affect plumbing commands, hence well-written
      scripts will not be affected.
      Signed-off-by: NMatthieu Moy <Matthieu.Moy@imag.fr>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5404c116
  5. 23 2月, 2016 3 次提交
    • J
      diff_populate_gitlink: use a strbuf · b1ddfb91
      Jeff King 提交于
      We allocate 100 bytes to hold the "Submodule commit ..."
      text. This is enough, but it's not immediately obvious that
      this is the case, and we have to repeat the magic 100 twice.
      
      We could get away with xstrfmt here, but we want to know the
      size, as well, so let's use a real strbuf. And while we're
      here, we can clean up the logic around size_only. It
      currently sets and clears the "data" field pointlessly, and
      leaves the "should_free" flag on even after we have cleared
      the data.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b1ddfb91
    • J
      convert trivial cases to FLEX_ARRAY macros · 96ffc06f
      Jeff King 提交于
      Using FLEX_ARRAY macros reduces the amount of manual
      computation size we have to do. It also ensures we don't
      overflow size_t, and it makes sure we write the same number
      of bytes that we allocated.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      96ffc06f
    • J
      diff: clarify textconv interface · a64e6a44
      Jeff King 提交于
      The memory allocation scheme for the textconv interface is a
      bit tricky, and not well documented. It was originally
      designed as an internal part of diff.c (matching
      fill_mmfile), but gradually was made public.
      
      Refactoring it is difficult, but we can at least improve the
      situation by documenting the intended flow and enforcing it
      with an in-code assertion.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a64e6a44
  6. 22 1月, 2016 1 次提交
  7. 23 10月, 2015 1 次提交
  8. 06 10月, 2015 1 次提交
    • J
      use sha1_to_hex_r() instead of strcpy · d59f765a
      Jeff King 提交于
      Before sha1_to_hex_r() existed, a simple way to get hex
      sha1 into a buffer was with:
      
        strcpy(buf, sha1_to_hex(sha1));
      
      This isn't wrong (assuming the buf is 41 characters), but it
      makes auditing the code base for bad strcpy() calls harder,
      as these become false positives.
      
      Let's convert them to sha1_to_hex_r(), and likewise for
      some calls to find_unique_abbrev(). While we're here, we'll
      double-check that all of the buffers are correctly sized,
      and use the more obvious GIT_SHA1_HEXSZ constant.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d59f765a
  9. 29 9月, 2015 1 次提交
    • J
      react to errors in xdi_diff · 3efb9880
      Jeff King 提交于
      When we call into xdiff to perform a diff, we generally lose
      the return code completely. Typically by ignoring the return
      of our xdi_diff wrapper, but sometimes we even propagate
      that return value up and then ignore it later.  This can
      lead to us silently producing incorrect diffs (e.g., "git
      log" might produce no output at all, not even a diff header,
      for a content-level diff).
      
      In practice this does not happen very often, because the
      typical reason for xdiff to report failure is that it
      malloc() failed (it uses straight malloc, and not our
      xmalloc wrapper).  But it could also happen when xdiff
      triggers one our callbacks, which returns an error (e.g.,
      outf() in builtin/rerere.c tries to report a write failure
      in this way). And the next patch also plans to add more
      failure modes.
      
      Let's notice an error return from xdiff and react
      appropriately. In most of the diff.c code, we can simply
      die(), which matches the surrounding code (e.g., that is
      what we do if we fail to load a file for diffing in the
      first place). This is not that elegant, but we are probably
      better off dying to let the user know there was a problem,
      rather than simply generating bogus output.
      
      We could also just die() directly in xdi_diff, but the
      callers typically have a bit more context, and can provide a
      better message (and if we do later decide to pass errors up,
      we're one step closer to doing so).
      
      There is one interesting case, which is in diff_grep(). Here
      if we cannot generate the diff, there is nothing to match,
      and we silently return "no hits". This is actually what the
      existing code does already, but we make it a little more
      explicit.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3efb9880
  10. 26 9月, 2015 1 次提交
    • J
      convert trivial sprintf / strcpy calls to xsnprintf · 5096d490
      Jeff King 提交于
      We sometimes sprintf into fixed-size buffers when we know
      that the buffer is large enough to fit the input (either
      because it's a constant, or because it's numeric input that
      is bounded in size). Likewise with strcpy of constant
      strings.
      
      However, these sites make it hard to audit sprintf and
      strcpy calls for buffer overflows, as a reader has to
      cross-reference the size of the array with the input. Let's
      use xsnprintf instead, which communicates to a reader that
      we don't expect this to overflow (and catches the mistake in
      case we do).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5096d490
  11. 20 8月, 2015 1 次提交
  12. 13 8月, 2015 1 次提交
  13. 13 7月, 2015 1 次提交
  14. 10 7月, 2015 1 次提交
  15. 28 5月, 2015 2 次提交
  16. 27 5月, 2015 2 次提交
    • J
      diff.c: --ws-error-highlight=<kind> option · b8767f79
      Junio C Hamano 提交于
      Traditionally, we only cared about whitespace breakages introduced
      in new lines.  Some people want to paint whitespace breakages on old
      lines, too.  When they see a whitespace breakage on a new line, they
      can spot the same kind of whitespace breakage on the corresponding
      old line and want to say "Ah, those breakages are there but they
      were inherited from the original, so let's not touch them for now."
      
      Introduce `--ws-error-highlight=<kind>` option, that lets them pass
      a comma separated list of `old`, `new`, and `context` to specify
      what lines to highlight whitespace errors on.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b8767f79
    • J
      diff.c: add emit_del_line() and emit_context_line() · 0e383e18
      Junio C Hamano 提交于
      Traditionally, we only had emit_add_line() helper, which knows how
      to find and paint whitespace breakages on the given line, because we
      only care about whitespace breakages introduced in new lines.  The
      context lines and old (i.e. deleted) lines are emitted with a
      simpler emit_line_0() that paints the entire line in plain or old
      colors.
      
      Identify callers of emit_line_0() that show deleted lines and
      context lines, have them call new helpers, emit_del_line() and
      emit_context_line(), so that we can later tweak what is done to
      these two classes of lines.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0e383e18
  17. 06 3月, 2015 1 次提交
  18. 03 3月, 2015 1 次提交
    • M
      diff --shortstat --dirstat: remove duplicate output · ab27389a
      Mårten Kongstad 提交于
      When --shortstat is used in conjunction with --dirstat=changes, git diff will
      output the dirstat information twice: first as calculated by the 'lines'
      algorithm, then as calculated by the 'changes' algorithm:
      
          $ git diff --dirstat=changes,10 --shortstat v2.2.0..v2.2.1
           23 files changed, 453 insertions(+), 54 deletions(-)
            33.5% Documentation/RelNotes/
            26.2% t/
            46.6% Documentation/RelNotes/
            16.6% t/
      
      The same duplication happens for --shortstat together with --dirstat=files, but
      not for --shortstat together with --dirstat=lines.
      
      Limit output to only include one dirstat part, calculated as specified
      by the --dirstat parameter. Also, add test for this.
      Signed-off-by: NMårten Kongstad <marten.kongstad@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ab27389a
  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. 21 8月, 2014 1 次提交
  21. 19 8月, 2014 3 次提交
  22. 18 7月, 2014 1 次提交
  23. 21 6月, 2014 3 次提交
    • J
      stat_opt: check extra strlen call · 0539cc00
      Jeff King 提交于
      As in earlier commits, the diff option parser uses
      starts_with to find that an argument starts with "--stat-",
      and then adds strlen("stat-") to find the rest of the
      option.
      
      However, in this case the starts_with and the strlen are
      separated across functions, making it easy to call the
      latter without the former. Let's use skip_prefix instead of
      raw pointer arithmetic to catch such a case.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0539cc00
    • 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
    • J
      use skip_prefix to avoid magic numbers · ae021d87
      Jeff King 提交于
      It's a common idiom to match a prefix and then skip past it
      with a magic number, like:
      
        if (starts_with(foo, "bar"))
      	  foo += 3;
      
      This is easy to get wrong, since you have to count the
      prefix string yourself, and there's no compiler check if the
      string changes.  We can use skip_prefix to avoid the magic
      numbers here.
      
      Note that some of these conversions could be much shorter.
      For example:
      
        if (starts_with(arg, "--foo=")) {
      	  bar = arg + 6;
      	  continue;
        }
      
      could become:
      
        if (skip_prefix(arg, "--foo=", &bar))
      	  continue;
      
      However, I have left it as:
      
        if (skip_prefix(arg, "--foo=", &v)) {
      	  bar = v;
      	  continue;
        }
      
      to visually match nearby cases which need to actually
      process the string. Like:
      
        if (skip_prefix(arg, "--foo=", &v)) {
      	  bar = atoi(v);
      	  continue;
        }
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ae021d87
  24. 19 6月, 2014 1 次提交
    • J
      parse_diff_color_slot: drop ofs parameter · 9e1a5ebe
      Jeff King 提交于
      This function originally took a whole config variable name
      ("var") and an offset ("ofs"). It checked "var+ofs" against
      each color slot, but reported errors using the whole "var".
      
      However, since 8b8e8624 (ignore unknown color configuration,
      2009-12-12), it returns -1 rather than printing its own
      error, and therefore only cares about var+ofs. We can drop
      the ofs parameter and teach its sole caller to derive the
      pointer itself.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9e1a5ebe
  25. 28 5月, 2014 1 次提交
  26. 21 5月, 2014 1 次提交
  27. 22 4月, 2014 6 次提交