1. 15 Jan, 2019 1 commit
    • brian m. carlson's avatar
      tree-walk: store object_id in a separate member · ea82b2a0
      brian m. carlson authored
      When parsing a tree, we read the object ID directly out of the tree
      buffer. This is normally fine, but such an object ID cannot be used with
      oidcpy, which copies GIT_MAX_RAWSZ bytes, because if we are using SHA-1,
      there may not be that many bytes to copy.
      
      Instead, store the object ID in a separate struct member. Since we can
      no longer efficiently compute the path length, store that information as
      well in struct name_entry. Ensure we only copy the object ID into the
      new buffer if the path length is nonzero, as some callers will pass us
      an empty path with no object ID following it, and we will not want to
      read past the end of the buffer.
      Signed-off-by: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      ea82b2a0
  2. 29 Jun, 2018 4 commits
  3. 16 May, 2018 1 commit
    • Stefan Beller's avatar
      object-store: move object access functions to object-store.h · cbd53a21
      Stefan Beller authored
      This should make these functions easier to find and cache.h less
      overwhelming to read.
      
      In particular, this moves:
      - read_object_file
      - oid_object_info
      - write_object_file
      
      As a result, most of the codebase needs to #include object-store.h.
      In this patch the #include is only added to files that would fail to
      compile otherwise.  It would be better to #include wherever
      identifiers from the header are used.  That can happen later
      when we have better tooling for it.
      Signed-off-by: Stefan Beller's avatarStefan Beller <sbeller@google.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      cbd53a21
  4. 24 Apr, 2018 1 commit
  5. 11 Apr, 2018 2 commits
    • Derrick Stolee's avatar
      treewide: replace maybe_tree with accessor methods · 2e27bd77
      Derrick Stolee authored
      In anticipation of making trees load lazily, create a Coccinelle
      script (contrib/coccinelle/commit.cocci) to ensure that all
      references to the 'maybe_tree' member of struct commit are either
      mutations or accesses through get_commit_tree() or
      get_commit_tree_oid().
      
      Apply the Coccinelle script to create the rest of the patch.
      Signed-off-by: Derrick Stolee's avatarDerrick Stolee <dstolee@microsoft.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      2e27bd77
    • Derrick Stolee's avatar
      treewide: rename tree to maybe_tree · 891435d5
      Derrick Stolee authored
      Using the commit-graph file to walk commit history removes the large
      cost of parsing commits during the walk. This exposes a performance
      issue: lookup_tree() takes a large portion of the computation time,
      even when Git never uses those trees.
      
      In anticipation of lazy-loading these trees, rename the 'tree' member
      of struct commit to 'maybe_tree'. This serves two purposes: it hints
      at the future role of possibly being NULL even if the commit has a
      valid tree, and it allows for unambiguous transformation from simple
      member access (i.e. commit->maybe_tree) to method access.
      Signed-off-by: Derrick Stolee's avatarDerrick Stolee <dstolee@microsoft.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      891435d5
  6. 14 Feb, 2018 1 commit
  7. 16 Oct, 2017 2 commits
  8. 08 May, 2017 4 commits
    • brian m. carlson's avatar
      object: convert parse_object* to take struct object_id · c251c83d
      brian m. carlson authored
      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: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      c251c83d
    • brian m. carlson's avatar
      Convert lookup_tree to struct object_id · 740ee055
      brian m. carlson authored
      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: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      740ee055
    • brian m. carlson's avatar
      Convert lookup_blob to struct object_id · 3aca1fc6
      brian m. carlson authored
      Convert lookup_blob to take a pointer to struct object_id.
      
      The commit was created with manual changes to blob.c and blob.h, plus
      the following semantic patch:
      
      @@
      expression E1;
      @@
      - lookup_blob(E1.hash)
      + lookup_blob(&E1)
      
      @@
      expression E1;
      @@
      - lookup_blob(E1->hash)
      + lookup_blob(E1)
      Signed-off-by: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3aca1fc6
    • brian m. carlson's avatar
      Convert lookup_commit* to struct object_id · bc83266a
      brian m. carlson authored
      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: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      bc83266a
  9. 08 Jul, 2016 1 commit
  10. 25 Apr, 2016 1 commit
  11. 15 Jan, 2016 1 commit
    • Junio C Hamano's avatar
      strbuf: introduce strbuf_getline_{lf,nul}() · 8f309aeb
      Junio C Hamano authored
      The strbuf_getline() interface allows a byte other than LF or NUL as
      the line terminator, but this is only because I wrote these
      codepaths anticipating that there might be a value other than NUL
      and LF that could be useful when I introduced line_termination long
      time ago.  No useful caller that uses other value has emerged.
      
      By now, it is clear that the interface is overly broad without a
      good reason.  Many codepaths have hardcoded preference to read
      either LF terminated or NUL terminated records from their input, and
      then call strbuf_getline() with LF or NUL as the third parameter.
      
      This step introduces two thin wrappers around strbuf_getline(),
      namely, strbuf_getline_lf() and strbuf_getline_nul(), and
      mechanically rewrites these call sites to call either one of
      them.  The changes contained in this patch are:
      
       * introduction of these two functions in strbuf.[ch]
      
       * mechanical conversion of all callers to strbuf_getline() with
         either '\n' or '\0' as the third parameter to instead call the
         respective thin wrapper.
      
      After this step, output from "git grep 'strbuf_getline('" would
      become a lot smaller.  An interim goal of this series is to make
      this an empty set, so that we can have strbuf_getline_crlf() take
      over the shorter name strbuf_getline().
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      8f309aeb
  12. 20 Nov, 2015 4 commits
  13. 05 Oct, 2015 1 commit
  14. 25 May, 2015 2 commits
  15. 17 Feb, 2015 1 commit
  16. 13 Jan, 2015 1 commit
  17. 15 Oct, 2014 1 commit
  18. 18 Sep, 2014 1 commit
  19. 03 Sep, 2014 1 commit
  20. 25 Aug, 2014 1 commit
  21. 19 Jun, 2014 1 commit
    • Jeff King's avatar
      walker_fetch: fix minor memory leak · f3320699
      Jeff King authored
      We sometimes allocate "msg" on the heap, but will fail to
      free it if we hit the failure code path. We can instead keep
      a separate variable that is safe to be freed no matter how
      we get to the failure code path.
      
      While we're here, we can also do two readability
      improvements:
      
        1. Use xstrfmt instead of a manual malloc/sprintf
      
        2. Due to the "maybe we allocate msg, maybe we don't"
           strategy, the logic for deciding which message to show
           was split into two parts. Since the deallocation is now
           pushed onto a separate variable, this is no longer a
           concern, and we can keep all of the logic in the same
           place.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      f3320699
  22. 25 Mar, 2014 1 commit
  23. 06 Jun, 2013 1 commit
    • Jeff King's avatar
      clear parsed flag when we free tree buffers · 6e454b9a
      Jeff King authored
      Many code paths will free a tree object's buffer and set it
      to NULL after finishing with it in order to keep memory
      usage down during a traversal. However, out of 8 sites that
      do this, only one actually unsets the "parsed" flag back.
      Those sites that don't are setting a trap for later users of
      the tree object; even after calling parse_tree, the buffer
      will remain NULL, causing potential segfaults.
      
      It is not known whether this is triggerable in the current
      code. Most commands do not do an in-memory traversal
      followed by actually using the objects again. However, it
      does not hurt to be safe for future callers.
      
      In most cases, we can abstract this out to a
      "free_tree_buffer" helper. However, there are two
      exceptions:
      
        1. The fsck code relies on the parsed flag to know that we
           were able to parse the object at one point. We can
           switch this to using a flag in the "flags" field.
      
        2. The index-pack code sets the buffer to NULL but does
           not free it (it is freed by a caller). We should still
           unset the parsed flag here, but we cannot use our
           helper, as we do not want to free the buffer.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      6e454b9a
  24. 05 Oct, 2011 1 commit
    • Michael Haggerty's avatar
      Change check_ref_format() to take a flags argument · 8d9c5010
      Michael Haggerty authored
      Change check_ref_format() to take a flags argument that indicates what
      is acceptable in the reference name (analogous to "git
      check-ref-format"'s "--allow-onelevel" and "--refspec-pattern").  This
      is more convenient for callers and also fixes a failure in the test
      suite (and likely elsewhere in the code) by enabling "onelevel" and
      "refspec-pattern" to be allowed independently of each other.
      
      Also rename check_ref_format() to check_refname_format() to make it
      obvious that it deals with refnames rather than references themselves.
      Signed-off-by: default avatarMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      8d9c5010
  25. 29 Nov, 2010 1 commit
  26. 23 Jul, 2009 1 commit
  27. 11 Feb, 2009 1 commit
  28. 18 Oct, 2008 1 commit