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

[PATCH 00/23] Prepare to separate out a packed_ref_store

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
May 17, 2017, 12:05 UTC
Message-ID
<cover.1495014840.git.mhagger@alum.mit.edu>

This patch series is the next leg on a journey towards reading `packed-refs` using `mmap()`, the most interesting aspect of which is that we will often be able to avoid having to read the whole `packed-refs` file if we only need a subset of references.

The first leg of the journey was separating out the reference cache into a separate module [1]. That branch is already merged to master.

This patch series prepares the ground for separating out a `packed_ref_store`, but doesn't yet take that step. (As you can see, it's a long enough patch series already!) It's kind of a grab bag of cleanup patches plus work to decouple the packed-refs handling code from the rest of `files_ref_store`. Some highlights:

* Patch 07/23 adds a log message parameter to `refs_delete_refs()` and
  `delete_refs()`, for consistency with other reference-changing
  operations. Even though `files_ref_store` is incapable of storing
  reflogs for deleted references, that is no reason that the API
  shouldn't admit the possibility for future backends.
* Patch 12/23 breaks `ref_transaction_commit()` into multiple
  functions:
  * `ref_transaction_prepare()`: do pre-checks, obtain locks, etc.; do
    everything possible to make sure that the reference update will be
    successful.
  * `ref_transaction_finish()`: actually commit a prepared
    transaction.
  * `ref_transaction_abort()`: abort a prepared transaction.
  This separation will be useful for supporting a "compound" reference
  store composed of multiple reference stores that work together
  (i.e., one for loose refs and one for packed refs).
* Patch 17/23 changes `get_packed_ref_cache()` to skip `lstat()`ing
  the packed-refs file (to check its freshness) if we already have it
  locked.
* Patch 19/23 fixes the error handling in `read_packed_refs()`: if
  `fopen()` fails due to `ENOENT`, then there are no packed refs. But
  if it fails for another reason, that is a problem that should be
  reported to the user.
* Patch 22/23 (by Peff) changes ref-filter to attempt to limit the
  reference traversal to a prefix, if there is a single
  `match_as_path` pattern that starts with non-glob characters. This
  limits the number of loose references that need to be read when
  processing a command like `git for-each-ref refs/heads/`.
* Patch 23/23 makes `cache_ref_iterator` smarter about avoiding
  "priming" directories of loose references that won't be needed,
  further reducing the number of loose references that need to be read
  in some cases of iterating over references.

These changes are also available as branch `packed-ref-store-prep` in my GitHub fork [2]. If you'd like to see a preview of the rest of the changes (which works but is not yet polished), checkout the `mmap-packed-refs` branch from the same place.

Michael
[1] http://public-inbox.org/git/cover.1490026594.git.mhagger@alum.mit.edu/
    http://public-inbox.org/git/cover.1490966385.git.mhagger@alum.mit.edu/
    http://public-inbox.org/git/cover.1492323985.git.mhagger@alum.mit.edu/
[2] https://github.com/mhagger/git
Jeff King (1):
  ref-filter: limit traversal to prefix
Michael Haggerty (22):
  t3600: clean up permissions test properly
  refs.h: clarify docstring for the ref_transaction_update()-related fns
  ref_iterator_begin_fn(): fix docstring
  prefix_ref_iterator: don't trim too much
  refs_ref_iterator_begin(): don't check prefixes redundantly
  refs: use `size_t` indexes when iterating over ref transaction updates
  ref_store: take `logmsg` parameter when deleting references
  lockfile: add a new method, is_lock_file_locked()
  files-backend: move `lock` member to `files_ref_store`
  files_ref_store: put the packed files lock directly in this struct
  files_transaction_cleanup(): new helper function
  ref_transaction_commit(): break into multiple functions
  ref_update_reject_duplicates(): expose function to whole refs module
  ref_update_reject_duplicates(): use `size_t` rather than `int`
  ref_update_reject_duplicates(): add a sanity check
  should_pack_ref(): new function, extracted from `files_pack_refs()`
  get_packed_ref_cache(): assume "packed-refs" won't change while locked
  read_packed_refs(): do more of the work of reading packed refs
  read_packed_refs(): report unexpected fopen() failures
  refs_ref_iterator_begin(): handle `GIT_REF_PARANOIA`
  create_ref_entry(): remove `check_name` option
  cache_ref_iterator_begin(): avoid priming unneeded directories
 builtin/fetch.c                |   2 +-
 builtin/remote.c               |   4 +-
 lockfile.h                     |   8 ++
 ref-filter.c                   |  62 ++++++++-
 refs.c                         |  83 ++++++++++--
 refs.h                         |  62 ++++++++-
 refs/files-backend.c           | 300 +++++++++++++++++++++++++----------------
 refs/iterator.c                |  14 +-
 refs/ref-cache.c               |  99 +++++++++++---
 refs/ref-cache.h               |   6 +-
 refs/refs-internal.h           |  56 ++++++--
 t/helper/test-ref-store.c      |   3 +-
 t/t1405-main-ref-store.sh      |   2 +-
 t/t1406-submodule-ref-store.sh |   2 +-
 t/t3600-rm.sh                  |   4 +-
 15 files changed, 538 insertions(+), 169 deletions(-)
-- 
2.11.0
Next: Michael Haggerty
Message 1 of 73 in “Prepare to separate out a packed_ref_store”
  1. 00/23 Prepare to separate out a packed_ref_storeMichael Haggerty, May 17, 2017
  2. 01/23 t3600: clean up permissions test properlyMichael Haggerty, May 17, 2017
  3. Jeff KingMay 17, 2017
  4. Michael HaggertyMay 17, 2017
  5. Junio C HamanoMay 18, 2017
  6. Michael HaggertyMay 19, 2017
  7. 02/23 refs.h: clarify docstring for the ref_transaction_update()-related fnsMichael Haggerty, May 17, 2017
  8. Stefan BellerMay 17, 2017
  9. Junio C HamanoMay 18, 2017
  10. 03/23 ref_iterator_begin_fn(): fix docstringMichael Haggerty, May 17, 2017
  11. 05/23 refs_ref_iterator_begin(): don't check prefixes redundantlyMichael Haggerty, May 17, 2017
  12. Jeff KingMay 17, 2017
  13. Michael HaggertyMay 17, 2017
  14. 07/23 ref_store: take `logmsg` parameter when deleting referencesMichael Haggerty, May 17, 2017
  15. Jeff KingMay 17, 2017
  16. Michael HaggertyMay 17, 2017
  17. Jeff KingMay 17, 2017
  18. 04/23 prefix_ref_iterator: don't trim too muchMichael Haggerty, May 17, 2017
  19. Jeff KingMay 17, 2017
  20. Michael HaggertyMay 17, 2017
  21. Jeff KingMay 17, 2017
  22. Junio C HamanoMay 18, 2017
  23. Michael HaggertyMay 18, 2017
  24. 09/23 files-backend: move `lock` member to `files_ref_store`Michael Haggerty, May 17, 2017
  25. Jeff KingMay 17, 2017
  26. Michael HaggertyMay 17, 2017
  27. 06/23 refs: use `size_t` indexes when iterating over ref transaction updatesMichael Haggerty, May 17, 2017
  28. Stefan BellerMay 17, 2017
  29. Michael HaggertyMay 18, 2017
  30. 10/23 files_ref_store: put the packed files lock directly in this structMichael Haggerty, May 17, 2017
  31. Jeff KingMay 17, 2017
  32. Michael HaggertyMay 17, 2017
  33. Stefan BellerMay 17, 2017
  34. Brandon WilliamsMay 18, 2017
  35. Michael HaggertyMay 19, 2017
  36. Brandon WilliamsMay 18, 2017
  37. Jeff KingMay 18, 2017
  38. Brandon WilliamsMay 18, 2017
  39. 12/23 ref_transaction_commit(): break into multiple functionsMichael Haggerty, May 17, 2017
  40. Stefan BellerMay 17, 2017
  41. Michael HaggertyMay 19, 2017
  42. 16/23 should_pack_ref(): new function, extracted from `files_pack_refs()`Michael Haggerty, May 17, 2017
  43. 17/23 get_packed_ref_cache(): assume "packed-refs" won't change while lockedMichael Haggerty, May 17, 2017
  44. Stefan BellerMay 17, 2017
  45. Jeff KingMay 18, 2017
  46. Stefan BellerMay 18, 2017
  47. 18/23 read_packed_refs(): do more of the work of reading packed refsMichael Haggerty, May 17, 2017
  48. 19/23 read_packed_refs(): report unexpected fopen() failuresMichael Haggerty, May 17, 2017
  49. Jeff KingMay 17, 2017
  50. Michael HaggertyMay 17, 2017
  51. Junio C HamanoMay 18, 2017
  52. Jeff KingMay 18, 2017
  53. 15/23 ref_update_reject_duplicates(): add a sanity checkMichael Haggerty, May 17, 2017
  54. 20/23 refs_ref_iterator_begin(): handle `GIT_REF_PARANOIA`Michael Haggerty, May 17, 2017
  55. Jeff KingMay 17, 2017
  56. 22/23 ref-filter: limit traversal to prefixMichael Haggerty, May 17, 2017
  57. Jeff KingMay 17, 2017
  58. Michael HaggertyMay 19, 2017
  59. 14/23 ref_update_reject_duplicates(): use `size_t` rather than `int`Michael Haggerty, May 17, 2017
  60. 23/23 cache_ref_iterator_begin(): avoid priming unneeded directoriesMichael Haggerty, May 17, 2017
  61. 21/23 create_ref_entry(): remove `check_name` optionMichael Haggerty, May 17, 2017
  62. 08/23 lockfile: add a new method, is_lock_file_locked()Michael Haggerty, May 17, 2017
  63. Jeff KingMay 17, 2017
  64. 11/23 files_transaction_cleanup(): new helper functionMichael Haggerty, May 17, 2017
  65. Jeff KingMay 17, 2017
  66. Michael HaggertyMay 19, 2017
  67. Stefan BellerMay 17, 2017
  68. Michael HaggertyMay 19, 2017
  69. 13/23 ref_update_reject_duplicates(): expose function to whole refs moduleMichael Haggerty, May 17, 2017
  70. Jeff KingMay 17, 2017
  71. Stefan BellerMay 17, 2017
  72. Johannes SixtMay 18, 2017
  73. Jeff KingMay 18, 2017

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.