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