1. 04 10月, 2016 1 次提交
    • J
      abbrev: prepare for new world order · 7b5b7721
      Junio C Hamano 提交于
      The code that sets custom abbreviation length, in response to
      command line argument, often does something like this:
      
      	if (skip_prefix(arg, "--abbrev=", &arg))
      		abbrev = atoi(arg);
      	else if (!strcmp("--abbrev", &arg))
      		abbrev = DEFAULT_ABBREV;
      	/* make the value sane */
      	if (abbrev < 0 || 40 < abbrev)
      		abbrev = ... some sane value ...
      
      However, it is pointless to sanity-check and tweak the value
      obtained from DEFAULT_ABBREV.  We are going to allow it to be
      initially set to -1 to signal that the default abbreviation length
      must be auto sized upon the first request to abbreviate, based on
      the number of objects in the repository, and when that happens,
      rejecting or tweaking a negative value to a "saner" one will
      negatively interfere with the auto sizing.  The codepaths for
      
          git rev-parse --short <object>
          git diff --raw --abbrev
      
      do exactly that; allow them to pass possibly negative abbrevs
      intact, that will come from DEFAULT_ABBREV in the future.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7b5b7721
  2. 09 9月, 2016 3 次提交
  3. 08 9月, 2016 1 次提交
  4. 01 9月, 2016 5 次提交
    • J
      diff: teach diff to display submodule difference with an inline diff · fd47ae6a
      Jacob Keller 提交于
      Teach git-diff and friends a new format for displaying the difference
      of a submodule. The new format is an inline diff of the contents of the
      submodule between the commit range of the update. This allows the user
      to see the actual code change caused by a submodule update.
      
      Add tests for the new format and option.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fd47ae6a
    • J
      submodule: convert show_submodule_summary to use struct object_id * · 602a283a
      Jacob Keller 提交于
      Since we're going to be changing this function in a future patch, lets
      go ahead and convert this to use object_id now.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      602a283a
    • J
      diff: prepare for additional submodule formats · 61cfbc05
      Jacob Keller 提交于
      A future patch will add a new format for displaying the difference of
      a submodule. Make it easier by changing how we store the current
      selected format. Replace the DIFF_OPT flag with an enumeration, as each
      format will be mutually exclusive.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      61cfbc05
    • J
      graph: add support for --line-prefix on all graph-aware output · 660e113c
      Jacob Keller 提交于
      Add an extension to git-diff and git-log (and any other graph-aware
      displayable output) such that "--line-prefix=<string>" will print the
      additional line-prefix on every line of output.
      
      To make this work, we have to fix a few bugs in the graph API that force
      graph_show_commit_msg to be used only when you have a valid graph.
      Additionally, we extend the default_diff_output_prefix handler to work
      even when no graph is enabled.
      
      This is somewhat of a hack on top of the graph API, but I think it
      should be acceptable here.
      
      This will be used by a future extension of submodule display which
      displays the submodule diff as the actual diff between the pre and post
      commit in the submodule project.
      
      Add some tests for both git-log and git-diff to ensure that the prefix
      is honored correctly.
      Signed-off-by: NJacob Keller <jacob.keller@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      660e113c
    • J
      diff.c: remove output_prefix_length field · cd48dadb
      Junio C Hamano 提交于
      "diff/log --stat" has a logic that determines the display columns
      available for the diffstat part of the output and apportions it for
      pathnames and diffstat graph automatically.
      
      5e71a84a (Add output_prefix_length to diff_options, 2012-04-16)
      added the output_prefix_length field to diff_options structure to
      allow this logic to subtract the display columns used for the
      history graph part from the total "terminal width"; this matters
      when the "git log --graph -p" option is in use.
      
      The field must be set to the number of display columns needed to
      show the output from the output_prefix() callback, which is error
      prone.  As there is only one user of the field, and the user has the
      actual value of the prefix string, let's get rid of the field and
      have the user count the display width itself.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cd48dadb
  5. 30 7月, 2016 1 次提交
  6. 23 7月, 2016 1 次提交
    • J
      diff: do not reuse worktree files that need "clean" conversion · 06dec439
      Jeff King 提交于
      When accessing a blob for a diff, we may try to reuse file
      contents in the working tree, under the theory that it is
      faster to mmap those file contents than it would be to
      extract the content from the object database.
      
      When we have to filter those contents, though, that
      assumption does not hold. Even for our internal conversions
      like CRLF, we have to allocate and fill a new buffer anyway.
      But much worse, for external clean filters we have to exec
      an arbitrary script, and we have no idea how expensive it
      may be to run.
      
      So let's skip this optimization when conversion into git's
      "clean" form is required. This applies whenever the
      "want_file" flag is false. When it's true, the caller
      actually wants the smudged worktree contents, which the
      reused file by definition already has (in fact, this is a
      key optimization going the other direction, since reusing
      the worktree file there lets us skip smudge filters).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      06dec439
  7. 29 6月, 2016 5 次提交
  8. 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
  9. 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
  10. 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
  11. 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
  12. 22 1月, 2016 1 次提交
  13. 23 10月, 2015 1 次提交
  14. 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
  15. 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
  16. 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
  17. 20 8月, 2015 1 次提交
  18. 13 8月, 2015 1 次提交
  19. 13 7月, 2015 1 次提交
  20. 10 7月, 2015 1 次提交
  21. 28 5月, 2015 2 次提交
  22. 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
  23. 06 3月, 2015 1 次提交
  24. 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
  25. 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
  26. 21 8月, 2014 1 次提交