1. 08 11月, 2017 1 次提交
    • M
      reduce_heads: fix memory leaks · 4da72644
      Martin Ågren 提交于
      We currently have seven callers of `reduce_heads(foo)`. Six of them do
      not use the original list `foo` again, and actually, all six of those
      end up leaking it.
      
      Introduce and use `reduce_heads_replace(&foo)` as a leak-free version of
      `foo = reduce_heads(foo)` to fix several of these. Fix the remaining
      leaks using `free_commit_list()`.
      
      While we're here, document `reduce_heads()` and mark it as `extern`.
      Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4da72644
  2. 24 9月, 2017 1 次提交
  3. 07 9月, 2017 1 次提交
  4. 19 8月, 2017 3 次提交
    • P
      commit: rewrite read_graft_line · cfa5bf16
      Patryk Obara 提交于
      Old implementation determined number of hashes by dividing length of
      line by length of hash, which works only if all hash representations
      have same length.
      
      New graft line parser works in two phases:
      
        1. In first phase line is scanned to verify correctness and compute
           number of hashes, then graft struct is allocated.
      
        2. In second phase line is scanned again to fill up already allocated
           graft struct.
      
      This way graft parsing code can support different sizes of hashes
      without any further code adaptations.
      
      A number of alternative implementations were considered and discarded:
      
        - Modifying graft structure to store oid_array instead of FLEXI_ARRAY
          indicates undesirable usage of struct to readers.
      
        - Parsing into temporary string_list or oid_array complicates code
          by adding more return paths, as these structures needs to be
          cleared before returning from function.
      
        - Determining number of hashes by counting separators might cause
          maintenance issues, if this function needs to be modified in future
          again.
      Signed-off-by: NPatryk Obara <patryk.obara@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cfa5bf16
    • P
      commit: allocate array using object_id size · bc65d226
      Patryk Obara 提交于
      struct commit_graft aggregates an array of object_id's, which have
      size >= GIT_MAX_RAWSZ bytes. This change prevents memory allocation
      error when size of object_id is larger than GIT_SHA1_RAWSZ.
      Signed-off-by: NPatryk Obara <patryk.obara@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bc65d226
    • P
      commit: replace the raw buffer with strbuf in read_graft_line · 9a934032
      Patryk Obara 提交于
      This simplifies function declaration and allows for use of strbuf_rtrim
      instead of modifying buffer directly.
      Signed-off-by: NPatryk Obara <patryk.obara@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9a934032
  5. 18 7月, 2017 2 次提交
    • R
      use MOVE_ARRAY · f331ab9d
      René Scharfe 提交于
      Simplify the code for moving members inside of an array and make it more
      robust by using the helper macro MOVE_ARRAY.  It calculates the size
      based on the specified number of elements for us and supports NULL
      pointers when that number is zero.  Raw memmove(3) calls with NULL can
      cause the compiler to (over-eagerly) optimize out later NULL checks.
      
      This patch was generated with contrib/coccinelle/array.cocci and spatch
      (Coccinelle).
      Signed-off-by: NRene Scharfe <l.s.r@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f331ab9d
    • B
      sha1_name: convert get_sha1* to get_oid* · e82caf38
      brian m. carlson 提交于
      Now that all the callers of get_sha1 directly or indirectly use struct
      object_id, rename the functions starting with get_sha1 to start with
      get_oid.  Convert the internals in sha1_name.c to use struct object_id
      as well, and eliminate explicit length checks where possible.  Convert a
      use of 40 in get_oid_basic to GIT_SHA1_HEXSZ.
      
      Outside of sha1_name.c and cache.h, this transition was made with the
      following semantic patch:
      
      @@
      expression E1, E2;
      @@
      - get_sha1(E1, E2.hash)
      + get_oid(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1(E1, E2->hash)
      + get_oid(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_committish(E1, E2.hash)
      + get_oid_committish(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_committish(E1, E2->hash)
      + get_oid_committish(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_treeish(E1, E2.hash)
      + get_oid_treeish(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_treeish(E1, E2->hash)
      + get_oid_treeish(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_commit(E1, E2.hash)
      + get_oid_commit(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_commit(E1, E2->hash)
      + get_oid_commit(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_tree(E1, E2.hash)
      + get_oid_tree(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_tree(E1, E2->hash)
      + get_oid_tree(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_blob(E1, E2.hash)
      + get_oid_blob(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_blob(E1, E2->hash)
      + get_oid_blob(E1, E2)
      
      @@
      expression E1, E2, E3, E4;
      @@
      - get_sha1_with_context(E1, E2, E3.hash, E4)
      + get_oid_with_context(E1, E2, &E3, E4)
      
      @@
      expression E1, E2, E3, E4;
      @@
      - get_sha1_with_context(E1, E2, E3->hash, E4)
      + get_oid_with_context(E1, E2, E3, E4)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e82caf38
  6. 14 7月, 2017 1 次提交
  7. 17 6月, 2017 1 次提交
  8. 26 5月, 2017 1 次提交
  9. 18 5月, 2017 1 次提交
    • B
      interpret-trailers: honor the cut line · d76650b8
      Brian Malehorn 提交于
      If a commit message is edited with the "verbose" option, the buffer
      will have a cut line and diff after the log message, like so:
      
          my subject
      
          # ------------------------ >8 ------------------------
          # Do not touch the line above.
          # Everything below will be removed.
          diff --git a/foo.txt b/foo.txt
          index 5716ca5..7601807 100644
          --- a/foo.txt
          +++ b/foo.txt
          @@ -1 +1 @@
          -bar
          +baz
      
      "git interpret-trailers" is unaware of the cut line, and assumes the
      trailer block would be at the end of the whole thing.  This can easily
      be seen with:
      
           $ GIT_EDITOR='git interpret-trailers --in-place --trailer Acked-by:me' \
             git commit --amend -v
      
      Teach "git interpret-trailers" to notice the cut-line and ignore the
      remainder of the input when looking for a place to add new trailer
      block.  This makes it consistent with how "git commit -v -s" inserts a
      new Signed-off-by: line.
      
      This can be done by the same logic as the existing helper function,
      wt_status_truncate_message_at_cut_line(), uses, but it wants the caller
      to pass a strbuf to it.  Because the function ignore_non_trailer() used
      by the command takes a <pointer, length> pair, not a strbuf, steal the
      logic from wt_status_truncate_message_at_cut_line() to create a new
      wt_status_locate_end() helper function that takes <pointer, length>
      pair, and make ignore_non_trailer() call it to help "interpret-trailers".
      
      Since there is only one caller of wt_status_truncate_message_at_cut_line()
      in cmd_commit(), rewrite it to call wt_status_locate_end() helper instead
      and remove the old helper that no longer has any caller.
      Signed-off-by: NBrian Malehorn <bmalehorn@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d76650b8
  10. 08 5月, 2017 4 次提交
    • B
      object: convert parse_object* to take struct object_id · c251c83d
      brian m. carlson 提交于
      Make parse_object, parse_object_or_die, and parse_object_buffer take a
      pointer to struct object_id.  Remove the temporary variables inserted
      earlier, since they are no longer necessary.  Transform all of the
      callers using the following semantic patch:
      
      @@
      expression E1;
      @@
      - parse_object(E1.hash)
      + parse_object(&E1)
      
      @@
      expression E1;
      @@
      - parse_object(E1->hash)
      + parse_object(E1)
      
      @@
      expression E1, E2;
      @@
      - parse_object_or_die(E1.hash, E2)
      + parse_object_or_die(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - parse_object_or_die(E1->hash, E2)
      + parse_object_or_die(E1, E2)
      
      @@
      expression E1, E2, E3, E4, E5;
      @@
      - parse_object_buffer(E1.hash, E2, E3, E4, E5)
      + parse_object_buffer(&E1, E2, E3, E4, E5)
      
      @@
      expression E1, E2, E3, E4, E5;
      @@
      - parse_object_buffer(E1->hash, E2, E3, E4, E5)
      + parse_object_buffer(E1, E2, E3, E4, E5)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c251c83d
    • B
      Convert lookup_tree to struct object_id · 740ee055
      brian m. carlson 提交于
      Convert the lookup_tree function to take a pointer to struct object_id.
      
      The commit was created with manual changes to tree.c, tree.h, and
      object.c, plus the following semantic patch:
      
      @@
      @@
      - lookup_tree(EMPTY_TREE_SHA1_BIN)
      + lookup_tree(&empty_tree_oid)
      
      @@
      expression E1;
      @@
      - lookup_tree(E1.hash)
      + lookup_tree(&E1)
      
      @@
      expression E1;
      @@
      - lookup_tree(E1->hash)
      + lookup_tree(E1)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      740ee055
    • B
      Convert lookup_commit* to struct object_id · bc83266a
      brian m. carlson 提交于
      Convert lookup_commit, lookup_commit_or_die,
      lookup_commit_reference, and lookup_commit_reference_gently to take
      struct object_id arguments.
      
      Introduce a temporary in parse_object buffer in order to convert this
      function.  This is required since in order to convert parse_object and
      parse_object_buffer, lookup_commit_reference_gently and
      lookup_commit_or_die would need to be converted.  Not introducing a
      temporary would therefore require that lookup_commit_or_die take a
      struct object_id *, but lookup_commit would take unsigned char *,
      leaving a confusing and hard-to-use interface.
      
      parse_object_buffer will lose this temporary in a later patch.
      
      This commit was created with manual changes to commit.c, commit.h, and
      object.c, plus the following semantic patch:
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_reference_gently(E1.hash, E2)
      + lookup_commit_reference_gently(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_reference_gently(E1->hash, E2)
      + lookup_commit_reference_gently(E1, E2)
      
      @@
      expression E1;
      @@
      - lookup_commit_reference(E1.hash)
      + lookup_commit_reference(&E1)
      
      @@
      expression E1;
      @@
      - lookup_commit_reference(E1->hash)
      + lookup_commit_reference(E1)
      
      @@
      expression E1;
      @@
      - lookup_commit(E1.hash)
      + lookup_commit(&E1)
      
      @@
      expression E1;
      @@
      - lookup_commit(E1->hash)
      + lookup_commit(E1)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_or_die(E1.hash, E2)
      + lookup_commit_or_die(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_or_die(E1->hash, E2)
      + lookup_commit_or_die(E1, E2)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bc83266a
    • B
      shallow: convert shallow registration functions to object_id · e92b848c
      brian m. carlson 提交于
      Convert register_shallow and unregister_shallow to take struct
      object_id.  register_shallow is a caller of lookup_commit, which we will
      convert later.  It doesn't make sense for the registration and
      unregistration functions to have incompatible interfaces, so convert
      them both.
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e92b848c
  11. 27 4月, 2017 1 次提交
    • J
      timestamp_t: a new data type for timestamps · dddbad72
      Johannes Schindelin 提交于
      Git's source code assumes that unsigned long is at least as precise as
      time_t. Which is incorrect, and causes a lot of problems, in particular
      where unsigned long is only 32-bit (notably on Windows, even in 64-bit
      versions).
      
      So let's just use a more appropriate data type instead. In preparation
      for this, we introduce the new `timestamp_t` data type.
      
      By necessity, this is a very, very large patch, as it has to replace all
      timestamps' data type in one go.
      
      As we will use a data type that is not necessarily identical to `time_t`,
      we need to be very careful to use `time_t` whenever we interact with the
      system functions, and `timestamp_t` everywhere else.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dddbad72
  12. 24 4月, 2017 1 次提交
  13. 28 2月, 2017 2 次提交
  14. 02 2月, 2017 1 次提交
  15. 30 11月, 2016 1 次提交
  16. 26 9月, 2016 1 次提交
    • R
      use COPY_ARRAY · 45ccef87
      René Scharfe 提交于
      Add a semantic patch for converting certain calls of memcpy(3) to
      COPY_ARRAY() and apply that transformation to the code base.  The result
      is
       shorter and safer code.  For now only consider calls where source and
      destination have the same type, or in other words: easy cases.
      Signed-off-by: NRene Scharfe <l.s.r@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      45ccef87
  17. 20 9月, 2016 1 次提交
  18. 14 8月, 2016 3 次提交
  19. 09 7月, 2016 1 次提交
    • J
      commit.c: remove print_commit_list() · 54307ea7
      Junio C Hamano 提交于
      The helper function tries to offer a way to conveniently show the
      last one differently from others, presumably to allow you to say
      something like
      
      	A, B, and C.
      
      while iterating over a list that has these three elements.
      
      However, there is only one caller, and it passes the same format
      string "%s\n" for both the last one and the other ones.  Retire the
      helper function and update the caller with a simplified version.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      54307ea7
  20. 30 6月, 2016 1 次提交
  21. 23 6月, 2016 1 次提交
  22. 23 2月, 2016 2 次提交
  23. 20 11月, 2015 3 次提交
  24. 27 10月, 2015 1 次提交
  25. 23 6月, 2015 2 次提交
  26. 02 6月, 2015 1 次提交
    • J
      add quieter versions of parse_{tree,commit} · 9cc2b07a
      Jeff King 提交于
      When we call parse_commit, it will complain to stderr if the
      object does not exist or cannot be read. This means that we
      may produce useless error messages if this situation is
      expected (e.g., because the object is marked UNINTERESTING,
      or because revs->ignore_missing_links is set).
      
      We can fix this by adding a new "parse_X_gently" form that
      takes a flag to suppress the messages. The existing
      "parse_X" form is already gentle in the sense that it
      returns an error rather than dying, and we could in theory
      just add a "quiet" flag to it (with existing callers passing
      "0"). But doing it this way means we do not have to disturb
      existing callers.
      
      Note also that the new flag is "quiet_on_missing", and not
      just "quiet". We could add a flag to suppress _all_ errors,
      but besides being a more invasive change (we would have to
      pass the flag down to sub-functions, too), there is a good
      reason not to: we would never want to use it. Missing a
      linked object is expected in some circumstances, but it is
      never expected to have a malformed commit, or to get a tree
      when we wanted a commit.  We should always complain about
      these corruptions.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9cc2b07a
  27. 23 5月, 2015 1 次提交
    • J
      commit-slab: introduce slabname##_peek() function · 862e730e
      Junio C Hamano 提交于
      There is no API to ask "Does this commit have associated data in
      slab?".  If an application wants to (1) parse just a few commits at
      the beginning of a process, (2) store data for only these commits,
      and then (3) start processing many commits, taking into account the
      data stored (for a few of them) in the slab, the application would
      use slabname##_at() to allocate a space to store data in (2), but
      there is no API other than slabname##_at() to use in step (3).  This
      allocates and wastes new space for these commits the caller is only
      interested in checking if they have data stored in step (2).
      
      Introduce slabname##_peek(), which is similar to slabname##_at() but
      returns NULL when there is no data already associated to it in such
      a use case.
      Helped-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      862e730e