Skip to content

Commit d3b5d47

Browse files
majiayu000bep
authored andcommitted
helpers: Limit verbose watch output for better readability
Limits the number of root groups shown in 'Watching for changes' output to 10 maximum, with a summary message for remaining paths. This prevents the message from becoming excessively long when watching sites with many mount points. Fixes gohugoio#14277 Signed-off-by: majiayu000 <1835304752@qq.com>
1 parent 86cd183 commit d3b5d47

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

‎helpers/path.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func ExtractAndGroupRootPaths(in []string) []string {
137137
return nil
138138
}
139139
const maxGroups = 5
140+
const maxRootGroups = 10
140141
sort.Strings(in)
141142
var groups []string
142143
tree := radix.New[[]string]()
@@ -186,6 +187,13 @@ LOOP:
186187

187188
tree.Walk(collect)
188189

190+
// Limit the total number of root groups to keep output manageable
191+
if len(groups) > maxRootGroups {
192+
remaining := len(groups) - maxRootGroups
193+
groups = groups[:maxRootGroups]
194+
groups = append(groups, fmt.Sprintf("... and %d more", remaining))
195+
}
196+
189197
return groups
190198
}
191199

‎helpers/path_test.go‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,34 @@ func TestAbsPathify(t *testing.T) {
345345
}
346346

347347
func TestExtractAndGroupRootPaths(t *testing.T) {
348-
in := []string{
349-
filepath.FromSlash("/a/b/c/d"),
350-
filepath.FromSlash("/a/b/c/e"),
351-
filepath.FromSlash("/a/b/e/f"),
352-
filepath.FromSlash("/a/b"),
353-
filepath.FromSlash("/a/b/c/b/g"),
354-
filepath.FromSlash("/c/d/e"),
355-
}
348+
c := qt.New(t)
356349

357-
result := helpers.ExtractAndGroupRootPaths(in)
350+
t.Run("Basic grouping", func(t *testing.T) {
351+
in := []string{
352+
filepath.FromSlash("/a/b/c/d"),
353+
filepath.FromSlash("/a/b/c/e"),
354+
filepath.FromSlash("/a/b/e/f"),
355+
filepath.FromSlash("/a/b"),
356+
filepath.FromSlash("/a/b/c/b/g"),
357+
filepath.FromSlash("/c/d/e"),
358+
}
358359

359-
c := qt.New(t)
360-
c.Assert(result, qt.DeepEquals, []string{"/a/b/{c,e}", "/c/d/e"})
360+
result := helpers.ExtractAndGroupRootPaths(in)
361+
c.Assert(result, qt.DeepEquals, []string{"/a/b/{c,e}", "/c/d/e"})
362+
})
363+
364+
t.Run("Limits number of root groups", func(t *testing.T) {
365+
in := []string{}
366+
// Create 15 different root paths to exceed maxRootGroups (10)
367+
for i := 0; i < 15; i++ {
368+
in = append(in, filepath.FromSlash(fmt.Sprintf("/path%d/subdir", i)))
369+
}
370+
371+
result := helpers.ExtractAndGroupRootPaths(in)
372+
// Should have 10 paths + 1 "... and X more" message
373+
c.Assert(len(result), qt.Equals, 11)
374+
c.Assert(result[10], qt.Matches, `\.\.\. and \d+ more`)
375+
})
361376
}
362377

363378
func BenchmarkExtractAndGroupRootPaths(b *testing.B) {

0 commit comments

Comments
 (0)