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

[PATCH v3 5/7] merge-ort: clarify the interning of strings in opt->priv->path

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 6, 2025, 23:15 UTC
Message-ID
<c4caba16c72636c7b726c6753815f7c5f77ecd1d.1754522123.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1943.v3.git.1754522122.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
Because merge-ort is dealing with potentially all the pathnames in the
repository, it sometimes needs to do an awful lot of string comparisons.
Because of this, struct merge_options_internal's path member was
envisioned from the beginning to contain an interned value for every
path in order to allow us to compare strings via pointer comparison
instead of using strcmp.  See
  * 5b59c3db059d (merge-ort: setup basic internal data structures,
                  2020-12-13)
  * f591c4724615 (merge-ort: copy and adapt merge_3way() from
                  merge-recursive.c, 2021-01-01)
for some of the early comments.

However, the original comment was slightly misleading when it switched from mentioning paths to only mentioning directories. Fix that, and while at it also point to an example in the code which applies the extra needed care to permit the pointer comparison optimization.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-ort.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/merge-ort.c b/merge-ort.c
index 9b9d82ed10f7..325b19b182ad 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -316,9 +316,14 @@ struct merge_options_internal {
 	 *     (e.g. "drivers/firmware/raspberrypi.c").
 	 *   * store all relevant paths in the repo, both directories and
 	 *     files (e.g. drivers, drivers/firmware would also be included)
-	 *   * these keys serve to intern all the path strings, which allows
-	 *     us to do pointer comparison on directory names instead of
-	 *     strcmp; we just have to be careful to use the interned strings.
+	 *   * these keys serve to intern *all* path strings, which allows us
+	 *     to do pointer comparisons on file & directory names instead of
+	 *     using strcmp; however, for this pointer-comparison optimization
+	 *     to work, any code path that independently computes a path needs
+	 *     to check for it existing in this strmap, and if so, point to
+	 *     the path in this strmap instead of their computed copy.  See
+	 *     the "reuse known pointer" comment in
+	 *     apply_directory_rename_modifications() for an example.
 	 *
 	 * The values of paths:
 	 *   * either a pointer to a merged_info, or a conflict_info struct
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 37 of 39 in “Fix various rename corner cases”
  1. 0/6 Fix various rename corner casesElijah Newren via GitGitGadget, Jul 22, 2025
  2. 1/6 merge-ort: update comments to modern testfile locationElijah Newren via GitGitGadget, Jul 22, 2025
  3. 2/6 merge-ort: drop unnecessary temporary in check_for_directory_rename()Elijah Newren via GitGitGadget, Jul 22, 2025
  4. 3/6 t6423: document two bugs with rename-to-self testcasesElijah Newren via GitGitGadget, Jul 22, 2025
  5. Patrick SteinhardtAug 1, 2025
  6. Elijah NewrenAug 4, 2025
  7. Patrick SteinhardtAug 5, 2025
  8. Elijah NewrenAug 5, 2025
  9. 4/6 t6423: fix missed staging of file in testcases 12i,12j,12kElijah Newren via GitGitGadget, Jul 22, 2025
  10. Patrick SteinhardtAug 1, 2025
  11. Elijah NewrenAug 4, 2025
  12. Patrick SteinhardtAug 5, 2025
  13. Elijah NewrenAug 5, 2025
  14. 5/6 merge-ort: fix incorrect file handlingElijah Newren via GitGitGadget, Jul 22, 2025
  15. Patrick SteinhardtAug 1, 2025
  16. Elijah NewrenAug 4, 2025
  17. Patrick SteinhardtAug 5, 2025
  18. Elijah NewrenAug 5, 2025
  19. 6/6 merge-ort: fix directory rename on top of source of other rename/deleteElijah Newren via GitGitGadget, Jul 22, 2025
  20. Patrick SteinhardtAug 1, 2025
  21. Elijah NewrenAug 4, 2025
  22. Patrick SteinhardtAug 1, 2025
  23. 0/6 Fix various rename corner casesElijah Newren via GitGitGadget, Aug 5, 2025
  24. 1/6 merge-ort: update comments to modern testfile locationElijah Newren via GitGitGadget, Aug 5, 2025
  25. 2/6 merge-ort: drop unnecessary temporary in check_for_directory_rename()Elijah Newren via GitGitGadget, Aug 5, 2025
  26. 3/6 t6423: document two bugs with rename-to-self testcasesElijah Newren via GitGitGadget, Aug 5, 2025
  27. 4/6 t6423: fix missed staging of file in testcases 12i,12j,12kElijah Newren via GitGitGadget, Aug 5, 2025
  28. 5/6 merge-ort: fix incorrect file handlingElijah Newren via GitGitGadget, Aug 5, 2025
  29. 6/6 merge-ort: fix directory rename on top of source of other rename/deleteElijah Newren via GitGitGadget, Aug 5, 2025
  30. Junio C HamanoAug 5, 2025
  31. Elijah NewrenAug 5, 2025
  32. 0/7 Fix various rename corner casesElijah Newren via GitGitGadget, Aug 6, 2025
  33. 1/7 merge-ort: update comments to modern testfile locationElijah Newren via GitGitGadget, Aug 6, 2025
  34. 2/7 merge-ort: drop unnecessary temporary in check_for_directory_rename()Elijah Newren via GitGitGadget, Aug 6, 2025
  35. 3/7 t6423: document two bugs with rename-to-self testcasesElijah Newren via GitGitGadget, Aug 6, 2025
  36. 4/7 t6423: fix missed staging of file in testcases 12i,12j,12kElijah Newren via GitGitGadget, Aug 6, 2025
  37. 5/7 merge-ort: clarify the interning of strings in opt->priv->pathElijah Newren via GitGitGadget, Aug 6, 2025
  38. 6/7 merge-ort: fix incorrect file handlingElijah Newren via GitGitGadget, Aug 6, 2025
  39. 7/7 merge-ort: fix directory rename on top of source of other rename/deleteElijah Newren via GitGitGadget, Aug 6, 2025

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.