Skip to content

Commit

Permalink
gitindex: store the complete zoekt.* config into Repository metadata
Browse files Browse the repository at this point in the history
Change-Id: I161c4876422616a5ce4157d3fdc96d5a500d1dc7
  • Loading branch information
hanwen committed Oct 3, 2017
1 parent fd8564a commit eb5aced
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
3 changes: 3 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ type Repository struct {
// The URL fragment to add to a file URL for line numbers.
// has access to {{LineNumber}}.
LineFragmentTemplate string

// All zoekt.* configuration settings.
RawConfig map[string]string
}

// IndexMetadata holds metadata stored in the index file.
Expand Down
32 changes: 18 additions & 14 deletions gitindex/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/object"

git "gopkg.in/src-d/go-git.v4"
plumcfg "gopkg.in/src-d/go-git.v4/plumbing/format/config"
)

// RepoModTime returns the time of last fetch of a git repository.
Expand Down Expand Up @@ -156,19 +157,12 @@ func configLookupRemoteURL(cfg *config.Config, key string) string {
return rc.URLs[0]
}

func configLookupString(cfg *config.Config, key string) string {
fields := strings.Split(key, ".")
for _, s := range cfg.Raw.Sections {
if s.Name != fields[0] {
func configLookupString(sec *plumcfg.Section, key string) string {
for _, o := range sec.Options {
if o.Key != key {
continue
}

for _, o := range s.Options {
if o.Key != fields[1] {
continue
}
return o.Value
}
return o.Value
}

return ""
Expand All @@ -189,9 +183,11 @@ func setTemplatesFromConfig(desc *zoekt.Repository, repoDir string) error {
return err
}

webURLStr := configLookupString(cfg, "zoekt.web-url")
sec := cfg.Raw.Section("zoekt")

webURLStr := configLookupString(sec, "web-url")

webURLType := configLookupString(cfg, "zoekt.web-url-type")
webURLType := configLookupString(sec, "web-url-type")

if webURLType != "" && webURLStr != "" {
webURL, err := url.Parse(webURLStr)
Expand All @@ -203,7 +199,7 @@ func setTemplatesFromConfig(desc *zoekt.Repository, repoDir string) error {
}
}

name := configLookupString(cfg, "zoekt.name")
name := configLookupString(sec, "name")
if name != "" {
desc.Name = name
} else {
Expand All @@ -219,6 +215,14 @@ func setTemplatesFromConfig(desc *zoekt.Repository, repoDir string) error {
return err
}
}

if desc.RawConfig == nil {
desc.RawConfig = map[string]string{}
}
for _, o := range sec.Options {
desc.RawConfig[o.Key] = o.Value
}

return nil
}

Expand Down

0 comments on commit eb5aced

Please sign in to comment.