mirror of https://git.jolheiser.com/ugit.git
Compare commits
No commits in common. "3faedb82368c46a3f424770d300ecb85dd4a6e91" and "00b0d91307a8d604d96ccf84e7e8967720072fea" have entirely different histories.
3faedb8236
...
00b0d91307
|
@ -18,10 +18,8 @@ type GrepResult struct {
|
||||||
|
|
||||||
// Grep performs a naive "code search" via git grep
|
// Grep performs a naive "code search" via git grep
|
||||||
func (r Repo) Grep(search string) ([]GrepResult, error) {
|
func (r Repo) Grep(search string) ([]GrepResult, error) {
|
||||||
if strings.HasPrefix(search, "=") {
|
// Plain-text search only
|
||||||
search = regexp.QuoteMeta(strings.TrimPrefix(search, "="))
|
re, err := regexp.Compile(regexp.QuoteMeta(search))
|
||||||
}
|
|
||||||
re, err := regexp.Compile(search)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,16 +13,18 @@ func (s SearchContext) DedupeResults() [][]git.GrepResult {
|
||||||
var (
|
var (
|
||||||
results [][]git.GrepResult
|
results [][]git.GrepResult
|
||||||
currentFile string
|
currentFile string
|
||||||
|
currentResults []git.GrepResult
|
||||||
)
|
)
|
||||||
var idx int
|
|
||||||
for _, result := range s.Results {
|
for _, result := range s.Results {
|
||||||
if result.File == currentFile {
|
if result.File == currentFile {
|
||||||
results[idx] = append(results[idx], result)
|
currentResults = append(currentResults, result)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
results = append(results, []git.GrepResult{result})
|
if currentFile != "" {
|
||||||
|
results = append(results, currentResults)
|
||||||
|
}
|
||||||
currentFile = result.File
|
currentFile = result.File
|
||||||
idx++
|
currentResults = []git.GrepResult{result}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -23,16 +23,18 @@ func (s SearchContext) DedupeResults() [][]git.GrepResult {
|
||||||
var (
|
var (
|
||||||
results [][]git.GrepResult
|
results [][]git.GrepResult
|
||||||
currentFile string
|
currentFile string
|
||||||
|
currentResults []git.GrepResult
|
||||||
)
|
)
|
||||||
var idx int
|
|
||||||
for _, result := range s.Results {
|
for _, result := range s.Results {
|
||||||
if result.File == currentFile {
|
if result.File == currentFile {
|
||||||
results[idx] = append(results[idx], result)
|
currentResults = append(currentResults, result)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
results = append(results, []git.GrepResult{result})
|
if currentFile != "" {
|
||||||
|
results = append(results, currentResults)
|
||||||
|
}
|
||||||
currentFile = result.File
|
currentFile = result.File
|
||||||
idx++
|
currentResults = []git.GrepResult{result}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
@ -126,7 +128,7 @@ func repoSearchResult(repo, ref string, results []git.GrepResult) templ.Componen
|
||||||
var templ_7745c5c3_Var5 string
|
var templ_7745c5c3_Var5 string
|
||||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(results[0].File)
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(results[0].File)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 48, Col: 230}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 50, Col: 230}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
|
@ -152,7 +154,7 @@ func repoSearchResult(repo, ref string, results []git.GrepResult) templ.Componen
|
||||||
var templ_7745c5c3_Var6 string
|
var templ_7745c5c3_Var6 string
|
||||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d ", len(results[1:])))
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d ", len(results[1:])))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 54, Col: 50}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 56, Col: 50}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
|
@ -179,7 +181,7 @@ func repoSearchResult(repo, ref string, results []git.GrepResult) templ.Componen
|
||||||
var templ_7745c5c3_Var8 string
|
var templ_7745c5c3_Var8 string
|
||||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(results[0].File)
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(results[0].File)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 56, Col: 230}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 58, Col: 230}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
|
|
|
@ -206,6 +206,7 @@ func (rh repoHandler) repoSearch(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
results[idx].Content = buf.String()
|
results[idx].Content = buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := html.RepoSearch(html.SearchContext{
|
if err := html.RepoSearch(html.SearchContext{
|
||||||
|
|
Loading…
Reference in New Issue