fork of https://github.com/sourcegraph/zoekt
1// Command zoekt-archive-index indexes an archive.
2//
3// Example via github.com:
4//
5// zoekt-archive-index -incremental -commit b57cb1605fd11ba2ecfa7f68992b4b9cc791934d -name github.com/gorilla/mux -strip_components 1 https://codeload.github.com/gorilla/mux/legacy.tar.gz/b57cb1605fd11ba2ecfa7f68992b4b9cc791934d
6//
7// zoekt-archive-index -branch master https://github.com/gorilla/mux/commit/b57cb1605fd11ba2ecfa7f68992b4b9cc791934d
8package main
9
10import (
11 "flag"
12 "log"
13
14 "go.uber.org/automaxprocs/maxprocs"
15
16 "github.com/sourcegraph/zoekt/cmd"
17 "github.com/sourcegraph/zoekt/internal/archive"
18)
19
20func main() {
21 var (
22 incremental = flag.Bool("incremental", true, "only index changed repositories")
23
24 name = flag.String("name", "", "The repository name for the archive")
25 urlRaw = flag.String("url", "", "The repository URL for the archive")
26 branch = flag.String("branch", "", "The branch name for the archive")
27 commit = flag.String("commit", "", "The commit sha for the archive. If incremental this will avoid updating shards already at commit")
28 strip = flag.Int("strip_components", 0, "Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped.")
29
30 downloadLimitMbps = flag.Int64("download-limit-mbps", 0, "If non-zero, limit archive downloads to specified amount in megabits per second")
31 )
32 flag.Parse()
33
34 // Tune GOMAXPROCS to match Linux container CPU quota.
35 _, _ = maxprocs.Set()
36
37 log.SetFlags(log.LstdFlags | log.Lshortfile)
38
39 if len(flag.Args()) != 1 {
40 log.Fatal("expected argument for archive location")
41 }
42 archiveURL := flag.Args()[0]
43 bopts := cmd.OptionsFromFlags()
44 opts := archive.Options{
45 Incremental: *incremental,
46
47 Archive: archiveURL,
48 Name: *name,
49 RepoURL: *urlRaw,
50 Branch: *branch,
51 Commit: *commit,
52 Strip: *strip,
53 }
54
55 // Sourcegraph specific: Limit HTTP traffic
56 limitHTTPDefaultClient(*downloadLimitMbps)
57
58 if err := archive.Index(opts, *bopts); err != nil {
59 log.Fatal(err)
60 }
61}