1. 28 1月, 2019 1 次提交
    • S
      object_as_type: initialize commit-graph-related fields of 'struct commit' · 4468d443
      SZEDER Gábor 提交于
      When the commit graph and generation numbers were introduced in
      commits 177722b3 (commit: integrate commit graph with commit
      parsing, 2018-04-10) and 83073cc9 (commit: add generation number to
      struct commit, 2018-04-25), they tried to make sure that the
      corresponding 'graph_pos' and 'generation' fields of 'struct commit'
      are initialized conservatively, as if the commit were not included in
      the commit-graph file.
      
      Alas, initializing those fields only in alloc_commit_node() missed the
      case when an object that happens to be a commit is first looked up via
      lookup_unknown_object(), and is then later converted to a 'struct
      commit' via the object_as_type() helper function (either calling it
      directly, or as part of a subsequent lookup_commit() call).
      Consequently, both of those fields incorrectly remain set to zero,
      which means e.g. that the commit is present in and is the first entry
      of the commit-graph file.  This will result in wrong timestamp, parent
      and root tree hashes, if such a 'struct commit' instance is later
      filled from the commit-graph.
      
      Extract the initialization of 'struct commit's fields from
      alloc_commit_node() into a helper function, and call it from
      object_as_type() as well, to make sure that it properly initializes
      the two commit-graph-related fields, too.  With this helper function
      it is hopefully less likely that any new fields added to 'struct
      commit' in the future would remain uninitialized.
      
      With this change alloc_commit_index() won't have any remaining callers
      outside of 'alloc.c', so mark it as static.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4468d443
  2. 09 1月, 2019 2 次提交
  3. 29 12月, 2018 1 次提交
  4. 14 11月, 2018 1 次提交
  5. 13 11月, 2018 3 次提交
    • J
      sha1-file: use an object_directory for the main object dir · f0eaf638
      Jeff King 提交于
      Our handling of alternate object directories is needlessly different
      from the main object directory. As a result, many places in the code
      basically look like this:
      
        do_something(r->objects->objdir);
      
        for (odb = r->objects->alt_odb_list; odb; odb = odb->next)
              do_something(odb->path);
      
      That gets annoying when do_something() is non-trivial, and we've
      resorted to gross hacks like creating fake alternates (see
      find_short_object_filename()).
      
      Instead, let's give each raw_object_store a unified list of
      object_directory structs. The first will be the main store, and
      everything after is an alternate. Very few callers even care about the
      distinction, and can just loop over the whole list (and those who care
      can just treat the first element differently).
      
      A few observations:
      
        - we don't need r->objects->objectdir anymore, and can just
          mechanically convert that to r->objects->odb->path
      
        - object_directory's path field needs to become a real pointer rather
          than a FLEX_ARRAY, in order to fill it with expand_base_dir()
      
        - we'll call prepare_alt_odb() earlier in many functions (i.e.,
          outside of the loop). This may result in us calling it even when our
          function would be satisfied looking only at the main odb.
      
          But this doesn't matter in practice. It's not a very expensive
          operation in the first place, and in the majority of cases it will
          be a noop. We call it already (and cache its results) in
          prepare_packed_git(), and we'll generally check packs before loose
          objects. So essentially every program is going to call it
          immediately once per program.
      
          Arguably we should just prepare_alt_odb() immediately upon setting
          up the repository's object directory, which would save us sprinkling
          calls throughout the code base (and forgetting to do so has been a
          source of subtle bugs in the past). But I've stopped short of that
          here, since there are already a lot of other moving parts in this
          patch.
      
        - Most call sites just get shorter. The check_and_freshen() functions
          are an exception, because they have entry points to handle local and
          nonlocal directories separately.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f0eaf638
    • J
      handle alternates paths the same as the main object dir · f3f043a1
      Jeff King 提交于
      When we generate loose file paths for the main object directory, the
      caller provides a buffer to loose_object_path (formerly sha1_file_name).
      The callers generally keep their own static buffer to avoid excessive
      reallocations.
      
      But for alternate directories, each struct carries its own scratch
      buffer. This is needlessly different; let's unify them.
      
      We could go either direction here, but this patch moves the alternates
      struct over to the main directory style (rather than vice-versa).
      Technically the alternates style is more efficient, as it avoids
      rewriting the object directory name on each call. But this is unlikely
      to matter in practice, as we avoid reallocations either way (and nobody
      has ever noticed or complained that the main object directory is copying
      a few extra bytes before making a much more expensive system call).
      
      And this has the advantage that the reusable buffers are tied to
      particular calls, which makes the invalidation rules simpler (for
      example, the return value from stat_sha1_file() used to be invalidated
      by basically any other object call, but now it is affected only by other
      calls to stat_sha1_file()).
      
      We do steal the trick from alt_sha1_path() of returning a pointer to the
      filled buffer, which makes a few conversions more convenient.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f3f043a1
    • J
      rename "alternate_object_database" to "object_directory" · 263db403
      Jeff King 提交于
      In preparation for unifying the handling of alt odb's and the normal
      repo object directory, let's use a more neutral name. This patch is
      purely mechanical, swapping the type name, and converting any variables
      named "alt" to "odb". There should be no functional change, but it will
      reduce the noise in subsequent diffs.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      263db403
  6. 30 8月, 2018 1 次提交
    • J
      convert "hashcmp() == 0" to hasheq() · e3ff0683
      Jeff King 提交于
      This is the partner patch to the previous one, but covering
      the "hash" variants instead of "oid".  Note that our
      coccinelle rule is slightly more complex to avoid triggering
      the call in hasheq().
      
      I didn't bother to add a new rule to convert:
      
        - hasheq(E1->hash, E2->hash)
        + oideq(E1, E2)
      
      Since these are new functions, there won't be any such
      existing callers. And since most of the code is already
      using oideq, we're not likely to introduce new ones.
      
      We might still see "!hashcmp(E1->hash, E2->hash)" from topics
      in flight. But because our new rule comes after the existing
      ones, that should first get converted to "!oidcmp(E1, E2)"
      and then to "oideq(E1, E2)".
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e3ff0683
  7. 24 7月, 2018 1 次提交
  8. 18 7月, 2018 1 次提交
  9. 30 6月, 2018 17 次提交
  10. 22 5月, 2018 1 次提交
    • D
      commit-graph: always load commit-graph information · e2838d85
      Derrick Stolee 提交于
      Most code paths load commits using lookup_commit() and then
      parse_commit(). In some cases, including some branch lookups, the commit
      is parsed using parse_object_buffer() which side-steps parse_commit() in
      favor of parse_commit_buffer().
      
      With generation numbers in the commit-graph, we need to ensure that any
      commit that exists in the commit-graph file has its generation number
      loaded.
      
      Create new load_commit_graph_info() method to fill in the information
      for a commit that exists only in the commit-graph file. Call it from
      parse_commit_buffer() after loading the other commit information from
      the given buffer. Only fill this information when specified by the
      'check_graph' parameter.
      Signed-off-by: NDerrick Stolee <dstolee@microsoft.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e2838d85
  11. 18 5月, 2018 2 次提交
  12. 16 5月, 2018 2 次提交
  13. 10 5月, 2018 1 次提交
  14. 09 5月, 2018 6 次提交