1. 05 Nov, 2018 2 commits
    • Jeff King's avatar
      xdiff-interface: drop parse_hunk_header() · 5eade074
      Jeff King authored
      This function was used only for parsing the hunk headers generated by
      xdiff. Now that we can use hunk callbacks to get that information
      directly, it has outlived its usefulness.
      Note to anyone who wants to resurrect it: the "len" parameter was
      totally unused, meaning that the function could read past the end of the
      "line" array. In practice this never happened, because we only used it
      to parse xdiff's generated header lines. But it would be dangerous to
      use it for other cases without fixing this defect.
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    • Jeff King's avatar
      diff: avoid generating unused hunk header lines · 3b40a090
      Jeff King authored
      Some callers of xdi_diff_outf() do not look at the generated hunk header
      lines at all. By plugging in a no-op hunk callback, this tells xdiff not
      to even bother formatting them.
      This patch introduces a stock no-op callback and uses it with a few
      callers whose line callbacks explicitly ignore hunk headers (because
      they look only for +/- lines).
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  2. 02 Nov, 2018 1 commit
    • Jeff King's avatar
      xdiff-interface: provide a separate consume callback for hunks · 9346d6d1
      Jeff King authored
      The previous commit taught xdiff to optionally provide the hunk header
      data to a specialized callback. But most users of xdiff actually use our
      more convenient xdi_diff_outf() helper, which ensures that our callbacks
      are always fed whole lines.
      Let's plumb the special hunk-callback through this interface, too. It
      will follow the same rule as xdiff when the hunk callback is NULL (i.e.,
      continue to pass a stringified hunk header to the line callback). Since
      we add NULL to each caller, there should be no behavior change yet.
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  3. 26 Oct, 2017 1 commit
  4. 07 Sep, 2016 1 commit
  5. 28 Sep, 2015 1 commit
    • Jeff King's avatar
      xdiff: reject files larger than ~1GB · dcd1742e
      Jeff King authored
      The xdiff code is not prepared to handle extremely large
      files. It uses "int" in many places, which can overflow if
      we have a very large number of lines or even bytes in our
      input files. This can cause us to produce incorrect diffs,
      with no indication that the output is wrong. Or worse, we
      may even underallocate a buffer whose size is the result of
      an overflowing addition.
      We're much better off to tell the user that we cannot diff
      or merge such a large file. This patch covers both cases,
      but in slightly different ways:
        1. For merging, we notice the large file and cleanly fall
           back to a binary merge (which is effectively "we cannot
           merge this").
        2. For diffing, we make the binary/text distinction much
           earlier, and in many different places. For this case,
           we'll use the xdi_diff as our choke point, and reject
           any diff there before it hits the xdiff code.
           This means in most cases we'll die() immediately after.
           That's not ideal, but in practice we shouldn't
           generally hit this code path unless the user is trying
           to do something tricky. We already consider files
           larger than core.bigfilethreshold to be binary, so this
           code would only kick in when that is circumvented
           (either by bumping that value, or by using a
           .gitattribute to mark a file as diffable).
           In other words, we can avoid being "nice" here, because
           there is already nice code that tries to do the right
           thing. We are adding the suspenders to the nice code's
           belt, so notice when it has been worked around (both to
           protect the user from malicious inputs, and because it
           is better to die() than generate bogus output).
      The maximum size was chosen after experimenting with feeding
      large files to the xdiff code. It's just under a gigabyte,
      which leaves room for two obvious cases:
        - a diff3 merge conflict result on files of maximum size X
          could be 3*X plus the size of the markers, which would
          still be only about 3G, which fits in a 32-bit int.
        - some of the diff code allocates arrays of one int per
          record. Even if each file consists only of blank lines,
          then a file smaller than 1G will have fewer than 1G
          records, and therefore the int array will fit in 4G.
      Since the limit is arbitrary anyway, I chose to go under a
      gigabyte, to leave a safety margin (e.g., we would not want
      to overflow by allocating "(records + 1) * sizeof(int)" or
      Signed-off-by: 's avatarJeff King <peff@peff.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  6. 09 May, 2012 1 commit
  7. 04 May, 2010 1 commit
  8. 17 Feb, 2010 1 commit
  9. 02 Jul, 2009 1 commit
  10. 25 Oct, 2008 1 commit
  11. 19 Sep, 2008 1 commit
  12. 31 Aug, 2008 1 commit
  13. 14 Aug, 2008 3 commits
    • Junio C Hamano's avatar
      xdiff-interface: hide the whole "xdiff_emit_state" business from the caller · 8a3f524b
      Junio C Hamano authored
      This further enhances xdi_diff_outf() interface so that it takes two
      common parameters: the callback function that processes one line at a
      time, and a pointer to its application specific callback data structure.
      xdi_diff_outf() creates its own "xdiff_emit_state" structure and stashes
      these two away inside it, which is used by the lowest level output
      function in the xdiff_outf() callchain, consume_one(), to call back to the
      application layer.  With this restructuring, we lift the requirement that
      the caller supplied callback data structure embeds xdiff_emit_state
      structure as its first member.
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    • Brian Downing's avatar
      Use strbuf for struct xdiff_emit_state's remainder · b4637760
      Brian Downing authored
      Continually xreallocing and freeing the remainder member of struct
      xdiff_emit_state was a noticeable performance hit.  Use a strbuf
      This yields a decent performance improvement on "git blame" on certain
      repositories.  For example, before this commit:
      $ time git blame -M -C -C -p --incremental server.c >/dev/null
      101.52user 0.17system 1:41.73elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+39561minor)pagefaults 0swaps
      With this commit:
      $ time git blame -M -C -C -p --incremental server.c >/dev/null
      80.38user 0.30system 1:20.81elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
      0inputs+0outputs (0major+50979minor)pagefaults 0swaps
      Signed-off-by: Brian Downing's avatarBrian Downing <bdowning@lavos.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    • Brian Downing's avatar
      Make xdi_diff_outf interface for running xdiff_outf diffs · c99db9d2
      Brian Downing authored
      To prepare for the need to initialize and release resources for an
      xdi_diff with the xdiff_outf output function, make a new function to
      wrap this usage.
      	ecb.outf = xdiff_outf;
      	ecb.priv = &state;
      	xdi_diff(file_p, file_o, &xpp, &xecfg, &ecb);
      	xdi_diff_outf(file_p, file_o, &state.xm, &xpp, &xecfg, &ecb);
      Signed-off-by: Brian Downing's avatarBrian Downing <bdowning@lavos.net>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  14. 14 Dec, 2007 1 commit
  15. 06 Jul, 2007 1 commit
    • Junio C Hamano's avatar
      Per-path attribute based hunk header selection. · f258475a
      Junio C Hamano authored
      This makes"diff -p" hunk headers customizable via gitattributes mechanism.
      It is based on Johannes's earlier patch that allowed to define a single
      regexp to be used for everything.
      The mechanism to arrive at the regexp that is used to define hunk header
      is the same as other use of gitattributes.  You assign an attribute, funcname
      (because "diff -p" typically uses the name of the function the patch is about
      as the hunk header), a simple string value.  This can be one of the names of
      built-in pattern (currently, "java" is defined) or a custom pattern name, to
      be looked up from the configuration file.
        (in .gitattributes)
        *.java   funcname=java
        *.perl   funcname=perl
        (in .git/config)
          java = ... # ugly and complicated regexp to override the built-in one.
          perl = ... # another ugly and complicated regexp to define a new one.
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
  16. 16 Jun, 2007 1 commit
  17. 05 Jun, 2007 1 commit
  18. 22 Dec, 2006 1 commit
  19. 07 Apr, 2006 1 commit
  20. 05 Apr, 2006 2 commits