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

[PATCH v2 0/3] speed up git reset

From
Ben Peart <peartben@gmail.com>
Date
Oct 19, 2018, 16:12 UTC
Message-ID
<20181019161228.17196-1-peartben@gmail.com>
In-Reply-To
<20181017164021.15204-1-peartben@gmail.com>
From: Ben Peart <benpeart@microsoft.com>

This itteration avoids the refresh_index() call completely if 'quiet'. The advantage of this is that "git refresh" without any pathspec is also significantly sped up.

Also added a notification if finding unstaged changes after reset takes longer than 2 seconds to make users aware of the option to speed it up if they don't need the unstaged changes after reset to be output.

It also renames the new config setting reset.quietDefault to reset.quiet.
Base Ref: 
Web-Diff: https://github.com/benpeart/git/commit/50d3415ef1
Checkout: git fetch https://github.com/benpeart/git reset-refresh-index-v2 && git checkout 50d3415ef1
### Interdiff (v1..v2):
diff --git a/Documentation/config.txt b/Documentation/config.txt
index a5cf4c019b..a2d1b8b116 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2728,11 +2728,8 @@ rerere.enabled::
 	`$GIT_DIR`, e.g. if "rerere" was previously used in the
 	repository.
 
-reset.quietDefault::
-	Sets the default value of the "quiet" option for the reset command.
-	Choosing "quiet" can optimize the performance of the reset command
-	by avoiding the scan of all files in the repo looking for additional
-	unstaged changes. Defaults to false.
+reset.quiet::
+	When set to true, 'git reset' will default to the '--quiet' option.
 
 include::sendemail-config.txt[]
 
diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt
index 8610309b55..1d697d9962 100644
--- a/Documentation/git-reset.txt
+++ b/Documentation/git-reset.txt
@@ -95,9 +95,7 @@ OPTIONS
 
 -q::
 --quiet::
-	Be quiet, only report errors.  Can optimize the performance of reset
-	by avoiding scaning all files in the repo looking for additional
-	unstaged changes.
+	Be quiet, only report errors.
 
 
 EXAMPLES
diff --git a/builtin/reset.c b/builtin/reset.c
index 7d151d48a0..d95a27d52e 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -25,6 +25,8 @@
 #include "submodule.h"
 #include "submodule-config.h"
 
+#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
+
 static const char * const git_reset_usage[] = {
 	N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"),
 	N_("git reset [-q] [<tree-ish>] [--] <paths>..."),
@@ -306,7 +308,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 	};
 
 	git_config(git_reset_config, NULL);
-	git_config_get_bool("reset.quietDefault", &quiet);
+	git_config_get_bool("reset.quiet", &quiet);
 
 	argc = parse_options(argc, argv, prefix, options, git_reset_usage,
 						PARSE_OPT_KEEP_DASHDASH);
@@ -376,9 +378,19 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 			int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
 			if (read_from_tree(&pathspec, &oid, intent_to_add))
 				return 1;
-			if (get_git_work_tree())
-				refresh_index(&the_index, flags, quiet ? &pathspec : NULL, NULL,
+			if (!quiet && get_git_work_tree()) {
+				uint64_t t_begin, t_delta_in_ms;
+
+				t_begin = getnanotime();
+				refresh_index(&the_index, flags, NULL, NULL,
 					      _("Unstaged changes after reset:"));
+				t_delta_in_ms = (getnanotime() - t_begin) / 1000000;
+				if (t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {
+					printf(_("\nIt took %.2f seconds to enumerate unstaged changes after reset.  You can\n"
+						"use '--quiet' to avoid this.  Set the config setting reset.quiet to true\n"
+						"to make this the default."), t_delta_in_ms / 1000.0);
+				}
+			}
 		} else {
 			int err = reset_index(&oid, reset_type, quiet);
 			if (reset_type == KEEP && !err)


### Patches

Ben Peart (3):
  reset: don't compute unstaged changes after reset when --quiet
  reset: add new reset.quiet config setting
  reset: warn when refresh_index() takes more than 2 seconds

 Documentation/config.txt |  3 +++
 builtin/reset.c          | 15 ++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)


base-commit: ca63497355222acefcca02b9cbb540a4768f3286
-- 
2.18.0.windows.1
Previous: Junio C HamanoNext: Ben Peart
Message 21 of 63 in “speed up git reset”
  1. 0/2 speed up git resetBen Peart, Oct 17, 2018
  2. 1/2 reset: don't compute unstaged changes after reset when --quietBen Peart, Oct 17, 2018
  3. Eric SunshineOct 17, 2018
  4. Jeff KingOct 17, 2018
  5. Junio C HamanoOct 18, 2018
  6. Jeff KingOct 18, 2018
  7. Ben PeartOct 18, 2018
  8. Duy NguyenOct 18, 2018
  9. Ben PeartOct 18, 2018
  10. Junio C HamanoOct 19, 2018
  11. 2/2 reset: add new reset.quietDefault config settingBen Peart, Oct 17, 2018
  12. Eric SunshineOct 17, 2018
  13. Jeff KingOct 17, 2018
  14. Ævar Arnfjörð BjarmasonOct 23, 2018
  15. Ben PeartOct 23, 2018
  16. Jeff KingOct 23, 2018
  17. Ævar Arnfjörð BjarmasonOct 23, 2018
  18. Recommended configurations (was Re: [PATCH v1 2/2] reset: add new reset.quietDefault config setting)Derrick Stolee, Oct 24, 2018
  19. Jeff KingOct 24, 2018
  20. Junio C HamanoOct 25, 2018
  21. 0/3 speed up git resetBen Peart, Oct 19, 2018
  22. 1/3 reset: don't compute unstaged changes after reset when --quietBen Peart, Oct 19, 2018
  23. 2/3 reset: add new reset.quiet config settingBen Peart, Oct 19, 2018
  24. Eric SunshineOct 19, 2018
  25. Jeff KingOct 19, 2018
  26. Eric SunshineOct 19, 2018
  27. Jeff KingOct 19, 2018
  28. Ben PeartOct 19, 2018
  29. Jeff KingOct 19, 2018
  30. Junio C HamanoOct 22, 2018
  31. Ben PeartOct 19, 2018
  32. 3/3 reset: warn when refresh_index() takes more than 2 secondsBen Peart, Oct 19, 2018
  33. 0/3 speed up git resetBen Peart, Oct 22, 2018
  34. 1/3 reset: don't compute unstaged changes after reset when --quietBen Peart, Oct 22, 2018
  35. Johannes SchindelinOct 22, 2018
  36. Ben PeartOct 22, 2018
  37. Johannes SchindelinOct 23, 2018
  38. Duy NguyenOct 23, 2018
  39. Johannes SchindelinOct 23, 2018
  40. 2/3 reset: add new reset.quiet config settingBen Peart, Oct 22, 2018
  41. Duy NguyenOct 22, 2018
  42. Ben PeartOct 23, 2018
  43. Junio C HamanoOct 24, 2018
  44. Junio C HamanoOct 24, 2018
  45. Duy NguyenOct 24, 2018
  46. Junio C HamanoOct 25, 2018
  47. Duy NguyenOct 24, 2018
  48. Ramsay JonesOct 22, 2018
  49. Jeff KingOct 22, 2018
  50. Ben PeartOct 23, 2018
  51. Jeff KingOct 23, 2018
  52. 3/3 reset: warn when refresh_index() takes more than 2 secondsBen Peart, Oct 22, 2018
  53. Junio C HamanoOct 23, 2018
  54. Ben PeartOct 23, 2018
  55. 0/3 speed up git resetBen Peart, Oct 23, 2018
  56. 1/3 reset: don't compute unstaged changes after reset when --quietBen Peart, Oct 23, 2018
  57. 2/3 reset: add new reset.quiet config settingBen Peart, Oct 23, 2018
  58. Ramsay JonesOct 24, 2018
  59. Junio C HamanoOct 25, 2018
  60. Junio C HamanoOct 25, 2018
  61. Ben PeartOct 25, 2018
  62. Ramsay JonesOct 25, 2018
  63. 3/3 reset: warn when refresh_index() takes more than 2 secondsBen Peart, Oct 23, 2018

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.