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

[PATCH v2 0/5] pack-write: cleanup usage of global variables

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jan 17, 2025, 09:20 UTC
Message-ID
<20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com>
In-Reply-To
<20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com>

This is a small series to remove global variable usage from `pack-write.c`. Mostly it bubble's up the usage of global variables to upper layers. The only exception is in `write-midx.c`, which was cleaned of global variable usage, so there, we use the repo that is in available in the context.

This series is based on fbe8d3079d (Git 2.48, 2025-01-10) with 'ps/more-sign-compare' and 'ps/the-repository' merged in.

There are no conflicts with topics in 'next', however there is a conflict with 'tb/incremental-midx-part-2' in 'seen', the fix is simple but happy to merge that in too if necessary.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
Changes in v2:
- Fixes to the commit messages to:
  - Fix copy-paste error s/the_hash_algo/the_repository
  - Mention why certain functions are modified
  - Small cleanups
- Link to v1: https://lore.kernel.org/r/20250116-kn-the-repo-cleanup-v1-0-a2f4c8e1c4c3@gmail.com
---
Karthik Nayak (5):
      pack-write: pass hash_algo to `fixup_pack_header_footer()`
      pack-write: pass repository to `index_pack_lockfile()`
      pack-write: pass hash_algo to `write_idx_file()`
      pack-write: pass hash_algo to `write_rev_file()`
      pack-write: pass hash_algo to internal functions
 builtin/fast-import.c  | 11 +++---
 builtin/index-pack.c   | 11 +++---
 builtin/pack-objects.c | 12 +++---
 builtin/receive-pack.c |  2 +-
 bulk-checkin.c         |  7 ++--
 fetch-pack.c           |  4 +-
 midx-write.c           |  4 +-
 pack-write.c           | 99 +++++++++++++++++++++++++++-----------------------
 pack.h                 | 30 ++++++++++++---
 9 files changed, 106 insertions(+), 74 deletions(-)
---
Range-diff versus v1:
1:  4e365523a5 = 1:  ed4ba01c95 pack-write: pass hash_algo to `fixup_pack_header_footer()`
2:  efa224f83b ! 2:  10aeaa5afc pack-write: pass repository to `index_pack_lockfile()`
    @@ Commit message
         variable to access the repository. To avoid global variable usage, pass
         the repository from the layers above.
     
    -    Altough the layers above could have access to the hash function
    -    internally, simply pass in `the_hash_algo`. This avoids any
    -    compatibility issues and bubbles up global variable usage to upper
    -    layers which can be eventually resolved.
    +    Altough the layers above could have access to the repository internally,
    +    simply pass in `the_repository`. This avoids any compatibility issues
    +    and bubbles up global variable usage to upper layers which can be
    +    eventually resolved.
     
         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
     
3:  6cca689d32 ! 3:  a4dbc3906d pack-write: pass hash_algo to `write_idx_file()`
    @@ Commit message
         to access the repository's hash function. To avoid global variable
         usage, pass the hash function from the layers above.
     
    +    Since `stage_tmp_packfiles()` also resides in 'pack-write.c' and calls
    +    `write_idx_file()`, update it to accept `the_hash_algo` as a parameter
    +    and pass it through to the callee.
    +
         Altough the layers above could have access to the hash function
         internally, simply pass in `the_hash_algo`. This avoids any
         compatibility issues and bubbles up global variable usage to upper
4:  b29eb6a305 ! 4:  d06d8ee962 pack-write: pass hash_algo to `write_rev_file()`
    @@ Commit message
     
         The `write_rev_file()` function uses the global `the_hash_algo` variable
         to access the repository's hash function. To avoid global variable
    -    usage, let's pass the hash function from the layers above.
    +    usage, let's pass the hash function from the layers above. Also modify
    +    children functions `write_rev_file_order()` and `write_rev_header()` to
    +    accept 'the_hash_algo'.
     
         Altough the layers above could have access to the hash function
         internally, simply pass in `the_hash_algo`. This avoids any
5:  438bfec4de ! 5:  1e34f5a70c pack-write: pass hash_algo to `write_rev_*()`
    @@ Metadata
     Author: Karthik Nayak <karthik.188@gmail.com>
     
      ## Commit message ##
    -    pack-write: pass hash_algo to `write_rev_*()`
    +    pack-write: pass hash_algo to internal functions
     
    -    The `write_rev_*()` functions use the global `the_hash_algo` variable to
    -    access the repository's hash function. Pass the hash from down as we've
    -    added made them available in the previous few commits.
    +    The internal functions `write_rev_trailer()`, `write_rev_trailer()`,
    +    `write_mtimes_header()` and write_mtimes_trailer()` use the global
    +    `the_hash_algo` variable to access the repository's hash function. Pass
    +    the hash from down as we've added made them available in the previous
    +    few commits.
    +
    +    This removes all global variables from the 'pack-write.c' file, so
    +    remove the 'USE_THE_REPOSITORY_VARIABLE' macro.
     
         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
     
---

base-commit: 8b2efc058aaa3d1437678616bccf7c5f7ce1f92b change-id: 20250110-kn-the-repo-cleanup-44144fa42dc3

Thanks
- Karthik
Previous: Karthik Nayak via B4 RelayNext: Karthik Nayak
Message 16 of 36 in “pack-write: cleanup usage of global variables”
  1. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak via B4 Relay, Jan 16, 2025
  2. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak via B4 Relay, Jan 16, 2025
  3. Junio C HamanoJan 16, 2025
  4. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak via B4 Relay, Jan 16, 2025
  5. Junio C HamanoJan 16, 2025
  6. Karthik NayakJan 17, 2025
  7. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak via B4 Relay, Jan 16, 2025
  8. Patrick SteinhardtJan 16, 2025
  9. Junio C HamanoJan 16, 2025
  10. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak via B4 Relay, Jan 16, 2025
  11. Patrick SteinhardtJan 16, 2025
  12. Karthik NayakJan 17, 2025
  13. Junio C HamanoJan 16, 2025
  14. Karthik NayakJan 17, 2025
  15. 5/5 pack-write: pass hash_algo to `write_rev_*()`Karthik Nayak via B4 Relay, Jan 16, 2025
  16. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak, Jan 17, 2025
  17. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak, Jan 17, 2025
  18. Toon ClaesJan 17, 2025
  19. Junio C HamanoJan 17, 2025
  20. Karthik NayakJan 19, 2025
  21. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak, Jan 17, 2025
  22. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak, Jan 17, 2025
  23. Toon ClaesJan 17, 2025
  24. Karthik NayakJan 19, 2025
  25. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak, Jan 17, 2025
  26. 5/5 pack-write: pass hash_algo to internal functionsKarthik Nayak, Jan 17, 2025
  27. Patrick SteinhardtJan 17, 2025
  28. Karthik NayakJan 17, 2025
  29. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak, Jan 19, 2025
  30. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak, Jan 19, 2025
  31. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak, Jan 19, 2025
  32. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak, Jan 19, 2025
  33. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak, Jan 19, 2025
  34. 5/5 pack-write: pass hash_algo to internal functionsKarthik Nayak, Jan 19, 2025
  35. Patrick SteinhardtJan 24, 2025
  36. Junio C HamanoJan 24, 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.