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

[PATCH v8 0/7] progress: test fixes / cleanup

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Dec 28, 2021, 15:18 UTC
Message-ID
<cover-v8-0.7-00000000000-20211228T150728Z-avarab@gmail.com>
In-Reply-To
<cover-v6-0.6-00000000000-20211228T143223Z-avarab@gmail.com>

Various test, leak and other fixes for the progress.c code and its tests. This v8 addresses feedback on v7[1] by Johannes Altmanninger. For that round I accidentally broke the In-Reply-To chain, so I'm replying to the v6 here to attach it to the original thread again.

1. https://lore.kernel.org/git/cover-v7-0.7-00000000000-20211217T041945Z-avarab@gmail.com/
Ævar Arnfjörð Bjarmason (7):
  leak tests: fix a memory leak in "test-progress" helper
  progress.c test helper: add missing braces
  progress.c tests: make start/stop commands on stdin
  progress.c tests: test some invalid usage
  progress.c: add temporary variable from progress struct
  pack-bitmap-write.c: don't return without stop_progress()
  *.c: use isatty(0|2), not isatty(STDIN_FILENO|STDERR_FILENO)
 builtin/bisect--helper.c    |  2 +-
 builtin/bundle.c            |  2 +-
 compat/mingw.c              |  2 +-
 pack-bitmap-write.c         |  6 +--
 progress.c                  | 14 +++---
 t/helper/test-progress.c    | 52 +++++++++++++++-----
 t/t0500-progress-display.sh | 94 ++++++++++++++++++++++++++++---------
 7 files changed, 126 insertions(+), 46 deletions(-)
Range-diff against v7:
1:  5367293ee84 ! 1:  aa08dab654d leak tests: fix a memory leaks in "test-progress" helper
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    leak tests: fix a memory leaks in "test-progress" helper
    +    leak tests: fix a memory leak in "test-progress" helper
     
         Fix a memory leak in the test-progress helper, and mark the
         corresponding "t0500-progress-display.sh" test as being leak-free
2:  81788101763 = 2:  3ecdab074b6 progress.c test helper: add missing braces
3:  d685c248686 ! 3:  271f6d7ec3b progress.c tests: make start/stop commands on stdin
    @@ t/helper/test-progress.c
      #include "progress.h"
      #include "strbuf.h"
     +#include "string-list.h"
    -+
    -+/*
    -+ * We can't use "end + 1" as an argument to start_progress() below, it
    -+ * doesn't xstrdup() its "title" argument. We need to hold onto a
    -+ * valid "char *" for it until the end.
    -+ */
    -+static char *dup_title(struct string_list *titles, const char *title)
    -+{
    -+	return string_list_insert(titles, title)->string;
    -+}
      
      int cmd__progress(int argc, const char **argv)
      {
    @@ t/helper/test-progress.c
     -		if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
     +		if (skip_prefix(line.buf, "start ", (const char **) &end)) {
     +			uint64_t total = strtoull(end, &end, 10);
    -+			if (*end == '\0')
    -+				progress = start_progress(default_title, total);
    ++			const char *title;
    ++			const char *str;
    ++
    ++			/*
    ++			 * We can't use "end + 1" as an argument to
    ++			 * start_progress(), it doesn't xstrdup() its
    ++			 * "title" argument. We need to hold onto a
    ++			 * valid "char *" for it until the end.
    ++			 */
    ++			if (!*end)
    ++				title = default_title;
     +			else if (*end == ' ')
    -+				progress = start_progress(dup_title(&titles,
    -+								    end + 1),
    -+							  total);
    ++				title = string_list_insert(&titles, end + 1)->string;
     +			else
     +				die("invalid input: '%s'\n", line.buf);
    ++
    ++			str = title ? title : default_title;
    ++			progress = start_progress(str, total);
     +		} else if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
      			uint64_t item_count = strtoull(end, &end, 10);
      			if (*end != '\0')
4:  40e446da277 = 4:  7c1b8b287c5 progress.c tests: test some invalid usage
5:  c2303bfd130 ! 5:  72a31bd7191 progress.c: add temporary variable from progress struct
    @@ Metadata
      ## Commit message ##
         progress.c: add temporary variable from progress struct
     
    -    Add a temporary "progress" variable for the dereferenced p_progress
    -    pointer to a "struct progress *". Before 98a13647408 (trace2: log
    -    progress time and throughput, 2020-05-12) we didn't dereference
    -    "p_progress" in this function, now that we do it's easier to read the
    -    code if we work with a "progress" struct pointer like everywhere else,
    -    instead of a pointer to a pointer.
    +    Since 98a13647408 (trace2: log progress time and throughput,
    +    2020-05-12) stop_progress() dereferences a "struct progress **"
    +    parameter in several places. Extract a dereferenced variable (like in
    +    stop_progress_msg()) to reduce clutter and make it clearer who needs
    +    to write to this parameter.
    +
    +    Now instead of using "*p_progress" several times in stop_progress() we
    +    check it once for NULL and then use a dereferenced "progress" variable
    +    thereafter. This continues the same pattern used in the above
    +    stop_progress() function, see ac900fddb7f (progress: don't dereference
    +    before checking for NULL, 2020-08-10).
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## progress.c ##
    -@@ progress.c: void stop_progress(struct progress **p_progress)
    - 	finish_if_sparse(*p_progress);
    +@@ progress.c: static void finish_if_sparse(struct progress *progress)
    + 
    + void stop_progress(struct progress **p_progress)
    + {
    ++	struct progress *progress;
    + 	if (!p_progress)
    + 		BUG("don't provide NULL to stop_progress");
    ++	progress = *p_progress;
    + 
    +-	finish_if_sparse(*p_progress);
    ++	finish_if_sparse(progress);
      
    - 	if (*p_progress) {
    -+		struct progress *progress = *p_progress;
    +-	if (*p_progress) {
    ++	if (progress) {
      		trace2_data_intmax("progress", the_repository, "total_objects",
    - 				   (*p_progress)->total);
    +-				   (*p_progress)->total);
    ++				   progress->total);
      
    - 		if ((*p_progress)->throughput)
    +-		if ((*p_progress)->throughput)
    ++		if (progress->throughput)
      			trace2_data_intmax("progress", the_repository,
      					   "total_bytes",
     -					   (*p_progress)->throughput->curr_total);
6:  776362de897 ! 6:  0bd08e1b018 pack-bitmap-write.c: don't return without stop_progress()
    @@ Commit message
         reached the early exit in this function.
     
         We could call stop_progress() before we return, but better yet is to
    -    defer calling start_progress() until we need it.
    -
    -    This will matter in a subsequent commit where we BUG(...) out if this
    -    happens, and matters now e.g. because we don't have a corresponding
    -    "region_end" for the progress trace2 event.
    +    defer calling start_progress() until we need it. For now this only
    +    matters in practice because we'd previously omit the "region_leave"
    +    for the progress trace2 event.
     
         Suggested-by: SZEDER Gábor <szeder.dev@gmail.com>
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7:  0670d1aa5f2 ! 7:  060483fb5ce various *.c: use isatty(0|2), not isatty(STDIN_FILENO|STDERR_FILENO)
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    various *.c: use isatty(0|2), not isatty(STDIN_FILENO|STDERR_FILENO)
    +    *.c: use isatty(0|2), not isatty(STDIN_FILENO|STDERR_FILENO)
     
         We have over 50 uses of "isatty(1)" and "isatty(2)" in the codebase,
    -    and around 10 "isatty(0)", but these used the
    +    and around 10 "isatty(0)", but three callers used the
         {STDIN_FILENO,STD{OUT,ERR}_FILENO} macros in "stdlib.h" to refer to
         them.
     
    -    Let's change these for consistency, and because another commit that
    -    would like to be based on top of this one[1] has a recipe to change
    -    all of these for ad-hoc testing, not needing to match these with that
    -    ad-hoc regex will make things easier to explain. Only one of these is
    -    related to the "struct progress" code which it discusses, but let's
    -    change all of these while we're at it.
    +    Let's change these for consistency.  This makes it easier to change
    +    all calls to isatty() at a whim, which is useful to test some
    +    scenarios[1].
     
         1. https://lore.kernel.org/git/patch-v6-8.8-bff919994b5-20211102T122507Z-avarab@gmail.com/
     
-- 
2.34.1.1257.g2af47340c7b
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 53 of 90 in “i18n: improve translatability of ambiguous object output”
  1. 0/2 i18n: improve translatability of ambiguous object outputÆvar Arnfjörð Bjarmason, Oct 4, 2021
  2. 1/2 object-name tests: tighten up advise() output testÆvar Arnfjörð Bjarmason, Oct 4, 2021
  3. Eric SunshineOct 4, 2021
  4. Jeff KingOct 4, 2021
  5. 2/2 object-name: make ambiguous object output translatableÆvar Arnfjörð Bjarmason, Oct 4, 2021
  6. Jeff KingOct 4, 2021
  7. Ævar Arnfjörð BjarmasonOct 4, 2021
  8. Jeff KingOct 4, 2021
  9. Ævar Arnfjörð BjarmasonOct 4, 2021
  10. Jeff KingOct 4, 2021
  11. 0/2 i18n: improve translatability of ambiguous object outputÆvar Arnfjörð Bjarmason, Oct 4, 2021
  12. 1/2 object.[ch]: mark object type names for translationÆvar Arnfjörð Bjarmason, Oct 4, 2021
  13. Eric SunshineOct 4, 2021
  14. Bagas SanjayaOct 5, 2021
  15. Ævar Arnfjörð BjarmasonOct 5, 2021
  16. Jeff KingOct 6, 2021
  17. Junio C HamanoOct 6, 2021
  18. Jeff KingOct 6, 2021
  19. Junio C HamanoOct 7, 2021
  20. 2/2 object-name: make ambiguous object output translatableÆvar Arnfjörð Bjarmason, Oct 4, 2021
  21. Jeff KingOct 6, 2021
  22. 0/3 i18n: improve translatability of ambiguous object outputÆvar Arnfjörð Bjarmason, Oct 8, 2021
  23. 1/3 object-name: remove unreachable "unknown type" handlingÆvar Arnfjörð Bjarmason, Oct 8, 2021
  24. 2/3 object-name: make ambiguous object output translatableÆvar Arnfjörð Bjarmason, Oct 8, 2021
  25. 3/3 object-name: show date for ambiguous tag objectsÆvar Arnfjörð Bjarmason, Oct 8, 2021
  26. 0/3 object-name: make ambiguous object output translatable + show tag dateÆvar Arnfjörð Bjarmason, Nov 22, 2021
  27. 3/3 object-name: show date for ambiguous tag objectsÆvar Arnfjörð Bjarmason, Nov 22, 2021
  28. 1/3 object-name: remove unreachable "unknown type" handlingÆvar Arnfjörð Bjarmason, Nov 22, 2021
  29. Jeff KingNov 22, 2021
  30. 2/3 object-name: make ambiguous object output translatableÆvar Arnfjörð Bjarmason, Nov 22, 2021
  31. 0/6 object-name: make ambiguous object output translatable + show tag dateÆvar Arnfjörð Bjarmason, Nov 25, 2021
  32. 1/6 object-name tests: add tests for ambiguous object blind spotsÆvar Arnfjörð Bjarmason, Nov 25, 2021
  33. Josh SteadmonDec 23, 2021
  34. 2/6 object-name: explicitly handle OBJ_BAD in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Nov 25, 2021
  35. Josh SteadmonDec 23, 2021
  36. Junio C HamanoDec 23, 2021
  37. 3/6 object-name: make ambiguous object output translatableÆvar Arnfjörð Bjarmason, Nov 25, 2021
  38. fixup! object-name: make ambiguous object output translatableJosh Steadmon, Dec 23, 2021
  39. Junio C HamanoDec 23, 2021
  40. 4/6 object-name: show date for ambiguous tag objectsÆvar Arnfjörð Bjarmason, Nov 25, 2021
  41. 5/6 object-name: iterate ambiguous objects before showing headerÆvar Arnfjörð Bjarmason, Nov 25, 2021
  42. 6/6 object-name: re-use "struct strbuf" in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Nov 25, 2021
  43. 0/6 object-name: make ambiguous object output translatable + show tag dateÆvar Arnfjörð Bjarmason, Dec 28, 2021
  44. 1/6 object-name tests: add tests for ambiguous object blind spotsÆvar Arnfjörð Bjarmason, Dec 28, 2021
  45. Junio C HamanoDec 30, 2021
  46. 3/6 object-name: make ambiguous object output translatableÆvar Arnfjörð Bjarmason, Dec 28, 2021
  47. Junio C HamanoDec 30, 2021
  48. 2/6 object-name: explicitly handle OBJ_BAD in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Dec 28, 2021
  49. 4/6 object-name: show date for ambiguous tag objectsÆvar Arnfjörð Bjarmason, Dec 28, 2021
  50. Junio C HamanoDec 30, 2021
  51. 5/6 object-name: iterate ambiguous objects before showing headerÆvar Arnfjörð Bjarmason, Dec 28, 2021
  52. 6/6 object-name: re-use "struct strbuf" in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Dec 28, 2021
  53. 0/7 progress: test fixes / cleanupÆvar Arnfjörð Bjarmason, Dec 28, 2021
  54. 1/7 leak tests: fix a memory leak in "test-progress" helperÆvar Arnfjörð Bjarmason, Dec 28, 2021
  55. 2/7 progress.c test helper: add missing bracesÆvar Arnfjörð Bjarmason, Dec 28, 2021
  56. 3/7 progress.c tests: make start/stop commands on stdinÆvar Arnfjörð Bjarmason, Dec 28, 2021
  57. Johannes AltmanningerDec 28, 2021
  58. 4/7 progress.c tests: test some invalid usageÆvar Arnfjörð Bjarmason, Dec 28, 2021
  59. Johannes AltmanningerDec 28, 2021
  60. 6/7 pack-bitmap-write.c: don't return without stop_progress()Ævar Arnfjörð Bjarmason, Dec 28, 2021
  61. 5/7 progress.c: add temporary variable from progress structÆvar Arnfjörð Bjarmason, Dec 28, 2021
  62. René ScharfeDec 28, 2021
  63. Johannes AltmanningerDec 28, 2021
  64. 7/7 *.c: use isatty(0|2), not isatty(STDIN_FILENO|STDERR_FILENO)Ævar Arnfjörð Bjarmason, Dec 28, 2021
  65. René ScharfeDec 28, 2021
  66. Ævar Arnfjörð BjarmasonDec 28, 2021
  67. Junio C HamanoJan 8, 2022
  68. 0/6 object-name: make ambiguous object output translatable + show tag dateÆvar Arnfjörð Bjarmason, Jan 12, 2022
  69. 1/6 object-name tests: add tests for ambiguous object blind spotsÆvar Arnfjörð Bjarmason, Jan 12, 2022
  70. Junio C HamanoJan 13, 2022
  71. Ævar Arnfjörð BjarmasonJan 14, 2022
  72. Junio C HamanoJan 14, 2022
  73. 2/6 object-name: explicitly handle OBJ_BAD in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Jan 12, 2022
  74. 3/6 object-name: make ambiguous object output translatableÆvar Arnfjörð Bjarmason, Jan 12, 2022
  75. 4/6 object-name: show date for ambiguous tag objectsÆvar Arnfjörð Bjarmason, Jan 12, 2022
  76. Junio C HamanoJan 13, 2022
  77. Ævar Arnfjörð BjarmasonJan 14, 2022
  78. Junio C HamanoJan 14, 2022
  79. Ævar Arnfjörð BjarmasonJan 14, 2022
  80. 5/6 object-name: iterate ambiguous objects before showing headerÆvar Arnfjörð Bjarmason, Jan 12, 2022
  81. 6/6 object-name: re-use "struct strbuf" in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Jan 12, 2022
  82. 0/7 object-name: make ambiguous object output translatable + show tag dateÆvar Arnfjörð Bjarmason, Jan 27, 2022
  83. 1/7 object-name tests: add tests for ambiguous object blind spotsÆvar Arnfjörð Bjarmason, Jan 27, 2022
  84. 2/7 object-name: explicitly handle OBJ_BAD in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Jan 27, 2022
  85. 3/7 object-name: explicitly handle bad tags in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Jan 27, 2022
  86. 4/7 object-name: make ambiguous object output translatableÆvar Arnfjörð Bjarmason, Jan 27, 2022
  87. 6/7 object-name: iterate ambiguous objects before showing headerÆvar Arnfjörð Bjarmason, Jan 27, 2022
  88. 5/7 object-name: show date for ambiguous tag objectsÆvar Arnfjörð Bjarmason, Jan 27, 2022
  89. 7/7 object-name: re-use "struct strbuf" in show_ambiguous_object()Ævar Arnfjörð Bjarmason, Jan 27, 2022
  90. Junio C HamanoJan 27, 2022

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.