1. 07 3月, 2017 1 次提交
    • V
      line-log: use COPY_ARRAY to fix mis-sized memcpy · 07f546cd
      Vegard Nossum 提交于
      This memcpy meant to get the sizeof a "struct range", not a
      "range_set", as the former is what our array holds. Rather
      than swap out the types, let's convert this site to
      COPY_ARRAY, which avoids the problem entirely (and confirms
      that the src and dst types match).
      
      Note for curiosity's sake that this bug doesn't trigger on
      I32LP64 systems, but does on ILP32 systems. The mistaken
      "struct range_set" has two ints and a pointer. That's 16
      bytes on LP64, or 12 on ILP32. The correct "struct range"
      type has two longs, which is also 16 on LP64, but only 8 on
      ILP32.
      
      Likewise an IL32P64 system would experience the bug.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NVegard Nossum <vegard.nossum@oracle.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      07f546cd
  2. 04 3月, 2017 1 次提交
    • A
      line-log.c: prevent crash during union of too many ranges · aaae0bf7
      Allan Xavier 提交于
      The existing implementation of range_set_union does not correctly
      reallocate memory, leading to a heap overflow when it attempts to union
      more than 24 separate line ranges.
      
      For struct range_set *out to grow correctly it must have out->nr set to
      the current size of the buffer when it is passed to range_set_grow.
      However, the existing implementation of range_set_union only updates
      out->nr at the end of the function, meaning that it is always zero
      before this. This results in range_set_grow never growing the buffer, as
      well as some of the union logic itself being incorrect as !out->nr is
      always true.
      
      The reason why 24 is the limit is that the first allocation of size 1
      ends up allocating a buffer of size 24 (due to the call to alloc_nr in
      ALLOC_GROW). This goes some way to explain why this hasn't been
      caught before.
      
      Fix the problem by correctly updating out->nr after reallocating the
      range_set. As this results in out->nr containing the same value as the
      variable o, replace o with out->nr as well.
      
      Finally, add a new test to help prevent the problem reoccurring in the
      future. Thanks to Vegard Nossum for writing the test.
      Signed-off-by: NAllan Xavier <allan.x.xavier@oracle.com>
      Reviewed-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      aaae0bf7
  3. 30 9月, 2016 1 次提交
  4. 29 6月, 2016 2 次提交
  5. 25 6月, 2016 1 次提交
  6. 15 6月, 2016 1 次提交
  7. 23 2月, 2016 2 次提交
    • J
      convert trivial cases to ALLOC_ARRAY · b32fa95f
      Jeff King 提交于
      Each of these cases can be converted to use ALLOC_ARRAY or
      REALLOC_ARRAY, which has two advantages:
      
        1. It automatically checks the array-size multiplication
           for overflow.
      
        2. It always uses sizeof(*array) for the element-size,
           so that it can never go out of sync with the declared
           type of the array.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b32fa95f
    • J
      convert manual allocations to argv_array · 850d2fec
      Jeff King 提交于
      There are many manual argv allocations that predate the
      argv_array API. Switching to that API brings a few
      advantages:
      
        1. We no longer have to manually compute the correct final
           array size (so it's one less thing we can screw up).
      
        2. In many cases we had to make a separate pass to count,
           then allocate, then fill in the array. Now we can do it
           in one pass, making the code shorter and easier to
           follow.
      
        3. argv_array handles memory ownership for us, making it
           more obvious when things should be free()d and and when
           not.
      
      Most of these cases are pretty straightforward. In some, we
      switch from "run_command_v" to "run_command" which lets us
      directly use the argv_array embedded in "struct
      child_process".
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      850d2fec
  8. 20 11月, 2015 2 次提交
  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. 28 5月, 2015 1 次提交
  11. 21 4月, 2015 1 次提交
  12. 31 3月, 2015 1 次提交
  13. 16 1月, 2015 1 次提交
  14. 05 11月, 2014 1 次提交
  15. 19 9月, 2014 1 次提交
  16. 18 7月, 2014 1 次提交
  17. 09 7月, 2014 1 次提交
  18. 06 2月, 2014 1 次提交
  19. 23 10月, 2013 1 次提交
  20. 07 8月, 2013 3 次提交
  21. 06 8月, 2013 1 次提交
  22. 24 7月, 2013 3 次提交
  23. 16 7月, 2013 1 次提交
  24. 10 7月, 2013 1 次提交
  25. 13 4月, 2013 2 次提交
    • T
      log -L: improve comments in process_all_files() · 1ddac3ff
      Thomas Rast 提交于
      The funny range assignment in process_all_files() had me sidetracked
      while investigating what led to the previous commit.  Let's improve
      the comments.
      Signed-off-by: NThomas Rast <trast@inf.ethz.ch>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1ddac3ff
    • T
      log -L: store the path instead of a diff_filespec · 31c61918
      Thomas Rast 提交于
      line_log_data has held a diff_filespec* since the very early versions
      of the code.  However, the only place in the code where we actually
      need the full filespec is parse_range_arg(); in all other cases, we
      are only interested in the path, so there is hardly a reason to store
      a filespec.  Even worse, it causes a lot of redundant ->spec->path
      pointer dereferencing.
      
      And *even* worse, it caused the following bug.  If you merge a rename
      with a modification to the old filename, like so:
      
        * Merge
        | \
        |  * Modify foo
        |  |
        *  | Rename foo->bar
        | /
        * Create foo
      
      we internally -- in process_ranges_merge_commit() -- scan all parents.
      We are mainly looking for one that doesn't have any modifications, so
      that we can assign all the blame to it and simplify away the merge.
      In doing so, we run the normal machinery on all parents in a loop.
      For each parent, we prepare a "working set" line_log_data by making a
      copy with line_log_data_copy(), which does *not* make a copy of the
      spec.
      
      Now suppose the rename is the first parent.  The diff machinery tells
      us that the filepair is ('foo', 'bar').  We duly update the path we
      are interested in:
      
        rg->spec->path = xstrdup(pair->one->path);
      
      But that 'struct spec' is shared between the output line_log_data and
      the original input line_log_data.  So we just wrecked the state of
      process_ranges_merge_commit().  When we get around to the second
      parent, the ranges tell us we are interested in a file 'foo' while the
      commits touch 'bar'.
      
      So most of this patch is just s/->spec->path/->path/ and associated
      management changes.  This implicitly fixes the bug because we removed
      the shared parts between input and output of line_log_data_copy(); it
      is now safe to overwrite the path in the copy.
      
      There's one only somewhat related change: the comment in
      process_all_files() explains the reasoning behind using 'range' there.
      That bit of half-correct code had me sidetracked for a while.
      Signed-off-by: NThomas Rast <trast@inf.ethz.ch>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      31c61918
  26. 06 4月, 2013 2 次提交
  27. 29 3月, 2013 3 次提交
    • T
      Speed up log -L... -M · 39410bf0
      Thomas Rast 提交于
      So far log -L only used the implicit diff filtering by pathspec.  If
      the user specifies -M, we cannot do that, and so we simply handed the
      whole diff queue (which is approximately 'git show --raw') to
      diffcore_std().
      
      Unfortunately this is very slow.  We can optimize a lot if we throw
      out files that we know cannot possibly be interesting, in the same
      spirit that the pathspec filtering reduces the number of files.
      
      However, in this case, we have to be more careful.  Because we want to
      look out for renames, we need to keep all filepairs where something
      was deleted.
      
      This is a bit hacky and should really be replaced by equivalent
      support in --follow, and just using that.  However, in the meantime it
      speeds up 'log -M -L' by an order of magnitude.
      Signed-off-by: NThomas Rast <trast@student.ethz.ch>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      39410bf0
    • T
      log -L: :pattern:file syntax to find by funcname · 13b8f68c
      Thomas Rast 提交于
      This new syntax finds a funcname matching /pattern/, and then takes from there
      up to (but not including) the next funcname.  So you can say
      
        git log -L:main:main.c
      
      and it will dig up the main() function and show its line-log, provided
      there are no other funcnames matching 'main'.
      Signed-off-by: NThomas Rast <trast@student.ethz.ch>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      13b8f68c
    • T
      Implement line-history search (git log -L) · 12da1d1f
      Thomas Rast 提交于
      This is a rewrite of much of Bo's work, mainly in an effort to split
      it into smaller, easier to understand routines.
      
      The algorithm is built around the struct range_set, which encodes a
      series of line ranges as intervals [a,b).  This is used in two
      contexts:
      
      * A set of lines we are tracking (which will change as we dig through
        history).
      * To encode diffs, as pairs of ranges.
      
      The main routine is range_set_map_across_diff().  It processes the
      diff between a commit C and some parent P.  It determines which diff
      hunks are relevant to the ranges tracked in C, and computes the new
      ranges for P.
      
      The algorithm is then simply to process history in topological order
      from newest to oldest, computing ranges and (partial) diffs.  At
      branch points, we need to merge the ranges we are watching.  We will
      find that many commits do not affect the chosen ranges, and mark them
      TREESAME (in addition to those already filtered by pathspec limiting).
      Another pass of history simplification then gets rid of such commits.
      
      This is wired as an extra filtering pass in the log machinery.  This
      currently only reduces code duplication, but should allow for other
      simplifications and options to be used.
      
      Finally, we hook a diff printer into the output chain.  Ideally we
      would wire directly into the diff logic, to optionally use features
      like word diff.  However, that will require some major reworking of
      the diff chain, so we completely replace the output with our own diff
      for now.
      
      As this was a GSoC project, and has quite some history by now, many
      people have helped.  In no particular order, thanks go to
      
        Jakub Narebski <jnareb@gmail.com>
        Jens Lehmann <Jens.Lehmann@web.de>
        Jonathan Nieder <jrnieder@gmail.com>
        Junio C Hamano <gitster@pobox.com>
        Ramsay Jones <ramsay@ramsay1.demon.co.uk>
        Will Palmer <wmpalmer@gmail.com>
      
      Apologies to everyone I forgot.
      Signed-off-by: NBo Yang <struggleyb.nku@gmail.com>
      Signed-off-by: NThomas Rast <trast@student.ethz.ch>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      12da1d1f