-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.go
More file actions
47 lines (40 loc) · 1002 Bytes
/
Copy pathlist.go
File metadata and controls
47 lines (40 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"context"
"fmt"
"io"
"log"
"os"
"strings"
"github.com/sourcegraph/zoekt"
"github.com/sourcegraph/zoekt/query"
"github.com/sourcegraph/zoekt/search"
)
func cmdList() {
log.SetOutput(io.Discard)
indexDir := defaultIndexDir()
searcher, err := search.NewDirectorySearcher(indexDir)
if err != nil {
fmt.Fprintf(os.Stderr, "fall: no index at %s\n", indexDir)
fmt.Fprintf(os.Stderr, "Run: fall add <repo-path>\n")
os.Exit(1)
}
defer searcher.Close()
repos, err := searcher.List(context.Background(), &query.Const{Value: true}, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "fall: %v\n", err)
os.Exit(1)
}
for _, r := range repos.Repos {
name := r.Repository.Name
short := name
if i := strings.LastIndex(name, "/"); i >= 0 {
short = name[i+1:]
}
fmt.Printf("%-20s %s (%d files, %d branches)\n",
short, name, r.Stats.Documents, countBranches(r.Repository))
}
}
func countBranches(repo zoekt.Repository) int {
return len(repo.Branches)
}