git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 03/27] sparse-index: API protection strategy

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 16, 2021, 21:16 UTC
Message-ID
<bbf19f8a2be599a3451469731eed2eada7d3456a.1615929436.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.906.git.1615929435.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>

Edit and expand the sparse-index design document with the plan for guarding index operations with ensure_full_index().

Notably, the plan has changed to not have an expand_to_path() method in favor of checking for a sparse-directory hit inside of the index_path_pos() API.

The changes that follow this one will incrementally add ensure_full_index() guards to iterations over all cache entries. Some iterations over the cache entries are not protected due to a few categories listed in the document. Since these are not being modified, here is a short list of the files and methods that will not receive these guards:

Looking for non-zero stage:
* builtin/add.c:chmod_pathspec()
* builtin/merge.c:count_unmerged_entries()
* read-cache.c:unmerged_index()
* rerere.c:check_one_conflict(), find_conflict(), rerere_remaining()
* revision.c:prepare_show_merge()
* sequencer.c:append_conflicts_hint()
* wt-status.c:wt_status_collect_changes_initial()
Looking for submodules:
* builtin/submodule--helper.c:module_list_compute()
* submodule.c: several methods
* worktree.c:validate_no_submodules()
Part of the index API:
* name-hash.c: lazy init methods
* preload-index.c:preload_thread(), preload_index()
* read-cache.c: file format methods
Checking for correct order of cache entries:
* read-cache.c:check_ce_order()
Ignores SKIP_WORKTREE entries or already aware:
* unpack-trees.c:mark_new_skip_worktree()
* wt-status.c:wt_status_check_sparse_checkout()
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 Documentation/technical/sparse-index.txt | 32 +++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/Documentation/technical/sparse-index.txt b/Documentation/technical/sparse-index.txt
index aa116406a016..7ab51bf6c441 100644
--- a/Documentation/technical/sparse-index.txt
+++ b/Documentation/technical/sparse-index.txt
@@ -82,9 +82,35 @@ also introduce other features that have been considered for improving the
 index, as well.
 
 Next, consumers of the index will be guarded against operating on a
-sparse-index by inserting calls to `ensure_full_index()` or
-`expand_index_to_path()`. After these guards are in place, we can begin
-leaving sparse-directory entries in the in-memory index structure.
+sparse-index by inserting calls to `ensure_full_index()` before iterating
+over all cache entries. If a specific path is requested, then those will
+be protected from within the `index_file_exists()` and `index_name_pos()`
+API calls: they will call `ensure_full_index()` if necessary.
+
+During a scan of the codebase, not every iteration of the cache entries
+needs an `ensure_full_index()` check. The basic reasons include:
+
+1. The loop is scanning for entries with non-zero stage. These entries
+   are not collapsed into a sparse-directory entry.
+
+2. The loop is scanning for submodules. These entries are not collapsed
+   into a sparse-directory entry.
+
+3. The loop is part of the index API, especially around reading or
+   writing the format.
+
+4. The loop is checking for correct order of cache entries and that is
+   correct if and only if the sparse-directory entries are in the correct
+   location.
+
+5. The loop ignores entries with the `SKIP_WORKTREE` bit set, or is
+   otherwise already aware of sparse directory entries.
+
+6. The sparse-index is disabled at this point when using the split-index
+   feature, so no effort is made to protect the split-index API.
+
+After these guards are in place, we can begin leaving sparse-directory
+entries in the in-memory index structure.
 
 Even after inserting these guards, we will keep expanding sparse-indexes
 for most Git commands using the `command_requires_full_index` repository
-- 
gitgitgadget
Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee via GitGitGadget
Message 3 of 111 in “Sparse Index: API protections”
  1. 00/27 Sparse Index: API protectionsDerrick Stolee via GitGitGadget, Mar 16, 2021
  2. 02/27 read-cache: expand on query into sparse-directory entryDerrick Stolee via GitGitGadget, Mar 16, 2021
  3. 03/27 sparse-index: API protection strategyDerrick Stolee via GitGitGadget, Mar 16, 2021
  4. 04/27 cache: move ensure_full_index() to cache.hDerrick Stolee via GitGitGadget, Mar 16, 2021
  5. 01/27 *: remove 'const' qualifier for struct index_stateDerrick Stolee via GitGitGadget, Mar 16, 2021
  6. Junio C HamanoMar 19, 2021
  7. Derrick StoleeMar 20, 2021
  8. Junio C HamanoMar 20, 2021
  9. Derrick StoleeMar 30, 2021
  10. 13/27 merge-index: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  11. 12/27 ls-files: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  12. 08/27 commit: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  13. 05/27 add: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  14. Elijah NewrenMar 17, 2021
  15. Matheus Tavares BernardinoMar 17, 2021
  16. Derrick StoleeMar 17, 2021
  17. 07/27 checkout: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  18. 09/27 difftool: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  19. 15/27 sparse-checkout: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  20. Elijah NewrenMar 18, 2021
  21. Derrick StoleeMar 23, 2021
  22. 14/27 rm: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  23. 10/27 fsck: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  24. 11/27 grep: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  25. 27/27 name-hash: use expand_to_path()Derrick Stolee via GitGitGadget, Mar 16, 2021
  26. 16/27 update-index: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  27. 06/27 checkout-index: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  28. Elijah NewrenMar 17, 2021
  29. Derrick StoleeMar 17, 2021
  30. Elijah NewrenMar 17, 2021
  31. Derrick StoleeMar 17, 2021
  32. Elijah NewrenMar 17, 2021
  33. Derrick StoleeMar 18, 2021
  34. 18/27 dir: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  35. 17/27 diff-lib: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  36. Elijah NewrenMar 18, 2021
  37. Derrick StoleeMar 23, 2021
  38. 26/27 sparse-index: expand_to_path()Derrick Stolee via GitGitGadget, Mar 16, 2021
  39. 23/27 read-cache: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  40. 24/27 resolve-undo: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  41. 21/27 merge-recursive: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  42. 19/27 entry: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  43. 25/27 revision: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  44. 20/27 merge-ort: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  45. Elijah NewrenMar 18, 2021
  46. Derrick StoleeMar 23, 2021
  47. 22/27 pathspec: ensure full indexDerrick Stolee via GitGitGadget, Mar 16, 2021
  48. Elijah NewrenMar 17, 2021
  49. Elijah NewrenMar 18, 2021
  50. 00/25 Sparse Index: API protectionsDerrick Stolee via GitGitGadget, Apr 1, 2021
  51. 01/25 sparse-index: API protection strategyDerrick Stolee via GitGitGadget, Apr 1, 2021
  52. 03/25 read-cache: expand on query into sparse-directory entryDerrick Stolee via GitGitGadget, Apr 1, 2021
  53. 04/25 cache: move ensure_full_index() to cache.hDerrick Stolee via GitGitGadget, Apr 1, 2021
  54. 05/25 add: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  55. 02/25 *: remove 'const' qualifier for struct index_stateDerrick Stolee via GitGitGadget, Apr 1, 2021
  56. 10/25 fsck: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  57. 06/25 checkout-index: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  58. 08/25 commit: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  59. 11/25 grep: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  60. 07/25 checkout: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  61. 17/25 dir: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  62. 12/25 ls-files: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  63. 15/25 stash: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  64. 14/25 rm: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  65. 09/25 difftool: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  66. 19/25 merge-recursive: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  67. 20/25 pathspec: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  68. 18/25 entry: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  69. 13/25 merge-index: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  70. 21/25 read-cache: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  71. 23/25 revision: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  72. 22/25 resolve-undo: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  73. 24/25 sparse-index: expand_to_path()Derrick Stolee via GitGitGadget, Apr 1, 2021
  74. Elijah NewrenApr 5, 2021
  75. Derrick StoleeApr 6, 2021
  76. 25/25 name-hash: use expand_to_path()Derrick Stolee via GitGitGadget, Apr 1, 2021
  77. Elijah NewrenApr 5, 2021
  78. 16/25 update-index: ensure full indexDerrick Stolee via GitGitGadget, Apr 1, 2021
  79. Junio C HamanoApr 1, 2021
  80. Derrick StoleeApr 1, 2021
  81. Elijah NewrenApr 5, 2021
  82. 00/26 Sparse Index: API protectionsDerrick Stolee via GitGitGadget, Apr 12, 2021
  83. 01/26 sparse-index: API protection strategyDerrick Stolee via GitGitGadget, Apr 12, 2021
  84. 03/26 read-cache: expand on query into sparse-directory entryDerrick Stolee via GitGitGadget, Apr 12, 2021
  85. 02/26 *: remove 'const' qualifier for struct index_stateDerrick Stolee via GitGitGadget, Apr 12, 2021
  86. 08/26 commit: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  87. 06/26 checkout-index: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  88. 07/26 checkout: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  89. 05/26 add: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  90. 04/26 cache: move ensure_full_index() to cache.hDerrick Stolee via GitGitGadget, Apr 12, 2021
  91. 09/26 difftool: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  92. 12/26 ls-files: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  93. 13/26 merge-index: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  94. 14/26 rm: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  95. 15/26 stash: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  96. 16/26 update-index: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  97. 17/26 dir: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  98. 18/26 entry: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  99. 19/26 merge-recursive: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  100. 24/26 name-hash: don't add directories to name_hashDerrick Stolee via GitGitGadget, Apr 12, 2021
  101. 23/26 revision: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  102. 22/26 resolve-undo: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  103. 21/26 read-cache: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  104. 20/26 pathspec: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  105. 26/26 name-hash: use expand_to_path()Derrick Stolee via GitGitGadget, Apr 12, 2021
  106. 25/26 sparse-index: expand_to_path()Derrick Stolee via GitGitGadget, Apr 12, 2021
  107. 10/26 fsck: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  108. 11/26 grep: ensure full indexDerrick Stolee via GitGitGadget, Apr 12, 2021
  109. Elijah NewrenApr 13, 2021
  110. Junio C HamanoApr 14, 2021
  111. Derrick StoleeApr 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.