1. 18 Mar, 2017 1 commit
    • Gábor Szeder's avatar
      pickaxe: fix segfault with '-S<...> --pickaxe-regex' · f53c5de2
      Gábor Szeder authored
      'git {log,diff,...} -S<...> --pickaxe-regex' can segfault as a result
      of out-of-bounds memory reads.
      
      diffcore-pickaxe.c:contains() looks for all matches of the given regex
      in a buffer in a loop, advancing the buffer pointer to the end of the
      last match in each iteration.  When we switched to REG_STARTEND in
      b7d36ffc (regex: use regexec_buf(), 2016-09-21), we started passing
      the size of that buffer to the regexp engine, too.  Unfortunately,
      this buffer size is never updated on subsequent iterations, and as the
      buffer pointer advances on each iteration, this "bufptr+bufsize"
      points past the end of the buffer.  This results in segmentation
      fault, if that memory can't be accessed.  In case of 'git log' it can
      also result in erroneously listed commits, if the memory past the end
      of buffer is accessible and happens to contain data matching the
      regex.
      
      Reduce the buffer size on each iteration as the buffer pointer is
      advanced, thus maintaining the correct end of buffer location.
      Furthermore, make sure that the buffer pointer is not dereferenced in
      the control flow statements when we already reached the end of the
      buffer.
      
      The new test is flaky, I've never seen it fail on my Linux box even
      without the fix, but this is expected according to db5dfa33 (regex:
      -G<pattern> feeds a non NUL-terminated string to regexec() and fails,
      2016-09-21).  However, it did fail on Travis CI with the first (and
      incomplete) version of the fix, and based on that commit message I
      would expect the new test without the fix to fail most of the time on
      Windows.
      Signed-off-by: Gábor Szeder's avatarSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      f53c5de2
  2. 21 Sep, 2016 1 commit
    • Johannes Schindelin's avatar
      regex: use regexec_buf() · b7d36ffc
      Johannes Schindelin authored
      The new regexec_buf() function operates on buffers with an explicitly
      specified length, rather than NUL-terminated strings.
      
      We need to use this function whenever the buffer we want to pass to
      regexec(3) may have been mmap(2)ed (and is hence not NUL-terminated).
      
      Note: the original motivation for this patch was to fix a bug where
      `git diff -G <regex>` would crash. This patch converts more callers,
      though, some of which allocated to construct NUL-terminated strings,
      or worse, modified buffers to temporarily insert NULs while calling
      regexec(3).  By converting them to use regexec_buf(), the code has
      become much cleaner.
      Signed-off-by: Johannes Schindelin's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      b7d36ffc
  3. 01 Jul, 2016 2 commits
  4. 28 Sep, 2015 1 commit
    • Jeff King's avatar
      react to errors in xdi_diff · 3efb9880
      Jeff King authored
      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: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3efb9880
  5. 24 Mar, 2014 5 commits
  6. 07 Jul, 2013 1 commit
  7. 03 Jun, 2013 1 commit
  8. 05 Apr, 2013 6 commits
    • Jeff King's avatar
      diffcore-pickaxe: unify code for log -S/-G · 61690bf4
      Jeff King authored
      The logic flow of has_changes() used for "log -S" and diff_grep()
      used for "log -G" are essentially the same.  See if we have both
      sides that could be different in any interesting way, slurp the
      contents in core, possibly after applying textconv, inspect the
      contents, clean-up and report the result.  The only difference
      between the two is how "inspect" step works.
      
      Unify this codeflow in a helper, pickaxe_match(), which takes a
      callback function that implements the specific "inspect" step.
      
      After removing the common scaffolding code from the existing
      has_changes() and diff_grep(), they each becomes such a callback
      function suitable for passing to pickaxe_match().
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      61690bf4
    • Junio C Hamano's avatar
      diffcore-pickaxe: fix leaks in "log -S<block>" and "log -G<pattern>" · 88ff684d
      Junio C Hamano authored
      The diff_grep() and has_changes() functions had early return
      codepaths for unmerged filepairs, which simply returned 0.  When we
      taught textconv filter to them, one was ignored and continued to
      return early without freeing the result filtered by textconv, and
      the other had a failed attempt to fix, which allowed the planned
      return value 0 to be overwritten by a bogus call to contains().
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      88ff684d
    • Junio C Hamano's avatar
      diffcore-pickaxe: port optimization from has_changes() to diff_grep() · ebb72262
      Junio C Hamano authored
      These two functions are called in the same codeflow to implement
      "log -S<block>" and "log -G<pattern>", respectively, but the latter
      lacked two obvious optimizations the former implemented, namely:
      
       - When a pickaxe limit is not given at all, they should return
         without wasting any cycle;
      
       - When both sides of the filepair are the same, and the same
         textconv conversion apply to them, return early, as there will be
         no interesting differences between the two anyway.
      
      Also release the filespec data once the processing is done (this is
      not about leaking memory--it is about releasing data we finished
      looking at as early as possible).
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      ebb72262
    • Simon Ruderich's avatar
      diffcore-pickaxe: respect --no-textconv · a8f61094
      Simon Ruderich authored
      git log -S doesn't respect --no-textconv:
      
          $ echo '*.txt diff=wrong' > .gitattributes
          $ git -c diff.wrong.textconv='xxx' log --no-textconv -Sfoo
          error: cannot run xxx: No such file or directory
          fatal: unable to read files to diff
      Reported-by: Matthieu Moy's avatarMatthieu Moy <Matthieu.Moy@grenoble-inp.fr>
      Signed-off-by: Simon Ruderich's avatarSimon Ruderich <simon@ruderich.org>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      a8f61094
    • Jeff King's avatar
      diffcore-pickaxe: remove fill_one() · 7cdb9b42
      Jeff King authored
      fill_one is _almost_ identical to just calling fill_textconv; the
      exception is that for the !DIFF_FILE_VALID case, fill_textconv gives us
      an empty buffer rather than a NULL one. Since we currently use the NULL
      pointer as a signal that the file is not present on one side of the
      diff, we must now switch to using DIFF_FILE_VALID to make the same
      check.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: Simon Ruderich's avatarSimon Ruderich <simon@ruderich.org>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      7cdb9b42
    • Simon Ruderich's avatar
      diffcore-pickaxe: remove unnecessary call to get_textconv() · bc615898
      Simon Ruderich authored
      The fill_one() function is responsible for finding and filling the
      textconv filter as necessary, and is called by diff_grep() function
      that implements "git log -G<pattern>".
      
      The has_changes() function that implements "git log -S<block>" calls
      get_textconv() for two sides being compared, before it checks to see
      if it was asked to perform the pickaxe limiting.  Move the code
      around to avoid this wastage.
      
      After has_changes() calls get_textconv() to obtain textconv for both
      sides, fill_one() is called to use them.
      
      By adding get_textconv() to diff_grep() and relieving fill_one() of
      responsibility to find the textconv filter, we can avoid calling
      get_textconv() twice in has_changes().
      
      With this change it's also no longer necessary for fill_one() to
      modify the textconv argument, therefore pass a pointer instead of a
      pointer to a pointer.
      Signed-off-by: Simon Ruderich's avatarSimon Ruderich <simon@ruderich.org>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      bc615898
  9. 28 Oct, 2012 3 commits
    • Jeff King's avatar
      pickaxe: use textconv for -S counting · ef90ab66
      Jeff King authored
      We currently just look at raw blob data when using "-S" to
      pickaxe. This is mostly historical, as pickaxe predates the
      textconv feature. If the user has bothered to define a
      textconv filter, it is more likely that their search string will be
      on the textconv output, as that is what they will see in the
      diff (and we do not even provide a mechanism for them to
      search for binary needles that contain NUL characters).
      
      This patch teaches "-S" to use textconv, just as we
      already do for "-G".
      Signed-off-by: default avatarJeff King <peff@peff.net>
      ef90ab66
    • Jeff King's avatar
      pickaxe: hoist empty needle check · 8fa4b09f
      Jeff King authored
      If we are given an empty pickaxe needle like "git log -S ''",
      it is impossible for us to find anything (because no matter
      what the content, the count will always be 0). We currently
      check this at the lowest level of contains(). Let's hoist
      the logic much earlier to has_changes(), so that it is
      simpler to return our answer before loading any blob data.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      8fa4b09f
    • Jeff King's avatar
      diff_grep: use textconv buffers for add/deleted files · b1c2f57d
      Jeff King authored
      If you use "-G" to grep a diff, we will apply a configured
      textconv filter to the data before generating the diff.
      However, if the diff is an addition or deletion, we do not
      bother running the diff at all, and just look for the token
      in the added (or removed) content. This works because we
      know that the diff must contain every line of content.
      
      However, while we used the textconv-derived buffers in the
      regular diff, we accidentally passed the original unmodified
      buffers to regexec when checking the added or removed
      content. This could lead to an incorrect answer.
      
      Worse, in some cases we might have a textconv buffer but no
      original buffer (e.g., if we pulled the textconv data from
      cache, or if we reused a working tree file when generating
      it). In that case, we could actually feed NULL to regexec
      and segfault.
      Reported-by: Peter Oberndorfer's avatarPeter Oberndorfer <kumbayo84@arcor.de>
      Signed-off-by: default avatarJeff King <peff@peff.net>
      b1c2f57d
  10. 29 Feb, 2012 1 commit
    • Junio C Hamano's avatar
      pickaxe: allow -i to search in patch case-insensitively · accccde4
      Junio C Hamano authored
      "git log -S<string>" is a useful way to find the last commit in the
      codebase that touched the <string>. As it was designed to be used by a
      porcelain script to dig the history starting from a block of text that
      appear in the starting commit, it never had to look for anything but an
      exact match.
      
      When used by an end user who wants to look for the last commit that
      removed a string (e.g. name of a variable) that he vaguely remembers,
      however, it is useful to support case insensitive match.
      
      When given the "--regexp-ignore-case" (or "-i") option, which originally
      was designed to affect case sensitivity of the search done in the commit
      log part, e.g. "log --grep", the matches made with -S/-G pickaxe search is
      done case insensitively now.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      accccde4
  11. 07 Oct, 2011 7 commits
  12. 21 Aug, 2011 1 commit
    • Fredrik K's avatar
      Use kwset in pickaxe · b95c5ada
      Fredrik K authored
      Benchmarks in the hot cache case:
      
      before:
      $ perf stat --repeat=5 git log -Sqwerty
      
      Performance counter stats for 'git log -Sqwerty' (5 runs):
      
             47,092,744 cache-misses             #      2.825 M/sec   ( +-   1.607% )
            123,368,389 cache-references         #      7.400 M/sec   ( +-   0.812% )
            330,040,998 branch-misses            #      3.134 %       ( +-   0.257% )
         10,530,896,750 branches                 #    631.663 M/sec   ( +-   0.121% )
         62,037,201,030 instructions             #      1.399 IPC     ( +-   0.142% )
         44,331,294,321 cycles                   #   2659.073 M/sec   ( +-   0.326% )
                 96,794 page-faults              #      0.006 M/sec   ( +-  11.952% )
                     25 CPU-migrations           #      0.000 M/sec   ( +-  25.266% )
                  1,424 context-switches         #      0.000 M/sec   ( +-   0.540% )
           16671.708650 task-clock-msecs         #      0.997 CPUs    ( +-   0.343% )
      
            16.728692052  seconds time elapsed   ( +-   0.344% )
      
      after:
      $ perf stat --repeat=5 git log -Sqwerty
      
      Performance counter stats for 'git log -Sqwerty' (5 runs):
      
             51,385,522 cache-misses             #      4.619 M/sec   ( +-   0.565% )
            129,177,880 cache-references         #     11.611 M/sec   ( +-   0.219% )
            319,222,775 branch-misses            #      6.946 %       ( +-   0.134% )
          4,595,913,233 branches                 #    413.086 M/sec   ( +-   0.112% )
         31,395,042,533 instructions             #      1.062 IPC     ( +-   0.129% )
         29,558,348,598 cycles                   #   2656.740 M/sec   ( +-   0.204% )
                 93,224 page-faults              #      0.008 M/sec   ( +-   4.487% )
                     19 CPU-migrations           #      0.000 M/sec   ( +-  10.425% )
                    950 context-switches         #      0.000 M/sec   ( +-   0.360% )
           11125.796039 task-clock-msecs         #      0.997 CPUs    ( +-   0.239% )
      
            11.164216599  seconds time elapsed   ( +-   0.240% )
      
      So the kwset code is about 33% faster.
      Signed-off-by: Fredrik K's avatarFredrik Kuivinen <frekui@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      b95c5ada
  13. 06 Oct, 2010 1 commit
  14. 05 Oct, 2010 1 commit
  15. 31 Aug, 2010 2 commits
    • Junio C Hamano's avatar
      git log/diff: add -G<regexp> that greps in the patch text · f506b8e8
      Junio C Hamano authored
      Teach "-G<regexp>" that is similar to "-S<regexp> --pickaxe-regexp" to the
      "git diff" family of commands.  This limits the diff queue to filepairs
      whose patch text actually has an added or a deleted line that matches the
      given regexp.  Unlike "-S<regexp>", changing other parts of the line that
      has a substring that matches the given regexp IS counted as a change, as
      such a change would appear as one deletion followed by one addition in a
      patch text.
      
      Unlike -S (pickaxe) that is intended to be used to quickly detect a commit
      that changes the number of occurrences of hits between the preimage and
      the postimage to serve as a part of larger toolchain, this is meant to be
      used as the top-level Porcelain feature.
      
      The implementation unfortunately has to run "diff" twice if you are
      running "log" family of commands to produce patches in the final output
      (e.g. "git log -p" or "git format-patch").  I think we _could_ cache the
      result in-core if we wanted to, but that would require larger surgery to
      the diffcore machinery (i.e. adding an extra pointer in the filepair
      structure to keep a pointer to a strbuf around, stuff the textual diff to
      the strbuf inside diffgrep_consume(), and make use of it in later stages
      when it is available) and it may not be worth it.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      f506b8e8
    • Junio C Hamano's avatar
      diff: pass the entire diff-options to diffcore_pickaxe() · 382f013b
      Junio C Hamano authored
      That would make it easier to give enhanced feature to the
      pickaxe transformation.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      382f013b
  16. 07 May, 2010 1 commit
  17. 22 Mar, 2009 1 commit
    • René Scharfe's avatar
      pickaxe: count regex matches only once · 7ad3c52e
      René Scharfe authored
      When --pickaxe-regex is used, forward past the end of matches instead of
      advancing to the byte after their start.  This way matches count only
      once, even if the regular expression matches their tail -- like in the
      fixed-string fork of the code.
      
      E.g.: /.*/ used to count the number of bytes instead of the number of
      lines.  /aa/ resulted in a count of two in "aaa" instead of one.
      
      Also document the fact that regexec() needs a NUL-terminated string as
      its second argument by adding an assert().
      Signed-off-by: default avatarRene Scharfe <rene.scharfe@lsrfire.ath.cx>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      7ad3c52e
  18. 17 Mar, 2009 1 commit
    • René Scharfe's avatar
      pickaxe: count regex matches only once · 50fd6997
      René Scharfe authored
      When --pickaxe-regex is used, forward past the end of matches instead of
      advancing to the byte after their start.  This way matches count only
      once, even if the regular expression matches their tail -- like in the
      fixed-string fork of the code.
      
      E.g.: /.*/ used to count the number of bytes instead of the number of
      lines.  /aa/ resulted in a count of two in "aaa" instead of one.
      
      Also document the fact that regexec() needs a NUL-terminated string as
      its second argument by adding an assert().
      Signed-off-by: default avatarRene Scharfe <rene.scharfe@lsrfire.ath.cx>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      50fd6997
  19. 03 Mar, 2009 1 commit
    • René Scharfe's avatar
      diffcore-pickaxe: use memmem() · ce163c79
      René Scharfe authored
      Use memmem() instead of open-coding it.  The system libraries usually have a
      much faster version than the memcmp()-loop here.  Even our own fall-back in
      compat/, which is used on Windows, is slightly faster.
      
      The following commands were run in a Linux kernel repository and timed, the
      best of five results is shown:
      
        $ STRING='Ensure that the real time constraints are schedulable.'
        $ git log -S"$STRING" HEAD -- kernel/sched.c >/dev/null
      
      On Ubuntu 8.10 x64, before (v1.6.2-rc2):
      
        8.09user 0.04system 0:08.14elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
        0inputs+0outputs (0major+30952minor)pagefaults 0swaps
      
      And with the patch:
      
        1.50user 0.04system 0:01.54elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
        0inputs+0outputs (0major+30645minor)pagefaults 0swaps
      
      On Fedora 10 x64, before:
      
        8.34user 0.05system 0:08.39elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
        0inputs+0outputs (0major+29268minor)pagefaults 0swaps
      
      And with the patch:
      
        1.15user 0.05system 0:01.20elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
        0inputs+0outputs (0major+32253minor)pagefaults 0swaps
      
      On Windows Vista x64, before:
      
        real    0m9.204s
        user    0m0.000s
        sys     0m0.000s
      
      And with the patch:
      
        real    0m8.470s
        user    0m0.000s
        sys     0m0.000s
      Signed-off-by: default avatarRene Scharfe <rene.scharfe@lsrfire.ath.cx>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      ce163c79
  20. 07 Jun, 2007 1 commit
    • Junio C Hamano's avatar
      War on whitespace · a6080a0a
      Junio C Hamano authored
      This uses "git-apply --whitespace=strip" to fix whitespace errors that have
      crept in to our source files over time.  There are a few files that need
      to have trailing whitespaces (most notably, test vectors).  The results
      still passes the test, and build result in Documentation/ area is unchanged.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      a6080a0a
  21. 07 May, 2007 1 commit