Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: get info from a 'bare' repo instead #487

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansi/ansi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
printTests = false
)

func makeReal(s string) string { //nolint
func makeReal(s string) string { //nolint
return strings.Replace(s, "~", "\x1b", -1)
}

Expand Down
1 change: 1 addition & 0 deletions ansi/tty.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package ansi
Expand Down
2 changes: 1 addition & 1 deletion ansi/tty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var (
modkernel32 = syscall.MustLoadDLL("kernel32.dll")
modkernel32 = syscall.MustLoadDLL("kernel32.dll")
procGetConsoleMode = modkernel32.MustFindProc("GetConsoleMode")
)

Expand Down
6 changes: 3 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func searchAll(
*filesOpened += r.res.FilesOpened
}

*duration = int(time.Now().Sub(startedAt).Seconds() * 1000) //nolint
*duration = int(time.Now().Sub(startedAt).Seconds() * 1000) //nolint

return res, nil
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func Setup(m *http.ServeMux, idx map[string]*searcher.Searcher, defaultMaxResult

type Webhook struct {
Repository struct {
Name string
Name string
Full_name string
}
}
Expand All @@ -291,7 +291,7 @@ func Setup(m *http.ServeMux, idx map[string]*searcher.Searcher, defaultMaxResult
err := json.NewDecoder(r.Body).Decode(&h)

if err != nil {
writeError(w,
writeError(w,
errors.New(http.StatusText(http.StatusBadRequest)),
http.StatusBadRequest)
return
Expand Down
32 changes: 16 additions & 16 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ import (

var parseAsIntAndUintTests = map[string]struct {
numResults string
min int
max int
def int
expected int
} {
"parse error test case": {"not a parsable integer", 101, 1000, 5000, 5000},
"less than min test case": {"100", 101, 1000, 5000, 101},
min int
max int
def int
expected int
}{
"parse error test case": {"not a parsable integer", 101, 1000, 5000, 5000},
"less than min test case": {"100", 101, 1000, 5000, 101},
"greater than max test case": {"1001", 101, 1000, 5000, 1000},
"within limits test case": {"100", 0, 100, 5000, 100},
"within limits test case": {"100", 0, 100, 5000, 100},
}

func TestParseAsIntAndUint(t *testing.T) {
for name, td := range parseAsIntAndUintTests {
t.Run(name, func(t *testing.T) {
if got, expected :=
if got, expected :=
parseAsUintValue(td.numResults, uint(td.min), uint(td.max), uint(td.def)), uint(td.expected); got != expected {
t.Fatalf("parseAsUintValue - %s: returned %d; expected %d", name, got, expected)
}
t.Fatalf("parseAsUintValue - %s: returned %d; expected %d", name, got, expected)
}

if got, expected :=
if got, expected :=
parseAsIntValue(td.numResults, td.min, td.max, td.def), td.expected; got != expected {
t.Fatalf("parseAsIntValue - %s: returned %d; expected %d", name, got, expected)
}
})
t.Fatalf("parseAsIntValue - %s: returned %d; expected %d", name, got, expected)
}
})
}
}
}
4 changes: 2 additions & 2 deletions client/coalesce.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func matchToBlock(m *index.Match) *Block {

v[b] = true

for _, line := range m.Before { //nolint
for _, line := range m.Before { //nolint
l = append(l, line)
}

l = append(l, m.Line)

for _, line := range m.After { //nolint
for _, line := range m.After { //nolint
l = append(l, line)
}

Expand Down
51 changes: 26 additions & 25 deletions codesearch/index/mmap_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,45 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build darwin || freebsd || openbsd || netbsd
// +build darwin freebsd openbsd netbsd

package index

import (
"log"
"os"
"syscall"
"log"
"os"
"syscall"
)

func mmapFile(f *os.File) mmapData {
st, err := f.Stat()
if err != nil {
log.Fatal(err)
}
size := st.Size()
if int64(int(size+4095)) != size+4095 {
log.Fatalf("%s: too large for mmap", f.Name())
}
n := int(size)
if n == 0 {
return mmapData{f, nil, nil}
}
data, err := syscall.Mmap(int(f.Fd()), 0, (n+4095)&^4095, syscall.PROT_READ, syscall.MAP_PRIVATE)
if err != nil {
log.Fatalf("mmap %s: %v", f.Name(), err)
}
return mmapData{f, data[:n], data}
st, err := f.Stat()
if err != nil {
log.Fatal(err)
}
size := st.Size()
if int64(int(size+4095)) != size+4095 {
log.Fatalf("%s: too large for mmap", f.Name())
}
n := int(size)
if n == 0 {
return mmapData{f, nil, nil}
}
data, err := syscall.Mmap(int(f.Fd()), 0, (n+4095)&^4095, syscall.PROT_READ, syscall.MAP_PRIVATE)
if err != nil {
log.Fatalf("mmap %s: %v", f.Name(), err)
}
return mmapData{f, data[:n], data}
}

func unmmapFile(m *mmapData) error {
if err := syscall.Munmap(m.o); err != nil {
return err
}
if err := syscall.Munmap(m.o); err != nil {
return err
}

return m.f.Close()
return m.f.Close()
}

func unmmap(d []byte) error {
return syscall.Munmap(d)
return syscall.Munmap(d)
}
50 changes: 25 additions & 25 deletions codesearch/index/mmap_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@
package index

import (
"log"
"os"
"syscall"
"log"
"os"
"syscall"
)

func mmapFile(f *os.File) mmapData {
st, err := f.Stat()
if err != nil {
log.Fatal(err)
}
size := st.Size()
if int64(int(size+4095)) != size+4095 {
log.Fatalf("%s: too large for mmap", f.Name())
}
n := int(size)
if n == 0 {
return mmapData{f, nil, nil}
}
data, err := syscall.Mmap(int(f.Fd()), 0, (n+4095)&^4095, syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
log.Fatalf("mmap %s: %v", f.Name(), err)
}
return mmapData{f, data[:n], data}
st, err := f.Stat()
if err != nil {
log.Fatal(err)
}
size := st.Size()
if int64(int(size+4095)) != size+4095 {
log.Fatalf("%s: too large for mmap", f.Name())
}
n := int(size)
if n == 0 {
return mmapData{f, nil, nil}
}
data, err := syscall.Mmap(int(f.Fd()), 0, (n+4095)&^4095, syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
log.Fatalf("mmap %s: %v", f.Name(), err)
}
return mmapData{f, data[:n], data}
}

func unmmapFile(m *mmapData) error {
if err := syscall.Munmap(m.o); err != nil {
return err
}
if err := syscall.Munmap(m.o); err != nil {
return err
}

return m.f.Close()
return m.f.Close()
}

func unmmap(d []byte) error {
return syscall.Munmap(d)
return syscall.Munmap(d)
}
2 changes: 1 addition & 1 deletion codesearch/index/mmap_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ func unmmapFile(m *mmapData) error {

func unmmap(d []byte) error {
return syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&d)))
}
}
Loading