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

[PATCH v3 01/18] reftable/stack: stop using `read_in_full()`

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 3, 2025, 08:03 UTC
Message-ID
<20250203-pks-reftable-drop-git-compat-util-v3-1-446c9ed4ee9e@pks.im>
In-Reply-To
<20250203-pks-reftable-drop-git-compat-util-v3-0-446c9ed4ee9e@pks.im>

There is a single callsite of `read_in_full()` in the reftable library. Open-code the function to reduce our dependency on the Git library.

Note that we only partially port over the logic from `read_in_full()` and its underlying `xread()` helper. Most importantly, the latter also knows to handle `EWOULDBLOCK` via `handle_nonblock()`. This logic is irrelevant for us though because the reftable library never sets the `O_NONBLOCK` option in the first place.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 reftable/stack.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/reftable/stack.c b/reftable/stack.c
index f7c1845e15..d57acd9540 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -115,13 +115,16 @@ int reftable_new_stack(struct reftable_stack **dest, const char *dir,
 
 static int fd_read_lines(int fd, char ***namesp)
 {
-	off_t size = lseek(fd, 0, SEEK_END);
 	char *buf = NULL;
 	int err = 0;
+	off_t size;
+
+	size = lseek(fd, 0, SEEK_END);
 	if (size < 0) {
 		err = REFTABLE_IO_ERROR;
 		goto done;
 	}
+
 	err = lseek(fd, 0, SEEK_SET);
 	if (err < 0) {
 		err = REFTABLE_IO_ERROR;
@@ -134,9 +137,16 @@ static int fd_read_lines(int fd, char ***namesp)
 		goto done;
 	}
 
-	if (read_in_full(fd, buf, size) != size) {
-		err = REFTABLE_IO_ERROR;
-		goto done;
+	for (off_t total_read = 0; total_read < size; ) {
+		ssize_t bytes_read = read(fd, buf + total_read, size - total_read);
+		if (bytes_read < 0 && (errno == EAGAIN || errno == EINTR))
+			continue;
+		if (bytes_read < 0 || !bytes_read) {
+			err = REFTABLE_IO_ERROR;
+			goto done;
+		}
+
+		total_read += bytes_read;
 	}
 	buf[size] = 0;
 
-- 
2.48.1.502.g6dc24dfdaf.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 61 of 123 in “reftable: stop using "git-compat-util.h"”
  1. 00/19 reftable: stop using "git-compat-util.h"Patrick Steinhardt, Jan 27, 2025
  2. 02/19 reftable/stack: stop using `write_in_full()`Patrick Steinhardt, Jan 27, 2025
  3. 01/19 reftable/stack: stop using `read_in_full()`Patrick Steinhardt, Jan 27, 2025
  4. Justin ToblerJan 27, 2025
  5. Patrick SteinhardtJan 28, 2025
  6. Junio C HamanoJan 28, 2025
  7. Patrick SteinhardtJan 29, 2025
  8. 03/19 reftable/blocksource: stop using `xmmap()`Patrick Steinhardt, Jan 27, 2025
  9. 04/19 reftable/record: stop using `COPY_ARRAY()`Patrick Steinhardt, Jan 27, 2025
  10. 05/19 reftable/record: stop using `BUG()` in `reftable_record_init()`Patrick Steinhardt, Jan 27, 2025
  11. Justin ToblerJan 27, 2025
  12. 06/19 reftable/record: don't `BUG()` in `reftable_record_cmp()`Patrick Steinhardt, Jan 27, 2025
  13. Justin ToblerJan 27, 2025
  14. 07/19 reftable: stop using `BUG()` in trivial casesPatrick Steinhardt, Jan 27, 2025
  15. 08/19 reftable/basics: stop using `st_mult()` in array allocatorsPatrick Steinhardt, Jan 27, 2025
  16. 09/19 reftable/basics: provide wrappers for big endian conversionPatrick Steinhardt, Jan 27, 2025
  17. 10/19 reftable/reader: stop using `ARRAY_SIZE()` macroPatrick Steinhardt, Jan 27, 2025
  18. 11/19 reftable/system: introduce `reftable_rand()`Patrick Steinhardt, Jan 27, 2025
  19. 12/19 reftable/stack: stop using `sleep_millisec()`Patrick Steinhardt, Jan 27, 2025
  20. 13/19 reftable/basics: stop using `SWAP()` macroPatrick Steinhardt, Jan 27, 2025
  21. 14/19 reftable/basics: stop using `UNUSED` annotationPatrick Steinhardt, Jan 27, 2025
  22. 15/19 compat/mingw: split out POSIX-related bitsPatrick Steinhardt, Jan 27, 2025
  23. 16/19 compat/msvc: split out POSIX-related bitsPatrick Steinhardt, Jan 27, 2025
  24. 17/19 git-compat-util.h: split out POSIX-emulating bitsPatrick Steinhardt, Jan 27, 2025
  25. Justin ToblerJan 27, 2025
  26. 18/19 reftable: decouple from Git codebase by pulling in "compat/posix.h"Patrick Steinhardt, Jan 27, 2025
  27. 19/19 Makefile: skip reftable library for CoccinellePatrick Steinhardt, Jan 27, 2025
  28. Junio C HamanoJan 27, 2025
  29. Patrick SteinhardtJan 28, 2025
  30. Junio C HamanoJan 28, 2025
  31. 00/20 reftable: stop using "git-compat-util.h"Patrick Steinhardt, Jan 28, 2025
  32. 01/20 reftable/stack: stop using `read_in_full()`Patrick Steinhardt, Jan 28, 2025
  33. 02/20 reftable/stack: stop using `write_in_full()`Patrick Steinhardt, Jan 28, 2025
  34. 04/20 reftable/record: stop using `COPY_ARRAY()`Patrick Steinhardt, Jan 28, 2025
  35. Justin ToblerJan 29, 2025
  36. Patrick SteinhardtFeb 3, 2025
  37. 03/20 reftable/blocksource: stop using `xmmap()`Patrick Steinhardt, Jan 28, 2025
  38. 05/20 reftable/record: stop using `BUG()` in `reftable_record_init()`Patrick Steinhardt, Jan 28, 2025
  39. 06/20 reftable/record: don't `BUG()` in `reftable_record_cmp()`Patrick Steinhardt, Jan 28, 2025
  40. 07/20 reftable: stop using `BUG()` in trivial casesPatrick Steinhardt, Jan 28, 2025
  41. 08/20 reftable/basics: stop using `st_mult()` in array allocatorsPatrick Steinhardt, Jan 28, 2025
  42. 09/20 reftable/basics: provide wrappers for big endian conversionPatrick Steinhardt, Jan 28, 2025
  43. 10/20 reftable/reader: stop using `ARRAY_SIZE()` macroPatrick Steinhardt, Jan 28, 2025
  44. 11/20 reftable/system: introduce `reftable_rand()`Patrick Steinhardt, Jan 28, 2025
  45. 12/20 reftable/stack: stop using `sleep_millisec()`Patrick Steinhardt, Jan 28, 2025
  46. 13/20 reftable/basics: stop using `SWAP()` macroPatrick Steinhardt, Jan 28, 2025
  47. 14/20 reftable/basics: stop using `UNUSED` annotationPatrick Steinhardt, Jan 28, 2025
  48. 15/20 compat: consistently resolve headers via project rootPatrick Steinhardt, Jan 28, 2025
  49. Johannes SixtJan 29, 2025
  50. Junio C HamanoJan 29, 2025
  51. Patrick SteinhardtFeb 3, 2025
  52. 16/20 compat/mingw: split out POSIX-related bitsPatrick Steinhardt, Jan 28, 2025
  53. 17/20 compat/msvc: split out POSIX-related bitsPatrick Steinhardt, Jan 28, 2025
  54. 18/20 git-compat-util.h: split out POSIX-emulating bitsPatrick Steinhardt, Jan 28, 2025
  55. 19/20 reftable: decouple from Git codebase by pulling in "compat/posix.h"Patrick Steinhardt, Jan 28, 2025
  56. 20/20 Makefile: skip reftable library for CoccinellePatrick Steinhardt, Jan 28, 2025
  57. Junio C HamanoJan 28, 2025
  58. Patrick SteinhardtJan 29, 2025
  59. Junio C HamanoJan 29, 2025
  60. 00/18 reftable: stop using "git-compat-util.h"Patrick Steinhardt, Feb 3, 2025
  61. 01/18 reftable/stack: stop using `read_in_full()`Patrick Steinhardt, Feb 3, 2025
  62. 02/18 reftable/stack: stop using `write_in_full()`Patrick Steinhardt, Feb 3, 2025
  63. 03/18 reftable/blocksource: stop using `xmmap()`Patrick Steinhardt, Feb 3, 2025
  64. 04/18 reftable/record: stop using `COPY_ARRAY()`Patrick Steinhardt, Feb 3, 2025
  65. 05/18 reftable/record: stop using `BUG()` in `reftable_record_init()`Patrick Steinhardt, Feb 3, 2025
  66. 06/18 reftable/record: don't `BUG()` in `reftable_record_cmp()`Patrick Steinhardt, Feb 3, 2025
  67. 07/18 reftable: stop using `BUG()` in trivial casesPatrick Steinhardt, Feb 3, 2025
  68. 08/18 reftable/basics: stop using `st_mult()` in array allocatorsPatrick Steinhardt, Feb 3, 2025
  69. 09/18 reftable/basics: provide wrappers for big endian conversionPatrick Steinhardt, Feb 3, 2025
  70. 10/18 reftable/reader: stop using `ARRAY_SIZE()` macroPatrick Steinhardt, Feb 3, 2025
  71. 11/18 reftable/system: introduce `reftable_rand()`Patrick Steinhardt, Feb 3, 2025
  72. 12/18 reftable/stack: stop using `sleep_millisec()`Patrick Steinhardt, Feb 3, 2025
  73. 13/18 reftable/basics: stop using `SWAP()` macroPatrick Steinhardt, Feb 3, 2025
  74. 14/18 reftable/basics: stop using `UNUSED` annotationPatrick Steinhardt, Feb 3, 2025
  75. 15/18 compat/mingw: split out POSIX-related bitsPatrick Steinhardt, Feb 3, 2025
  76. 16/18 git-compat-util.h: split out POSIX-emulating bitsPatrick Steinhardt, Feb 3, 2025
  77. 17/18 reftable: decouple from Git codebase by pulling in "compat/posix.h"Patrick Steinhardt, Feb 3, 2025
  78. 18/18 Makefile: skip reftable library for CoccinellePatrick Steinhardt, Feb 3, 2025
  79. Justin ToblerFeb 6, 2025
  80. 00/18 reftable: stop using "git-compat-util.h"Patrick Steinhardt, Feb 6, 2025
  81. 02/18 reftable/stack: stop using `write_in_full()`Patrick Steinhardt, Feb 6, 2025
  82. 01/18 reftable/stack: stop using `read_in_full()`Patrick Steinhardt, Feb 6, 2025
  83. 03/18 reftable/blocksource: stop using `xmmap()`Patrick Steinhardt, Feb 6, 2025
  84. 04/18 reftable/record: stop using `COPY_ARRAY()`Patrick Steinhardt, Feb 6, 2025
  85. 05/18 reftable/record: stop using `BUG()` in `reftable_record_init()`Patrick Steinhardt, Feb 6, 2025
  86. 06/18 reftable/record: don't `BUG()` in `reftable_record_cmp()`Patrick Steinhardt, Feb 6, 2025
  87. 07/18 reftable: stop using `BUG()` in trivial casesPatrick Steinhardt, Feb 6, 2025
  88. 08/18 reftable/basics: stop using `st_mult()` in array allocatorsPatrick Steinhardt, Feb 6, 2025
  89. 10/18 reftable/reader: stop using `ARRAY_SIZE()` macroPatrick Steinhardt, Feb 6, 2025
  90. 09/18 reftable/basics: provide wrappers for big endian conversionPatrick Steinhardt, Feb 6, 2025
  91. 11/18 reftable/system: introduce `reftable_rand()`Patrick Steinhardt, Feb 6, 2025
  92. 12/18 reftable/stack: stop using `sleep_millisec()`Patrick Steinhardt, Feb 6, 2025
  93. 13/18 reftable/basics: stop using `SWAP()` macroPatrick Steinhardt, Feb 6, 2025
  94. 14/18 reftable/basics: stop using `UNUSED` annotationPatrick Steinhardt, Feb 6, 2025
  95. Toon ClaesFeb 7, 2025
  96. Patrick SteinhardtFeb 7, 2025
  97. 15/18 compat/mingw: split out POSIX-related bitsPatrick Steinhardt, Feb 6, 2025
  98. 16/18 git-compat-util.h: split out POSIX-emulating bitsPatrick Steinhardt, Feb 6, 2025
  99. 17/18 reftable: decouple from Git codebase by pulling in "compat/posix.h"Patrick Steinhardt, Feb 6, 2025
  100. 18/18 Makefile: skip reftable library for CoccinellePatrick Steinhardt, Feb 6, 2025
  101. 00/18 reftable: stop using "git-compat-util.h"Patrick Steinhardt, Feb 7, 2025
  102. 01/18 reftable/stack: stop using `read_in_full()`Patrick Steinhardt, Feb 7, 2025
  103. 02/18 reftable/stack: stop using `write_in_full()`Patrick Steinhardt, Feb 7, 2025
  104. 03/18 reftable/blocksource: stop using `xmmap()`Patrick Steinhardt, Feb 7, 2025
  105. 04/18 reftable/record: stop using `COPY_ARRAY()`Patrick Steinhardt, Feb 7, 2025
  106. 05/18 reftable/record: stop using `BUG()` in `reftable_record_init()`Patrick Steinhardt, Feb 7, 2025
  107. 06/18 reftable/record: don't `BUG()` in `reftable_record_cmp()`Patrick Steinhardt, Feb 7, 2025
  108. 08/18 reftable/basics: stop using `st_mult()` in array allocatorsPatrick Steinhardt, Feb 7, 2025
  109. 07/18 reftable: stop using `BUG()` in trivial casesPatrick Steinhardt, Feb 7, 2025
  110. 09/18 reftable/basics: provide wrappers for big endian conversionPatrick Steinhardt, Feb 7, 2025
  111. 10/18 reftable/reader: stop using `ARRAY_SIZE()` macroPatrick Steinhardt, Feb 7, 2025
  112. 11/18 reftable/system: introduce `reftable_rand()`Patrick Steinhardt, Feb 7, 2025
  113. 12/18 reftable/stack: stop using `sleep_millisec()`Patrick Steinhardt, Feb 7, 2025
  114. 13/18 reftable/basics: stop using `SWAP()` macroPatrick Steinhardt, Feb 7, 2025
  115. 14/18 reftable/basics: introduce `REFTABLE_UNUSED` annotationPatrick Steinhardt, Feb 7, 2025
  116. 15/18 compat/mingw: split out POSIX-related bitsPatrick Steinhardt, Feb 7, 2025
  117. Johannes SixtFeb 9, 2025
  118. Junio C HamanoFeb 10, 2025
  119. Johannes SchindelinFeb 13, 2025
  120. Patrick SteinhardtFeb 17, 2025
  121. 16/18 git-compat-util.h: split out POSIX-emulating bitsPatrick Steinhardt, Feb 7, 2025
  122. 17/18 reftable: decouple from Git codebase by pulling in "compat/posix.h"Patrick Steinhardt, Feb 7, 2025
  123. 18/18 Makefile: skip reftable library for CoccinellePatrick Steinhardt, Feb 7, 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.