]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
helpers: Limit verbose watch output for better readability
authormajiayu000 <1835304752@qq.com>
Tue, 30 Dec 2025 06:44:27 +0000 (14:44 +0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 30 Dec 2025 18:44:35 +0000 (19:44 +0100)
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 #14277

Signed-off-by: majiayu000 <1835304752@qq.com>
helpers/path.go
helpers/path_test.go

index 0b3fcce5aae19726f438b0d6bd52b7d96cbf9bbb..7e7ec025267e548b5cb3c7bd19af5cfa59cc1a7d 100644 (file)
@@ -137,6 +137,7 @@ func ExtractAndGroupRootPaths(in []string) []string {
                return nil
        }
        const maxGroups = 5
+       const maxRootGroups = 10
        sort.Strings(in)
        var groups []string
        tree := radix.New[[]string]()
@@ -186,6 +187,13 @@ LOOP:
 
        tree.Walk(collect)
 
+       // Limit the total number of root groups to keep output manageable
+       if len(groups) > maxRootGroups {
+               remaining := len(groups) - maxRootGroups
+               groups = groups[:maxRootGroups]
+               groups = append(groups, fmt.Sprintf("... and %d more", remaining))
+       }
+
        return groups
 }
 
index f8ca5251e369d35d58c1abb2ee19e0adce4aa494..a1928b2b5e269e503a8816455d39b0ebb4ced8eb 100644 (file)
@@ -345,19 +345,34 @@ func TestAbsPathify(t *testing.T) {
 }
 
 func TestExtractAndGroupRootPaths(t *testing.T) {
-       in := []string{
-               filepath.FromSlash("/a/b/c/d"),
-               filepath.FromSlash("/a/b/c/e"),
-               filepath.FromSlash("/a/b/e/f"),
-               filepath.FromSlash("/a/b"),
-               filepath.FromSlash("/a/b/c/b/g"),
-               filepath.FromSlash("/c/d/e"),
-       }
+       c := qt.New(t)
 
-       result := helpers.ExtractAndGroupRootPaths(in)
+       t.Run("Basic grouping", func(t *testing.T) {
+               in := []string{
+                       filepath.FromSlash("/a/b/c/d"),
+                       filepath.FromSlash("/a/b/c/e"),
+                       filepath.FromSlash("/a/b/e/f"),
+                       filepath.FromSlash("/a/b"),
+                       filepath.FromSlash("/a/b/c/b/g"),
+                       filepath.FromSlash("/c/d/e"),
+               }
 
-       c := qt.New(t)
-       c.Assert(result, qt.DeepEquals, []string{"/a/b/{c,e}", "/c/d/e"})
+               result := helpers.ExtractAndGroupRootPaths(in)
+               c.Assert(result, qt.DeepEquals, []string{"/a/b/{c,e}", "/c/d/e"})
+       })
+
+       t.Run("Limits number of root groups", func(t *testing.T) {
+               in := []string{}
+               // Create 15 different root paths to exceed maxRootGroups (10)
+               for i := 0; i < 15; i++ {
+                       in = append(in, filepath.FromSlash(fmt.Sprintf("/path%d/subdir", i)))
+               }
+
+               result := helpers.ExtractAndGroupRootPaths(in)
+               // Should have 10 paths + 1 "... and X more" message
+               c.Assert(len(result), qt.Equals, 11)
+               c.Assert(result[10], qt.Matches, `\.\.\. and \d+ more`)
+       })
 }
 
 func BenchmarkExtractAndGroupRootPaths(b *testing.B) {