Re: [PATCH v5 1/5] eoie: add End of Index Entry (EOIE) extension

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 9/15/2018 6:02 AM, Duy Nguyen wrote:

         default:
                 if (*ext < 'A' || 'Z' < *ext)
                         return error("index uses %.4s extension, which we do not understand",
@@ -1889,6 +1893,11 @@ static size_t estimate_cache_size(size_t ondisk_size, unsigned int entries)
         return ondisk_size + entries * per_entry;
  }

+#ifndef NO_PTHREADS
+static unsigned long read_eoie_extension(void *mmap_, size_t mmap_size);
+#endif

Keep functions unconditionally built as much as possible. I don't see
why this read_eoie_extension() must be built only on multithread
platforms.


This is conditional to avoid generating a warning on single threaded platforms where the function is currently unused. That seemed like a better choice than calling it and ignoring it on single threaded platforms just to avoid a compiler warning.

+static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, unsigned long offset);
+
  /* remember to discard_cache() before reading a different cache! */
  int do_read_index(struct index_state *istate, const char *path, int must_exist)
  {
@@ -2198,11 +2207,15 @@ static int ce_write(git_hash_ctx *context, int fd, void *data, unsigned int len)
         return 0;
  }

-static int write_index_ext_header(git_hash_ctx *context, int fd,
-                                 unsigned int ext, unsigned int sz)
+static int write_index_ext_header(git_hash_ctx *context, git_hash_ctx *eoie_context,
+                                 int fd, unsigned int ext, unsigned int sz)
  {
         ext = htonl(ext);
         sz = htonl(sz);
+       if (eoie_context) {
+               the_hash_algo->update_fn(eoie_context, &ext, 4);
+               the_hash_algo->update_fn(eoie_context, &sz, 4);
+       }
         return ((ce_write(context, fd, &ext, 4) < 0) ||
                 (ce_write(context, fd, &sz, 4) < 0)) ? -1 : 0;
  }
@@ -2445,7 +2458,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
  {
         uint64_t start = getnanotime();
         int newfd = tempfile->fd;
-       git_hash_ctx c;
+       git_hash_ctx c, eoie_c;
         struct cache_header hdr;
         int i, err = 0, removed, extended, hdr_version;
         struct cache_entry **cache = istate->cache;
@@ -2454,6 +2467,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
         struct ondisk_cache_entry_extended ondisk;
         struct strbuf previous_name_buf = STRBUF_INIT, *previous_name;
         int drop_cache_tree = istate->drop_cache_tree;
+       unsigned long offset;

         for (i = removed = extended = 0; i < entries; i++) {
                 if (cache[i]->ce_flags & CE_REMOVE)
@@ -2520,11 +2534,13 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
                 return err;

         /* Write extension data here */
+       offset = lseek(newfd, 0, SEEK_CUR) + write_buffer_len;
+       the_hash_algo->init_fn(&eoie_c);

Don't write (or even calculate to write it) unless it's needed. Which
means only do this when parallel reading is enabled and the index size
large enough, or when a test variable is set so you can force writing
this extension.

I made the logic always write the extension based on the earlier discussion [1] where it was suggested this should have been part of the original index format for extensions from the beginning. This helps ensure it is available for current and future uses we haven't even discovered yet.

[1] https://public-inbox.org/git/xmqqwp2s1h1x.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxxx/


+
+static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, unsigned long offset)

We normally just put function implementations before it's used to
avoid static forward declaration. Any special reason why it's not done
here?


This was done to promote readability of the (already large) read-cache.c file. I first considered moving the EOIE read/write functions into a separate file entirely but they need access to information only available within read-cache.c so I compromised and moved them to the end of the file instead.

+{
+       uint32_t buffer;
+       unsigned char hash[GIT_MAX_RAWSZ];
+
+       /* offset */
+       put_be32(&buffer, offset);
+       strbuf_add(sb, &buffer, sizeof(uint32_t));
+
+       /* hash */
+       the_hash_algo->final_fn(hash, eoie_context);
+       strbuf_add(sb, hash, the_hash_algo->rawsz);
+}
diff --git a/t/README b/t/README
index 9028b47d92..d8754dd23a 100644
--- a/t/README
+++ b/t/README
@@ -319,6 +319,11 @@ GIT_TEST_OE_DELTA_SIZE=<n> exercises the uncomon pack-objects code
  path where deltas larger than this limit require extra memory
  allocation for bookkeeping.

+GIT_TEST_DISABLE_EOIE=<boolean> disables writing the EOIE extension.
+This is used to allow tests 1, 4-9 in t1700-split-index.sh to succeed

I have a feeling that you won't have problems if you don't write eoie
extension by default in the first place. Then this could be switched
to GIT_TEST_ENABLE_EOIE instead. We may still have problem if both
eoie and split index are forced on when running through the test
suite, but that should be an easy fix.

+as they currently hard code SHA values for the index which are no longer
+valid due to the addition of the EOIE extension.
+
  Naming Tests
  ------------

diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh
index 39133bcbc8..f613dd72e3 100755
--- a/t/t1700-split-index.sh
+++ b/t/t1700-split-index.sh
@@ -7,6 +7,7 @@ test_description='split index mode tests'
  # We need total control of index splitting here
  sane_unset GIT_TEST_SPLIT_INDEX
  sane_unset GIT_FSMONITOR_TEST
+export GIT_TEST_DISABLE_EOIE=true

  test_expect_success 'enable split index' '
         git config splitIndex.maxPercentChange 100 &&
--
2.18.0.windows.1






[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux