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

[PATCH v2 00/18] Consolidate reachability logic

From
Derrick Stolee <dstolee@microsoft.com>
Date
Jul 20, 2018, 16:33 UTC
Message-ID
<20180720163227.105950-1-dstolee@microsoft.com>
In-Reply-To
<pull.10.git.gitgitgadget@gmail.com>

There are many places in Git that use a commit walk to determine reachability between commits and/or refs. A lot of this logic is duplicated.

I wanted to achieve the following:

Consolidate several different commit walks into one file Reduce duplicate reachability logic Increase testability (correctness and performance) Improve performance of reachability queries My approach is mostly in three parts:

I. Move code to a new commit-reach.c file. II. Add a 'test-tool reach' command to test these methods directly. III. Modify the logic by improving performance and calling methods with similar logic but different prototypes.

The 'test-tool reach' command is helpful to make sure I don't break anything as I change the logic, but also so I can test methods that are normally only exposed by other more complicated commands. For instance, ref_newer() is part of 'git push -f' and ok_to_give_up() is buried deep within fetch negotiation. Both of these methods have some problematic performance issues that are corrected by this series. As I discovered them, it was clear that it would be better to consolidate walk logic instead of discovering a new walk in another file hidden somewhere.

For the ok_to_give_up() method, I refactored the method so I could pull the logic out of the depths of fetch negotiation. In the commit "commit-reach: make can_all_from_reach... linear" I discuss how the existing algorithm is quadratic and how we can make it linear. Also, we can use heuristic knowledge about the shape of the commit graph and the usual haves/wants to get some extra performance bonus. (The heuristic is to do a DFS with first-parents first, and stop on first found result. We expect haves/wants to include ref tips, which typically have their previous values in their first-parent history.)

One major difference in this series versus the RFC is that I added a new method 'generation_numbers_enabled()' to detect if we have a commit-graph file with non-zero generation numbers. Using can_all_from_reach in is_descendant_of is only faster if we have generation numbers as a cutoff.

V2 Update: The biggest material change in this version is that we drop the method declarations from commit.h, which requires adding a lot of references to commit-reach.h across the codebase. This change is in a commit on its own. In addition, we have the following smaller changes:

* Use 'unsigned int' for the flag variables.
* Properly align the here-doc test input data.
* Use single rev-parse commands in test output, and pipe the OIDs through 'sort'
* Check output of parse_commit()
* Update flag documentation in object.h
* Add tests for commit_contains() including both algorithms.
* Reduce size of "mixed-mode" commit-graph to ensure we start commit walks
  'above' the graph and then walk into the commits with generation numbers.

Thanks, -Stolee

This series is based on jt/commit-graph-per-object-store
Derrick Stolee (18):
  commit-reach: move walk methods from commit.c
  commit.h: remove method declarations
  commit-reach: move ref_newer from remote.c
  commit-reach: move commit_contains from ref-filter
  upload-pack: make reachable() more generic
  upload-pack: refactor ok_to_give_up()
  upload-pack: generalize commit date cutoff
  commit-reach: move can_all_from_reach_with_flags
  test-reach: create new test tool for ref_newer
  test-reach: test in_merge_bases
  test-reach: test is_descendant_of
  test-reach: test get_merge_bases_many
  test-reach: test reduce_heads
  test-reach: test can_all_from_reach_with_flags
  test-reach: test commit_contains
  commit-reach: replace ref_newer logic
  commit-reach: make can_all_from_reach... linear
  commit-reach: use can_all_from_reach
 Makefile                |   2 +
 bisect.c                |   1 +
 builtin/branch.c        |   1 +
 builtin/commit.c        |   1 +
 builtin/fetch.c         |   1 +
 builtin/fmt-merge-msg.c |   1 +
 builtin/log.c           |   1 +
 builtin/merge-base.c    |   1 +
 builtin/merge.c         |   1 +
 builtin/pull.c          |   1 +
 builtin/receive-pack.c  |   1 +
 builtin/remote.c        |   1 +
 builtin/rev-parse.c     |   1 +
 commit-graph.c          |  18 ++
 commit-graph.h          |   6 +
 commit-reach.c          | 662 ++++++++++++++++++++++++++++++++++++++++
 commit-reach.h          |  77 +++++
 commit.c                | 358 ----------------------
 commit.h                |  29 --
 fast-import.c           |   1 +
 http-push.c             |   2 +-
 merge-recursive.c       |   1 +
 notes-merge.c           |   1 +
 object.h                |   4 +-
 pack-bitmap-write.c     |   1 +
 ref-filter.c            | 146 +--------
 remote.c                |  50 +--
 remote.h                |   1 -
 revision.c              |   1 +
 sequencer.c             |   1 +
 sha1-name.c             |   1 +
 shallow.c               |   1 +
 submodule.c             |   1 +
 t/helper/test-reach.c   | 130 ++++++++
 t/helper/test-tool.c    |   1 +
 t/helper/test-tool.h    |   1 +
 t/t6600-test-reach.sh   | 242 +++++++++++++++
 upload-pack.c           |  58 +---
 38 files changed, 1177 insertions(+), 631 deletions(-)
 create mode 100644 commit-reach.c
 create mode 100644 commit-reach.h
 create mode 100644 t/helper/test-reach.c
 create mode 100755 t/t6600-test-reach.sh
-- 
2.18.0.118.gd4f65b8d14
Previous: Johannes SchindelinNext: Derrick Stolee
Message 78 of 118 in “Consolidate reachability logic”
  1. 00/16 Consolidate reachability logicDerrick Stolee via GitGitGadget, Jul 16, 2018
  2. 04/16 upload-pack: make reachable() more genericDerrick Stolee via GitGitGadget, Jun 19, 2018
  3. 05/16 upload-pack: refactor ok_to_give_up()Derrick Stolee via GitGitGadget, Jun 19, 2018
  4. 01/16 commit-reach: move walk methods from commit.cDerrick Stolee via GitGitGadget, Jun 25, 2018
  5. Stefan BellerJul 16, 2018
  6. Jonathan TanJul 16, 2018
  7. 02/16 commit-reach: move ref_newer from remote.cDerrick Stolee via GitGitGadget, Jun 25, 2018
  8. Stefan BellerJul 16, 2018
  9. 03/16 commit-reach: move commit_contains from ref-filterDerrick Stolee via GitGitGadget, Jun 25, 2018
  10. Stefan BellerJul 16, 2018
  11. 15/16 commit-reach: make can_all_from_reach... linearDerrick Stolee via GitGitGadget, Jun 28, 2018
  12. Stefan BellerJul 16, 2018
  13. Jonathan TanJul 17, 2018
  14. René ScharfeOct 1, 2018
  15. Derrick StoleeOct 1, 2018
  16. René ScharfeOct 1, 2018
  17. René ScharfeOct 4, 2018
  18. Derrick StoleeOct 5, 2018
  19. Jeff KingOct 5, 2018
  20. René ScharfeOct 5, 2018
  21. Jeff KingOct 5, 2018
  22. René ScharfeOct 5, 2018
  23. Jeff KingOct 5, 2018
  24. René ScharfeOct 14, 2018
  25. Derrick StoleeOct 15, 2018
  26. René ScharfeOct 15, 2018
  27. Junio C HamanoOct 16, 2018
  28. Jeff KingOct 17, 2018
  29. Jonathan NiederNov 18, 2020
  30. Jeff KingNov 18, 2020
  31. René ScharfeNov 18, 2020
  32. Ævar Arnfjörð BjarmasonOct 5, 2018
  33. Jeff KingOct 5, 2018
  34. Ævar Arnfjörð BjarmasonOct 5, 2018
  35. Jeff KingOct 5, 2018
  36. 06/16 upload-pack: generalize commit date cutoffDerrick Stolee via GitGitGadget, Jul 12, 2018
  37. Stefan BellerJul 16, 2018
  38. Derrick StoleeJul 18, 2018
  39. 07/16 commit-reach: move can_all_from_reach_with_flagsDerrick Stolee via GitGitGadget, Jul 12, 2018
  40. Jonathan TanJul 16, 2018
  41. 08/16 test-reach: create new test tool for ref_newerDerrick Stolee via GitGitGadget, Jul 13, 2018
  42. Jonathan TanJul 16, 2018
  43. Derrick StoleeJul 18, 2018
  44. 09/16 test-reach: test in_merge_basesDerrick Stolee via GitGitGadget, Jul 13, 2018
  45. 10/16 test-reach: test is_descendant_ofDerrick Stolee via GitGitGadget, Jul 13, 2018
  46. 11/16 test-reach: test get_merge_bases_manyDerrick Stolee via GitGitGadget, Jul 13, 2018
  47. Stefan BellerJul 16, 2018
  48. Jonathan TanJul 16, 2018
  49. 12/16 test-reach: test reduce_headsDerrick Stolee via GitGitGadget, Jul 13, 2018
  50. Stefan BellerJul 16, 2018
  51. Eric SunshineJul 16, 2018
  52. 13/16 test-reach: test can_all_from_reach_with_flagsDerrick Stolee via GitGitGadget, Jul 13, 2018
  53. Stefan BellerJul 16, 2018
  54. Derrick StoleeJul 18, 2018
  55. Jonathan TanJul 17, 2018
  56. 14/16 commit-reach: replace ref_newer logicDerrick Stolee via GitGitGadget, Jul 13, 2018
  57. Stefan BellerJul 16, 2018
  58. 16/16 commit-reach: use can_all_from_reachDerrick Stolee via GitGitGadget, Jul 13, 2018
  59. Stefan BellerJul 16, 2018
  60. Ramsay JonesJul 16, 2018
  61. Jeff KingJul 16, 2018
  62. Eric SunshineJul 16, 2018
  63. Jeff KingJul 16, 2018
  64. Eric SunshineJul 16, 2018
  65. Johannes SchindelinJul 18, 2018
  66. Johannes SchindelinJul 18, 2018
  67. Jeff KingJul 18, 2018
  68. Johannes SchindelinJul 19, 2018
  69. Stefan BellerJul 16, 2018
  70. Eric SunshineJul 16, 2018
  71. Derrick StoleeJul 16, 2018
  72. Johannes SchindelinJul 18, 2018
  73. Duy NguyenJul 18, 2018
  74. Junio C HamanoJul 18, 2018
  75. Derrick StoleeJul 18, 2018
  76. Johannes SchindelinJul 19, 2018
  77. Johannes SchindelinJul 19, 2018
  78. 00/18 Consolidate reachability logicDerrick Stolee, Jul 20, 2018
  79. 02/18 commit.h: remove method declarationsDerrick Stolee, Jul 20, 2018
  80. 03/18 commit-reach: move ref_newer from remote.cDerrick Stolee, Jul 20, 2018
  81. 04/18 commit-reach: move commit_contains from ref-filterDerrick Stolee, Jul 20, 2018
  82. Jonathan NiederAug 28, 2018
  83. Derrick StoleeAug 28, 2018
  84. commit-reach: correct accidental #include of C fileJonathan Nieder, Aug 28, 2018
  85. Derrick StoleeAug 28, 2018
  86. 05/18 upload-pack: make reachable() more genericDerrick Stolee, Jul 20, 2018
  87. 07/18 upload-pack: generalize commit date cutoffDerrick Stolee, Jul 20, 2018
  88. 06/18 upload-pack: refactor ok_to_give_up()Derrick Stolee, Jul 20, 2018
  89. 09/18 test-reach: create new test tool for ref_newerDerrick Stolee, Jul 20, 2018
  90. 08/18 commit-reach: move can_all_from_reach_with_flagsDerrick Stolee, Jul 20, 2018
  91. 11/18 test-reach: test is_descendant_ofDerrick Stolee, Jul 20, 2018
  92. 12/18 test-reach: test get_merge_bases_manyDerrick Stolee, Jul 20, 2018
  93. 10/18 test-reach: test in_merge_basesDerrick Stolee, Jul 20, 2018
  94. 14/18 test-reach: test can_all_from_reach_with_flagsDerrick Stolee, Jul 20, 2018
  95. 15/18 test-reach: test commit_containsDerrick Stolee, Jul 20, 2018
  96. Jonathan TanJul 23, 2018
  97. Junio C HamanoJul 25, 2018
  98. Derrick StoleeJul 25, 2018
  99. 16/18 commit-reach: replace ref_newer logicDerrick Stolee, Jul 20, 2018
  100. 01/18 commit-reach: move walk methods from commit.cDerrick Stolee, Jul 20, 2018
  101. 18/18 commit-reach: use can_all_from_reachDerrick Stolee, Jul 20, 2018
  102. 17/18 commit-reach: make can_all_from_reach... linearDerrick Stolee, Jul 20, 2018
  103. Jonathan TanJul 23, 2018
  104. Derrick StoleeAug 1, 2018
  105. Jeff KingSep 12, 2018
  106. Jeff KingSep 12, 2018
  107. Derrick StoleeSep 12, 2018
  108. 13/18 test-reach: test reduce_headsDerrick Stolee, Jul 20, 2018
  109. Stefan BellerJul 20, 2018
  110. Derrick StoleeJul 20, 2018
  111. Stefan BellerJul 20, 2018
  112. Derrick StoleeAug 1, 2018
  113. Derrick StoleeJul 20, 2018
  114. Eric SunshineJul 20, 2018
  115. Derrick StoleeJul 20, 2018
  116. Duy NguyenJul 20, 2018
  117. Derrick StoleeJul 20, 2018
  118. Junio C HamanoJul 20, 2018

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.