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

[PATCH v5 0/7] scalar: implement the subcommand "diagnose"

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
May 19, 2022, 18:17 UTC
Message-ID
<pull.1128.v5.git.1652984283.gitgitgadget@gmail.com>
In-Reply-To
<pull.1128.v4.git.1652210824.gitgitgadget@gmail.com>

Over the course of the years, we developed a sub-command that gathers diagnostic data into a .zip file that can then be attached to bug reports. This sub-command turned out to be very useful in helping Scalar developers identify and fix issues.

Changes since v4:
 * Squashed in Junio's suggested fixups
 * Renamed the option from --add-file-with-content=<name>:<content> to
   --add-virtual-file=<name>:<content>
 * Fixed one instance where I had used error() instead of error_errno().
Changes since v3:
 * We're now using unquote_c_style() instead of rolling our own unquoter.
 * Fixed the added regression test.
 * As pointed out by Scalar's Functional Tests, the
   add_directory_to_archiver() function should not fail when scalar diagnose
   encounters FSMonitor's Unix socket, but only warn instead.
 * Related: add_directory_to_archiver() needs to propagate errors from
   processing subdirectories so that the top-level call returns an error,
   too.
Changes since v2:
 * Clarified in the commit message what the biggest benefit of
   --add-file-with-content is.
 * The <path> part of the -add-file-with-content argument can now contain
   colons. To do this, the path needs to start and end in double-quote
   characters (which are stripped), and the backslash serves as escape
   character in that case (to allow the path to contain both colons and
   double-quotes).
 * Fixed incorrect grammar.
 * Instead of strcmp(<what-we-don't-want>), we now say
   !strcmp(<what-we-want>).
 * The help text for --add-file-with-content was improved a tiny bit.
 * Adjusted the commit message that still talked about spawning plenty of
   processes and about a throw-away repository for the sake of generating a
   .zip file.
 * Simplified the code that shows the diagnostics and adds them to the .zip
   file.
 * The final message that reports that the archive is complete is now
   printed to stderr instead of stdout.
Changes since v1:
 * Instead of creating a throw-away repository, staging the contents of the
   .zip file and then using git write-tree and git archive to write the .zip
   file, the patch series now introduces a new option to git archive and
   uses write_archive() directly (avoiding any separate process).
 * Since the command avoids separate processes, it is now blazing fast on
   Windows, and I dropped the spinner() function because it's no longer
   needed.
 * While reworking the test case, I noticed that scalar [...] <enlistment>
   failed to verify that the specified directory exists, and would happily
   "traverse to its parent directory" on its quest to find a Scalar
   enlistment. That is of course incorrect, and has been fixed as a "while
   at it" sort of preparatory commit.
 * I had forgotten to sign off on all the commits, which has been fixed.
 * Instead of some "home-grown" readdir()-based function, the code now uses
   for_each_file_in_pack_dir() to look through the pack directories.
 * If any alternates are configured, their pack directories are now included
   in the output.
 * The commit message that might be interpreted to promise information about
   large loose files has been corrected to no longer promise that.
 * The test cases have been adjusted to test a little bit more (e.g.
   verifying that specific paths are mentioned in the output, instead of
   merely verifying that the output is non-empty).
Johannes Schindelin (5):
  archive: optionally add "virtual" files
  archive --add-file-with-contents: allow paths containing colons
  scalar: validate the optional enlistment argument
  Implement `scalar diagnose`
  scalar diagnose: include disk space information
Matthew John Cheetham (2):
  scalar: teach `diagnose` to gather packfile info
  scalar: teach `diagnose` to gather loose objects information
 Documentation/git-archive.txt    |  17 ++
 archive.c                        |  63 ++++++-
 contrib/scalar/scalar.c          | 292 ++++++++++++++++++++++++++++++-
 contrib/scalar/scalar.txt        |  12 ++
 contrib/scalar/t/t9099-scalar.sh |  27 +++
 t/t5003-archive-zip.sh           |  20 +++
 6 files changed, 421 insertions(+), 10 deletions(-)
base-commit: ddc35d833dd6f9e8946b09cecd3311b8aa18d295
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1128%2Fdscho%2Fscalar-diagnose-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1128/dscho/scalar-diagnose-v5
Pull-Request: https://github.com/gitgitgadget/git/pull/1128
Range-diff vs v4:
 1:  45662cf582a ! 1:  42e73fb0aac archive: optionally add "virtual" files
     @@ Documentation/git-archive.txt: OPTIONS
       	by concatenating the value for `--prefix` (if any) and the
       	basename of <file>.
       
     -+--add-file-with-content=<path>:<content>::
     ++--add-virtual-file=<path>:<content>::
      +	Add the specified contents to the archive.  Can be repeated to add
      +	multiple files.  The path of the file in the archive is built
      +	by concatenating the value for `--prefix` (if any) and the
     @@ archive.c: static int add_file_cb(const struct option *opt, const char *arg, int
      +		if (!S_ISREG(info->stat.st_mode))
      +			die(_("Not a regular file: %s"), path);
      +		info->content = NULL; /* read the file later */
     -+	} else {
     ++	} else if (!strcmp(opt->long_name, "add-virtual-file")) {
      +		const char *colon = strchr(arg, ':');
      +		char *p;
      +
     @@ archive.c: static int add_file_cb(const struct option *opt, const char *arg, int
      +		info->stat.st_mode = S_IFREG | 0644;
      +		info->content = xstrdup(colon + 1);
      +		info->stat.st_size = strlen(info->content);
     ++	} else {
     ++		BUG("add_file_cb() called for %s", opt->long_name);
      +	}
      +	item = string_list_append_nodup(&args->extra_files, path);
      +	item->util = info;
     @@ archive.c: static int parse_archive_args(int argc, const char **argv,
       		{ OPTION_CALLBACK, 0, "add-file", args, N_("file"),
       		  N_("add untracked file to archive"), 0, add_file_cb,
       		  (intptr_t)&base },
     -+		{ OPTION_CALLBACK, 0, "add-file-with-content", args,
     ++		{ OPTION_CALLBACK, 0, "add-virtual-file", args,
      +		  N_("path:content"), N_("add untracked file to archive"), 0,
      +		  add_file_cb, (intptr_t)&base },
       		OPT_STRING('o', "output", &output, N_("file"),
     @@ t/t5003-archive-zip.sh: test_expect_success 'git archive --format=zip --add-file
       check_zip with_untracked
       check_added with_untracked untracked untracked
       
     -+test_expect_success UNZIP 'git archive --format=zip --add-file-with-content' '
     ++test_expect_success UNZIP 'git archive --format=zip --add-virtual-file' '
      +	git archive --format=zip >with_file_with_content.zip \
     -+		--add-file-with-content=hello:world $EMPTY_TREE &&
     ++		--add-virtual-file=hello:world $EMPTY_TREE &&
      +	test_when_finished "rm -rf tmp-unpack" &&
      +	mkdir tmp-unpack && (
      +		cd tmp-unpack &&
 2:  fdba4ed6f4d ! 2:  b5ebd61066a archive --add-file-with-contents: allow paths containing colons
     @@ archive.c
      @@ archive.c: static int add_file_cb(const struct option *opt, const char *arg, int unset)
       			die(_("Not a regular file: %s"), path);
       		info->content = NULL; /* read the file later */
     - 	} else {
     + 	} else if (!strcmp(opt->long_name, "add-virtual-file")) {
      -		const char *colon = strchr(arg, ':');
      -		char *p;
      +		struct strbuf buf = STRBUF_INIT;
     @@ archive.c: static int add_file_cb(const struct option *opt, const char *arg, int
      -		info->content = xstrdup(colon + 1);
      +		info->content = xstrdup(p + 1);
       		info->stat.st_size = strlen(info->content);
     - 	}
     - 	item = string_list_append_nodup(&args->extra_files, path);
     + 	} else {
     + 		BUG("add_file_cb() called for %s", opt->long_name);
      
       ## t/t5003-archive-zip.sh ##
      @@ t/t5003-archive-zip.sh: check_zip with_untracked
       check_added with_untracked untracked untracked
       
     - test_expect_success UNZIP 'git archive --format=zip --add-file-with-content' '
     + test_expect_success UNZIP 'git archive --format=zip --add-virtual-file' '
      +	if test_have_prereq FUNNYNAMES
      +	then
      +		QUOTED=quoted:colon
     @@ t/t5003-archive-zip.sh: check_zip with_untracked
      +		QUOTED=quoted
      +	fi &&
       	git archive --format=zip >with_file_with_content.zip \
     -+		--add-file-with-content=\"$QUOTED\": \
     - 		--add-file-with-content=hello:world $EMPTY_TREE &&
     ++		--add-virtual-file=\"$QUOTED\": \
     + 		--add-virtual-file=hello:world $EMPTY_TREE &&
       	test_when_finished "rm -rf tmp-unpack" &&
       	mkdir tmp-unpack && (
       		cd tmp-unpack &&
 3:  da9f52a8240 = 3:  f1ba69c02d7 scalar: validate the optional enlistment argument
 4:  87bdc22322b ! 4:  3fb90194744 Implement `scalar diagnose`
     @@ contrib/scalar/scalar.c: static int unregister_dir(void)
      +	int res = 0;
      +
      +	if (!dir)
     -+		return error(_("could not open directory '%s'"), path);
     ++		return error_errno(_("could not open directory '%s'"), path);
      +
      +	if (!at_root)
      +		strbuf_addf(&buf, "%s/", path);
     @@ contrib/scalar/scalar.c: cleanup:
      +	strbuf_addf(&buf, "Enlistment root: %s\n", the_repository->worktree);
      +	write_or_die(stdout_fd, buf.buf, buf.len);
      +	strvec_pushf(&archiver_args,
     -+		     "--add-file-with-content=diagnostics.log:%.*s",
     ++		     "--add-virtual-file=diagnostics.log:%.*s",
      +		     (int)buf.len, buf.buf);
      +
      +	if ((res = add_directory_to_archiver(&archiver_args, ".git", 0)) ||
 5:  3f63b197d42 ! 5:  2e645b08a9e scalar diagnose: include disk space information
     @@ contrib/scalar/scalar.c: static int cmd_diagnose(int argc, const char **argv)
      +	get_disk_info(&buf);
       	write_or_die(stdout_fd, buf.buf, buf.len);
       	strvec_pushf(&archiver_args,
     - 		     "--add-file-with-content=diagnostics.log:%.*s",
     + 		     "--add-virtual-file=diagnostics.log:%.*s",
      
       ## contrib/scalar/t/t9099-scalar.sh ##
      @@ contrib/scalar/t/t9099-scalar.sh: SQ="'"
 6:  fc1319338fc ! 6:  0fa20d73750 scalar: teach `diagnose` to gather packfile info
     @@ contrib/scalar/scalar.c: cleanup:
       {
       	struct option options[] = {
      @@ contrib/scalar/scalar.c: static int cmd_diagnose(int argc, const char **argv)
     - 		     "--add-file-with-content=diagnostics.log:%.*s",
     + 		     "--add-virtual-file=diagnostics.log:%.*s",
       		     (int)buf.len, buf.buf);
       
      +	strbuf_reset(&buf);
     -+	strbuf_addstr(&buf, "--add-file-with-content=packs-local.txt:");
     ++	strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
      +	dir_file_stats(the_repository->objects->odb, &buf);
      +	foreach_alt_odb(dir_file_stats, &buf);
      +	strvec_push(&archiver_args, buf.buf);
 7:  e8f5b42f7b7 ! 7:  62e173b47cf scalar: teach `diagnose` to gather loose objects information
     @@ contrib/scalar/scalar.c: static int cmd_diagnose(int argc, const char **argv)
       	strvec_push(&archiver_args, buf.buf);
       
      +	strbuf_reset(&buf);
     -+	strbuf_addstr(&buf, "--add-file-with-content=objects-local.txt:");
     ++	strbuf_addstr(&buf, "--add-virtual-file=objects-local.txt:");
      +	loose_objs_stats(&buf, ".git/objects");
      +	strvec_push(&archiver_args, buf.buf);
      +
-- 
gitgitgadget
Previous: Johannes SchindelinNext: Johannes Schindelin via GitGitGadget
Message 92 of 140 in “scalar: implement the subcommand "diagnose"”
  1. 0/5 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, Jan 26, 2022
  2. 1/5 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, Jan 26, 2022
  3. René ScharfeJan 26, 2022
  4. Taylor BlauJan 26, 2022
  5. Johannes SchindelinFeb 6, 2022
  6. Elijah NewrenJan 27, 2022
  7. 2/5 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, Jan 26, 2022
  8. 3/5 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, Jan 26, 2022
  9. Taylor BlauJan 26, 2022
  10. Derrick StoleeJan 27, 2022
  11. Johannes SchindelinFeb 6, 2022
  12. 4/5 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, Jan 26, 2022
  13. Taylor BlauJan 26, 2022
  14. Derrick StoleeJan 27, 2022
  15. Elijah NewrenJan 27, 2022
  16. Johannes SchindelinFeb 6, 2022
  17. 5/5 scalar diagnose: show a spinner while staging contentJohannes Schindelin via GitGitGadget, Jan 26, 2022
  18. Derrick StoleeJan 27, 2022
  19. Johannes SchindelinFeb 6, 2022
  20. 0/6 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, Feb 6, 2022
  21. 2/6 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, Feb 6, 2022
  22. 1/6 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, Feb 6, 2022
  23. René ScharfeFeb 7, 2022
  24. Junio C HamanoFeb 7, 2022
  25. Johannes SchindelinFeb 8, 2022
  26. Junio C HamanoFeb 8, 2022
  27. René ScharfeFeb 8, 2022
  28. Junio C HamanoFeb 9, 2022
  29. René ScharfeFeb 10, 2022
  30. Junio C HamanoFeb 10, 2022
  31. René ScharfeFeb 11, 2022
  32. Junio C HamanoFeb 11, 2022
  33. René ScharfeFeb 12, 2022
  34. Junio C HamanoFeb 13, 2022
  35. René ScharfeFeb 13, 2022
  36. Junio C HamanoFeb 14, 2022
  37. Johannes SchindelinFeb 8, 2022
  38. 3/6 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, Feb 6, 2022
  39. René ScharfeFeb 7, 2022
  40. Johannes SchindelinFeb 8, 2022
  41. 4/6 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, Feb 6, 2022
  42. 5/6 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, Feb 6, 2022
  43. 6/6 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, Feb 6, 2022
  44. 0/7 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, May 4, 2022
  45. 2/7 archive --add-file-with-contents: allow paths containing colonsJohannes Schindelin via GitGitGadget, May 4, 2022
  46. Elijah NewrenMay 7, 2022
  47. Johannes SchindelinMay 9, 2022
  48. 1/7 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, May 4, 2022
  49. 3/7 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, May 4, 2022
  50. 5/7 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, May 4, 2022
  51. 7/7 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, May 4, 2022
  52. 6/7 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, May 4, 2022
  53. 4/7 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, May 4, 2022
  54. Elijah NewrenMay 7, 2022
  55. 0/7 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, May 10, 2022
  56. 2/7 archive --add-file-with-contents: allow paths containing colonsJohannes Schindelin via GitGitGadget, May 10, 2022
  57. Junio C HamanoMay 10, 2022
  58. rsbecker@nexbridge.comMay 10, 2022
  59. Johannes SchindelinMay 19, 2022
  60. Johannes SchindelinMay 19, 2022
  61. Junio C HamanoMay 19, 2022
  62. 3/7 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, May 10, 2022
  63. Ævar Arnfjörð BjarmasonMay 17, 2022
  64. Junio C HamanoMay 18, 2022
  65. Ævar Arnfjörð BjarmasonMay 20, 2022
  66. Johannes SchindelinMay 20, 2022
  67. Ævar Arnfjörð BjarmasonMay 21, 2022
  68. Junio C HamanoMay 22, 2022
  69. Johannes SchindelinMay 24, 2022
  70. Ævar Arnfjörð BjarmasonMay 24, 2022
  71. Junio C HamanoMay 24, 2022
  72. Johannes SchindelinMay 25, 2022
  73. 4/7 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, May 10, 2022
  74. Ævar Arnfjörð BjarmasonMay 17, 2022
  75. 6/7 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, May 10, 2022
  76. 5/7 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, May 10, 2022
  77. 1/7 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, May 10, 2022
  78. Junio C HamanoMay 10, 2022
  79. rsbecker@nexbridge.comMay 10, 2022
  80. Junio C HamanoMay 10, 2022
  81. René ScharfeMay 11, 2022
  82. Junio C HamanoMay 11, 2022
  83. René ScharfeMay 12, 2022
  84. Junio C HamanoMay 12, 2022
  85. Junio C HamanoMay 12, 2022
  86. René ScharfeMay 14, 2022
  87. fixup! archive: optionally add "virtual" filesJunio C Hamano, May 12, 2022
  88. 7/7 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, May 10, 2022
  89. Ævar Arnfjörð BjarmasonMay 17, 2022
  90. rsbecker@nexbridge.comMay 17, 2022
  91. Johannes SchindelinMay 19, 2022
  92. 0/7 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, May 19, 2022
  93. 1/7 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, May 19, 2022
  94. René ScharfeMay 20, 2022
  95. Junio C HamanoMay 20, 2022
  96. 2/7 archive --add-file-with-contents: allow paths containing colonsJohannes Schindelin via GitGitGadget, May 19, 2022
  97. 5/7 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, May 19, 2022
  98. 4/7 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, May 19, 2022
  99. 3/7 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, May 19, 2022
  100. 6/7 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, May 19, 2022
  101. 7/7 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, May 19, 2022
  102. Junio C HamanoMay 19, 2022
  103. 0/7 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, May 21, 2022
  104. 1/7 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, May 21, 2022
  105. Junio C HamanoMay 25, 2022
  106. René ScharfeMay 26, 2022
  107. Junio C HamanoMay 26, 2022
  108. René ScharfeMay 26, 2022
  109. Junio C HamanoMay 26, 2022
  110. René ScharfeMay 27, 2022
  111. Junio C HamanoMay 27, 2022
  112. René ScharfeMay 28, 2022
  113. 3/7 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, May 21, 2022
  114. 2/7 archive --add-virtual-file: allow paths containing colonsJohannes Schindelin via GitGitGadget, May 21, 2022
  115. Junio C HamanoMay 25, 2022
  116. Junio C HamanoMay 25, 2022
  117. Junio C HamanoMay 25, 2022
  118. 6/7 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, May 21, 2022
  119. 4/7 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, May 21, 2022
  120. 5/7 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, May 21, 2022
  121. 7/7 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, May 21, 2022
  122. 0/7 js/scalar-diagnose rebasedJunio C Hamano, May 28, 2022
  123. 1/7 archive: optionally add "virtual" filesJunio C Hamano, May 28, 2022
  124. 3/7 scalar: validate the optional enlistment argumentJunio C Hamano, May 28, 2022
  125. 2/7 archive --add-virtual-file: allow paths containing colonsJunio C Hamano, May 28, 2022
  126. Adam DinwoodieJun 15, 2022
  127. Junio C HamanoJun 15, 2022
  128. Adam DinwoodieJun 15, 2022
  129. Johannes SchindelinJun 18, 2022
  130. Junio C HamanoJun 18, 2022
  131. Adam DinwoodieJun 20, 2022
  132. 4/7 scalar: implement `scalar diagnose`Junio C Hamano, May 28, 2022
  133. Ævar Arnfjörð BjarmasonJun 10, 2022
  134. Junio C HamanoJun 10, 2022
  135. Ævar Arnfjörð BjarmasonJun 10, 2022
  136. 6/7 scalar: teach `diagnose` to gather packfile infoJunio C Hamano, May 28, 2022
  137. 7/7 scalar: teach `diagnose` to gather loose objects informationJunio C Hamano, May 28, 2022
  138. 5/7 scalar diagnose: include disk space informationJunio C Hamano, May 28, 2022
  139. Johannes SchindelinMay 30, 2022
  140. Junio C HamanoMay 30, 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.