id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
150,300 | cenkalti/backoff | context.go | WithContext | func WithContext(b BackOff, ctx context.Context) BackOffContext {
if ctx == nil {
panic("nil context")
}
if b, ok := b.(*backOffContext); ok {
return &backOffContext{
BackOff: b.BackOff,
ctx: ctx,
}
}
return &backOffContext{
BackOff: b,
ctx: ctx,
}
} | go | func WithContext(b BackOff, ctx context.Context) BackOffContext {
if ctx == nil {
panic("nil context")
}
if b, ok := b.(*backOffContext); ok {
return &backOffContext{
BackOff: b.BackOff,
ctx: ctx,
}
}
return &backOffContext{
BackOff: b,
ctx: ctx,
}
} | [
"func",
"WithContext",
"(",
"b",
"BackOff",
",",
"ctx",
"context",
".",
"Context",
")",
"BackOffContext",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"b",
",",
"ok",
":=",
"b",
".",
"(",
"*",
"backOffContext",
")",
";",
"ok",
"{",
"return",
"&",
"backOffContext",
"{",
"BackOff",
":",
"b",
".",
"BackOff",
",",
"ctx",
":",
"ctx",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"backOffContext",
"{",
"BackOff",
":",
"b",
",",
"ctx",
":",
"ctx",
",",
"}",
"\n",
"}"
] | // WithContext returns a BackOffContext with context ctx
//
// ctx must not be nil | [
"WithContext",
"returns",
"a",
"BackOffContext",
"with",
"context",
"ctx",
"ctx",
"must",
"not",
"be",
"nil"
] | 1e4cf3da559842a91afcb6ea6141451e6c30c618 | https://github.com/cenkalti/backoff/blob/1e4cf3da559842a91afcb6ea6141451e6c30c618/context.go#L23-L39 |
150,301 | sideshow/apns2 | notification.go | MarshalJSON | func (n *Notification) MarshalJSON() ([]byte, error) {
switch n.Payload.(type) {
case string:
return []byte(n.Payload.(string)), nil
case []byte:
return n.Payload.([]byte), nil
default:
return json.Marshal(n.Payload)
}
} | go | func (n *Notification) MarshalJSON() ([]byte, error) {
switch n.Payload.(type) {
case string:
return []byte(n.Payload.(string)), nil
case []byte:
return n.Payload.([]byte), nil
default:
return json.Marshal(n.Payload)
}
} | [
"func",
"(",
"n",
"*",
"Notification",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"n",
".",
"Payload",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"[",
"]",
"byte",
"(",
"n",
".",
"Payload",
".",
"(",
"string",
")",
")",
",",
"nil",
"\n",
"case",
"[",
"]",
"byte",
":",
"return",
"n",
".",
"Payload",
".",
"(",
"[",
"]",
"byte",
")",
",",
"nil",
"\n",
"default",
":",
"return",
"json",
".",
"Marshal",
"(",
"n",
".",
"Payload",
")",
"\n",
"}",
"\n",
"}"
] | // MarshalJSON converts the notification payload to JSON. | [
"MarshalJSON",
"converts",
"the",
"notification",
"payload",
"to",
"JSON",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/notification.go#L71-L80 |
150,302 | sideshow/apns2 | token/token.go | GenerateIfExpired | func (t *Token) GenerateIfExpired() {
t.Lock()
defer t.Unlock()
if t.Expired() {
t.Generate()
}
} | go | func (t *Token) GenerateIfExpired() {
t.Lock()
defer t.Unlock()
if t.Expired() {
t.Generate()
}
} | [
"func",
"(",
"t",
"*",
"Token",
")",
"GenerateIfExpired",
"(",
")",
"{",
"t",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"Unlock",
"(",
")",
"\n",
"if",
"t",
".",
"Expired",
"(",
")",
"{",
"t",
".",
"Generate",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // GenerateIfExpired checks to see if the token is about to expire and
// generates a new token. | [
"GenerateIfExpired",
"checks",
"to",
"see",
"if",
"the",
"token",
"is",
"about",
"to",
"expire",
"and",
"generates",
"a",
"new",
"token",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/token/token.go#L71-L77 |
150,303 | sideshow/apns2 | token/token.go | Expired | func (t *Token) Expired() bool {
return time.Now().Unix() >= (t.IssuedAt + TokenTimeout)
} | go | func (t *Token) Expired() bool {
return time.Now().Unix() >= (t.IssuedAt + TokenTimeout)
} | [
"func",
"(",
"t",
"*",
"Token",
")",
"Expired",
"(",
")",
"bool",
"{",
"return",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
">=",
"(",
"t",
".",
"IssuedAt",
"+",
"TokenTimeout",
")",
"\n",
"}"
] | // Expired checks to see if the token has expired. | [
"Expired",
"checks",
"to",
"see",
"if",
"the",
"token",
"has",
"expired",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/token/token.go#L80-L82 |
150,304 | sideshow/apns2 | token/token.go | Generate | func (t *Token) Generate() (bool, error) {
if t.AuthKey == nil {
return false, ErrAuthKeyNil
}
issuedAt := time.Now().Unix()
jwtToken := &jwt.Token{
Header: map[string]interface{}{
"alg": "ES256",
"kid": t.KeyID,
},
Claims: jwt.MapClaims{
"iss": t.TeamID,
"iat": issuedAt,
},
Method: jwt.SigningMethodES256,
}
bearer, err := jwtToken.SignedString(t.AuthKey)
if err != nil {
return false, err
}
t.IssuedAt = issuedAt
t.Bearer = bearer
return true, nil
} | go | func (t *Token) Generate() (bool, error) {
if t.AuthKey == nil {
return false, ErrAuthKeyNil
}
issuedAt := time.Now().Unix()
jwtToken := &jwt.Token{
Header: map[string]interface{}{
"alg": "ES256",
"kid": t.KeyID,
},
Claims: jwt.MapClaims{
"iss": t.TeamID,
"iat": issuedAt,
},
Method: jwt.SigningMethodES256,
}
bearer, err := jwtToken.SignedString(t.AuthKey)
if err != nil {
return false, err
}
t.IssuedAt = issuedAt
t.Bearer = bearer
return true, nil
} | [
"func",
"(",
"t",
"*",
"Token",
")",
"Generate",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"t",
".",
"AuthKey",
"==",
"nil",
"{",
"return",
"false",
",",
"ErrAuthKeyNil",
"\n",
"}",
"\n",
"issuedAt",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
"\n",
"jwtToken",
":=",
"&",
"jwt",
".",
"Token",
"{",
"Header",
":",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"t",
".",
"KeyID",
",",
"}",
",",
"Claims",
":",
"jwt",
".",
"MapClaims",
"{",
"\"",
"\"",
":",
"t",
".",
"TeamID",
",",
"\"",
"\"",
":",
"issuedAt",
",",
"}",
",",
"Method",
":",
"jwt",
".",
"SigningMethodES256",
",",
"}",
"\n",
"bearer",
",",
"err",
":=",
"jwtToken",
".",
"SignedString",
"(",
"t",
".",
"AuthKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"t",
".",
"IssuedAt",
"=",
"issuedAt",
"\n",
"t",
".",
"Bearer",
"=",
"bearer",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // Generate creates a new token. | [
"Generate",
"creates",
"a",
"new",
"token",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/token/token.go#L85-L108 |
150,305 | sideshow/apns2 | client.go | Push | func (c *Client) Push(n *Notification) (*Response, error) {
return c.PushWithContext(nil, n)
} | go | func (c *Client) Push(n *Notification) (*Response, error) {
return c.PushWithContext(nil, n)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Push",
"(",
"n",
"*",
"Notification",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"return",
"c",
".",
"PushWithContext",
"(",
"nil",
",",
"n",
")",
"\n",
"}"
] | // Push sends a Notification to the APNs gateway. If the underlying http.Client
// is not currently connected, this method will attempt to reconnect
// transparently before sending the notification. It will return a Response
// indicating whether the notification was accepted or rejected by the APNs
// gateway, or an error if something goes wrong.
//
// Use PushWithContext if you need better cancellation and timeout control. | [
"Push",
"sends",
"a",
"Notification",
"to",
"the",
"APNs",
"gateway",
".",
"If",
"the",
"underlying",
"http",
".",
"Client",
"is",
"not",
"currently",
"connected",
"this",
"method",
"will",
"attempt",
"to",
"reconnect",
"transparently",
"before",
"sending",
"the",
"notification",
".",
"It",
"will",
"return",
"a",
"Response",
"indicating",
"whether",
"the",
"notification",
"was",
"accepted",
"or",
"rejected",
"by",
"the",
"APNs",
"gateway",
"or",
"an",
"error",
"if",
"something",
"goes",
"wrong",
".",
"Use",
"PushWithContext",
"if",
"you",
"need",
"better",
"cancellation",
"and",
"timeout",
"control",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/client.go#L137-L139 |
150,306 | sideshow/apns2 | client.go | PushWithContext | func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error) {
payload, err := json.Marshal(n)
if err != nil {
return nil, err
}
url := fmt.Sprintf("%v/3/device/%v", c.Host, n.DeviceToken)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if c.Token != nil {
c.setTokenHeader(req)
}
setHeaders(req, n)
httpRes, err := c.requestWithContext(ctx, req)
if err != nil {
return nil, err
}
defer httpRes.Body.Close()
response := &Response{}
response.StatusCode = httpRes.StatusCode
response.ApnsID = httpRes.Header.Get("apns-id")
decoder := json.NewDecoder(httpRes.Body)
if err := decoder.Decode(&response); err != nil && err != io.EOF {
return &Response{}, err
}
return response, nil
} | go | func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error) {
payload, err := json.Marshal(n)
if err != nil {
return nil, err
}
url := fmt.Sprintf("%v/3/device/%v", c.Host, n.DeviceToken)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if c.Token != nil {
c.setTokenHeader(req)
}
setHeaders(req, n)
httpRes, err := c.requestWithContext(ctx, req)
if err != nil {
return nil, err
}
defer httpRes.Body.Close()
response := &Response{}
response.StatusCode = httpRes.StatusCode
response.ApnsID = httpRes.Header.Get("apns-id")
decoder := json.NewDecoder(httpRes.Body)
if err := decoder.Decode(&response); err != nil && err != io.EOF {
return &Response{}, err
}
return response, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"PushWithContext",
"(",
"ctx",
"Context",
",",
"n",
"*",
"Notification",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"payload",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"n",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Host",
",",
"n",
".",
"DeviceToken",
")",
"\n",
"req",
",",
"_",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"bytes",
".",
"NewBuffer",
"(",
"payload",
")",
")",
"\n\n",
"if",
"c",
".",
"Token",
"!=",
"nil",
"{",
"c",
".",
"setTokenHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"setHeaders",
"(",
"req",
",",
"n",
")",
"\n\n",
"httpRes",
",",
"err",
":=",
"c",
".",
"requestWithContext",
"(",
"ctx",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"httpRes",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"response",
":=",
"&",
"Response",
"{",
"}",
"\n",
"response",
".",
"StatusCode",
"=",
"httpRes",
".",
"StatusCode",
"\n",
"response",
".",
"ApnsID",
"=",
"httpRes",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n\n",
"decoder",
":=",
"json",
".",
"NewDecoder",
"(",
"httpRes",
".",
"Body",
")",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"response",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"io",
".",
"EOF",
"{",
"return",
"&",
"Response",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"response",
",",
"nil",
"\n",
"}"
] | // PushWithContext sends a Notification to the APNs gateway. Context carries a
// deadline and a cancellation signal and allows you to close long running
// requests when the context timeout is exceeded. Context can be nil, for
// backwards compatibility.
//
// If the underlying http.Client is not currently connected, this method will
// attempt to reconnect transparently before sending the notification. It will
// return a Response indicating whether the notification was accepted or
// rejected by the APNs gateway, or an error if something goes wrong. | [
"PushWithContext",
"sends",
"a",
"Notification",
"to",
"the",
"APNs",
"gateway",
".",
"Context",
"carries",
"a",
"deadline",
"and",
"a",
"cancellation",
"signal",
"and",
"allows",
"you",
"to",
"close",
"long",
"running",
"requests",
"when",
"the",
"context",
"timeout",
"is",
"exceeded",
".",
"Context",
"can",
"be",
"nil",
"for",
"backwards",
"compatibility",
".",
"If",
"the",
"underlying",
"http",
".",
"Client",
"is",
"not",
"currently",
"connected",
"this",
"method",
"will",
"attempt",
"to",
"reconnect",
"transparently",
"before",
"sending",
"the",
"notification",
".",
"It",
"will",
"return",
"a",
"Response",
"indicating",
"whether",
"the",
"notification",
"was",
"accepted",
"or",
"rejected",
"by",
"the",
"APNs",
"gateway",
"or",
"an",
"error",
"if",
"something",
"goes",
"wrong",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/client.go#L150-L180 |
150,307 | sideshow/apns2 | client_manager.go | NewClientManager | func NewClientManager() *ClientManager {
manager := &ClientManager{
MaxSize: 64,
MaxAge: 10 * time.Minute,
Factory: NewClient,
}
manager.initInternals()
return manager
} | go | func NewClientManager() *ClientManager {
manager := &ClientManager{
MaxSize: 64,
MaxAge: 10 * time.Minute,
Factory: NewClient,
}
manager.initInternals()
return manager
} | [
"func",
"NewClientManager",
"(",
")",
"*",
"ClientManager",
"{",
"manager",
":=",
"&",
"ClientManager",
"{",
"MaxSize",
":",
"64",
",",
"MaxAge",
":",
"10",
"*",
"time",
".",
"Minute",
",",
"Factory",
":",
"NewClient",
",",
"}",
"\n\n",
"manager",
".",
"initInternals",
"(",
")",
"\n\n",
"return",
"manager",
"\n",
"}"
] | // NewClientManager returns a new ClientManager for prolonged, concurrent usage
// of multiple APNs clients. ClientManager is flexible enough to work best for
// your use case. When a client is not found in the manager, Get will return
// the result of calling Factory, which can be a Client or nil.
//
// Having multiple clients per certificate in the manager is not allowed.
//
// By default, MaxSize is 64, MaxAge is 10 minutes, and Factory always returns
// a Client with default options. | [
"NewClientManager",
"returns",
"a",
"new",
"ClientManager",
"for",
"prolonged",
"concurrent",
"usage",
"of",
"multiple",
"APNs",
"clients",
".",
"ClientManager",
"is",
"flexible",
"enough",
"to",
"work",
"best",
"for",
"your",
"use",
"case",
".",
"When",
"a",
"client",
"is",
"not",
"found",
"in",
"the",
"manager",
"Get",
"will",
"return",
"the",
"result",
"of",
"calling",
"Factory",
"which",
"can",
"be",
"a",
"Client",
"or",
"nil",
".",
"Having",
"multiple",
"clients",
"per",
"certificate",
"in",
"the",
"manager",
"is",
"not",
"allowed",
".",
"By",
"default",
"MaxSize",
"is",
"64",
"MaxAge",
"is",
"10",
"minutes",
"and",
"Factory",
"always",
"returns",
"a",
"Client",
"with",
"default",
"options",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/client_manager.go#L49-L59 |
150,308 | sideshow/apns2 | client_manager.go | Add | func (m *ClientManager) Add(client *Client) {
m.initInternals()
m.mu.Lock()
defer m.mu.Unlock()
key := cacheKey(client.Certificate)
now := time.Now()
if ele, hit := m.cache[key]; hit {
item := ele.Value.(*managerItem)
item.client = client
item.lastUsed = now
m.ll.MoveToFront(ele)
return
}
ele := m.ll.PushFront(&managerItem{key, client, now})
m.cache[key] = ele
if m.MaxSize != 0 && m.ll.Len() > m.MaxSize {
m.mu.Unlock()
m.removeOldest()
m.mu.Lock()
}
} | go | func (m *ClientManager) Add(client *Client) {
m.initInternals()
m.mu.Lock()
defer m.mu.Unlock()
key := cacheKey(client.Certificate)
now := time.Now()
if ele, hit := m.cache[key]; hit {
item := ele.Value.(*managerItem)
item.client = client
item.lastUsed = now
m.ll.MoveToFront(ele)
return
}
ele := m.ll.PushFront(&managerItem{key, client, now})
m.cache[key] = ele
if m.MaxSize != 0 && m.ll.Len() > m.MaxSize {
m.mu.Unlock()
m.removeOldest()
m.mu.Lock()
}
} | [
"func",
"(",
"m",
"*",
"ClientManager",
")",
"Add",
"(",
"client",
"*",
"Client",
")",
"{",
"m",
".",
"initInternals",
"(",
")",
"\n",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"key",
":=",
"cacheKey",
"(",
"client",
".",
"Certificate",
")",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"if",
"ele",
",",
"hit",
":=",
"m",
".",
"cache",
"[",
"key",
"]",
";",
"hit",
"{",
"item",
":=",
"ele",
".",
"Value",
".",
"(",
"*",
"managerItem",
")",
"\n",
"item",
".",
"client",
"=",
"client",
"\n",
"item",
".",
"lastUsed",
"=",
"now",
"\n",
"m",
".",
"ll",
".",
"MoveToFront",
"(",
"ele",
")",
"\n",
"return",
"\n",
"}",
"\n",
"ele",
":=",
"m",
".",
"ll",
".",
"PushFront",
"(",
"&",
"managerItem",
"{",
"key",
",",
"client",
",",
"now",
"}",
")",
"\n",
"m",
".",
"cache",
"[",
"key",
"]",
"=",
"ele",
"\n",
"if",
"m",
".",
"MaxSize",
"!=",
"0",
"&&",
"m",
".",
"ll",
".",
"Len",
"(",
")",
">",
"m",
".",
"MaxSize",
"{",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"m",
".",
"removeOldest",
"(",
")",
"\n",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Add adds a Client to the manager. You can use this to individually configure
// Clients in the manager. | [
"Add",
"adds",
"a",
"Client",
"to",
"the",
"manager",
".",
"You",
"can",
"use",
"this",
"to",
"individually",
"configure",
"Clients",
"in",
"the",
"manager",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/client_manager.go#L63-L84 |
150,309 | sideshow/apns2 | client_manager.go | Get | func (m *ClientManager) Get(certificate tls.Certificate) *Client {
m.initInternals()
m.mu.Lock()
defer m.mu.Unlock()
key := cacheKey(certificate)
now := time.Now()
if ele, hit := m.cache[key]; hit {
item := ele.Value.(*managerItem)
if m.MaxAge != 0 && item.lastUsed.Before(now.Add(-m.MaxAge)) {
c := m.Factory(certificate)
if c == nil {
return nil
}
item.client = c
}
item.lastUsed = now
m.ll.MoveToFront(ele)
return item.client
}
c := m.Factory(certificate)
if c == nil {
return nil
}
m.mu.Unlock()
m.Add(c)
m.mu.Lock()
return c
} | go | func (m *ClientManager) Get(certificate tls.Certificate) *Client {
m.initInternals()
m.mu.Lock()
defer m.mu.Unlock()
key := cacheKey(certificate)
now := time.Now()
if ele, hit := m.cache[key]; hit {
item := ele.Value.(*managerItem)
if m.MaxAge != 0 && item.lastUsed.Before(now.Add(-m.MaxAge)) {
c := m.Factory(certificate)
if c == nil {
return nil
}
item.client = c
}
item.lastUsed = now
m.ll.MoveToFront(ele)
return item.client
}
c := m.Factory(certificate)
if c == nil {
return nil
}
m.mu.Unlock()
m.Add(c)
m.mu.Lock()
return c
} | [
"func",
"(",
"m",
"*",
"ClientManager",
")",
"Get",
"(",
"certificate",
"tls",
".",
"Certificate",
")",
"*",
"Client",
"{",
"m",
".",
"initInternals",
"(",
")",
"\n",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"key",
":=",
"cacheKey",
"(",
"certificate",
")",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"if",
"ele",
",",
"hit",
":=",
"m",
".",
"cache",
"[",
"key",
"]",
";",
"hit",
"{",
"item",
":=",
"ele",
".",
"Value",
".",
"(",
"*",
"managerItem",
")",
"\n",
"if",
"m",
".",
"MaxAge",
"!=",
"0",
"&&",
"item",
".",
"lastUsed",
".",
"Before",
"(",
"now",
".",
"Add",
"(",
"-",
"m",
".",
"MaxAge",
")",
")",
"{",
"c",
":=",
"m",
".",
"Factory",
"(",
"certificate",
")",
"\n",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"item",
".",
"client",
"=",
"c",
"\n",
"}",
"\n",
"item",
".",
"lastUsed",
"=",
"now",
"\n",
"m",
".",
"ll",
".",
"MoveToFront",
"(",
"ele",
")",
"\n",
"return",
"item",
".",
"client",
"\n",
"}",
"\n\n",
"c",
":=",
"m",
".",
"Factory",
"(",
"certificate",
")",
"\n",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"m",
".",
"Add",
"(",
"c",
")",
"\n",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // Get gets a Client from the manager. If a Client is not found in the manager
// or if a Client has remained in the manager longer than MaxAge, Get will call
// the ClientManager's Factory function, store the result in the manager if
// non-nil, and return it. | [
"Get",
"gets",
"a",
"Client",
"from",
"the",
"manager",
".",
"If",
"a",
"Client",
"is",
"not",
"found",
"in",
"the",
"manager",
"or",
"if",
"a",
"Client",
"has",
"remained",
"in",
"the",
"manager",
"longer",
"than",
"MaxAge",
"Get",
"will",
"call",
"the",
"ClientManager",
"s",
"Factory",
"function",
"store",
"the",
"result",
"in",
"the",
"manager",
"if",
"non",
"-",
"nil",
"and",
"return",
"it",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/client_manager.go#L90-L119 |
150,310 | sideshow/apns2 | client_manager.go | Len | func (m *ClientManager) Len() int {
if m.cache == nil {
return 0
}
m.mu.Lock()
defer m.mu.Unlock()
return m.ll.Len()
} | go | func (m *ClientManager) Len() int {
if m.cache == nil {
return 0
}
m.mu.Lock()
defer m.mu.Unlock()
return m.ll.Len()
} | [
"func",
"(",
"m",
"*",
"ClientManager",
")",
"Len",
"(",
")",
"int",
"{",
"if",
"m",
".",
"cache",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"ll",
".",
"Len",
"(",
")",
"\n",
"}"
] | // Len returns the current size of the ClientManager. | [
"Len",
"returns",
"the",
"current",
"size",
"of",
"the",
"ClientManager",
"."
] | d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2 | https://github.com/sideshow/apns2/blob/d5157a5e6ef01fe1b953450a7a8a1bbe77e865c2/client_manager.go#L122-L129 |
150,311 | google/zoekt | gitindex/submodule.go | ParseGitModules | func ParseGitModules(content []byte) (map[string]*SubmoduleEntry, error) {
dec := config.NewDecoder(bytes.NewBuffer(content))
cfg := &config.Config{}
if err := dec.Decode(cfg); err != nil {
return nil, err
}
result := map[string]*SubmoduleEntry{}
for _, s := range cfg.Sections {
if s.Name != "submodule" {
continue
}
for _, ss := range s.Subsections {
name := ss.Name
e := &SubmoduleEntry{}
for _, o := range ss.Options {
switch o.Key {
case "branch":
e.Branch = o.Value
case "path":
e.Path = o.Value
case "url":
e.URL = o.Value
}
}
result[name] = e
}
}
return result, nil
} | go | func ParseGitModules(content []byte) (map[string]*SubmoduleEntry, error) {
dec := config.NewDecoder(bytes.NewBuffer(content))
cfg := &config.Config{}
if err := dec.Decode(cfg); err != nil {
return nil, err
}
result := map[string]*SubmoduleEntry{}
for _, s := range cfg.Sections {
if s.Name != "submodule" {
continue
}
for _, ss := range s.Subsections {
name := ss.Name
e := &SubmoduleEntry{}
for _, o := range ss.Options {
switch o.Key {
case "branch":
e.Branch = o.Value
case "path":
e.Path = o.Value
case "url":
e.URL = o.Value
}
}
result[name] = e
}
}
return result, nil
} | [
"func",
"ParseGitModules",
"(",
"content",
"[",
"]",
"byte",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"SubmoduleEntry",
",",
"error",
")",
"{",
"dec",
":=",
"config",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewBuffer",
"(",
"content",
")",
")",
"\n",
"cfg",
":=",
"&",
"config",
".",
"Config",
"{",
"}",
"\n\n",
"if",
"err",
":=",
"dec",
".",
"Decode",
"(",
"cfg",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"result",
":=",
"map",
"[",
"string",
"]",
"*",
"SubmoduleEntry",
"{",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"cfg",
".",
"Sections",
"{",
"if",
"s",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"ss",
":=",
"range",
"s",
".",
"Subsections",
"{",
"name",
":=",
"ss",
".",
"Name",
"\n",
"e",
":=",
"&",
"SubmoduleEntry",
"{",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"ss",
".",
"Options",
"{",
"switch",
"o",
".",
"Key",
"{",
"case",
"\"",
"\"",
":",
"e",
".",
"Branch",
"=",
"o",
".",
"Value",
"\n",
"case",
"\"",
"\"",
":",
"e",
".",
"Path",
"=",
"o",
".",
"Value",
"\n",
"case",
"\"",
"\"",
":",
"e",
".",
"URL",
"=",
"o",
".",
"Value",
"\n",
"}",
"\n",
"}",
"\n\n",
"result",
"[",
"name",
"]",
"=",
"e",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // ParseGitModules parses the contents of a .gitmodules file. | [
"ParseGitModules",
"parses",
"the",
"contents",
"of",
"a",
".",
"gitmodules",
"file",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/submodule.go#L31-L64 |
150,312 | google/zoekt | bits.go | caseFoldingEqualsRunes | func caseFoldingEqualsRunes(lower, mixed []byte) (int, bool) {
matchTotal := 0
for len(lower) > 0 && len(mixed) > 0 {
lr, lsz := utf8.DecodeRune(lower)
lower = lower[lsz:]
mr, msz := utf8.DecodeRune(mixed)
mixed = mixed[msz:]
matchTotal += msz
if lr != unicode.ToLower(mr) {
return 0, false
}
}
return matchTotal, len(lower) == 0
} | go | func caseFoldingEqualsRunes(lower, mixed []byte) (int, bool) {
matchTotal := 0
for len(lower) > 0 && len(mixed) > 0 {
lr, lsz := utf8.DecodeRune(lower)
lower = lower[lsz:]
mr, msz := utf8.DecodeRune(mixed)
mixed = mixed[msz:]
matchTotal += msz
if lr != unicode.ToLower(mr) {
return 0, false
}
}
return matchTotal, len(lower) == 0
} | [
"func",
"caseFoldingEqualsRunes",
"(",
"lower",
",",
"mixed",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"bool",
")",
"{",
"matchTotal",
":=",
"0",
"\n",
"for",
"len",
"(",
"lower",
")",
">",
"0",
"&&",
"len",
"(",
"mixed",
")",
">",
"0",
"{",
"lr",
",",
"lsz",
":=",
"utf8",
".",
"DecodeRune",
"(",
"lower",
")",
"\n",
"lower",
"=",
"lower",
"[",
"lsz",
":",
"]",
"\n\n",
"mr",
",",
"msz",
":=",
"utf8",
".",
"DecodeRune",
"(",
"mixed",
")",
"\n",
"mixed",
"=",
"mixed",
"[",
"msz",
":",
"]",
"\n",
"matchTotal",
"+=",
"msz",
"\n\n",
"if",
"lr",
"!=",
"unicode",
".",
"ToLower",
"(",
"mr",
")",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"matchTotal",
",",
"len",
"(",
"lower",
")",
"==",
"0",
"\n",
"}"
] | // compare 'lower' and 'mixed', where lower is the needle. 'mixed' may
// be larger than 'lower'. Returns whether there was a match, and if
// yes, the byte size of the match. | [
"compare",
"lower",
"and",
"mixed",
"where",
"lower",
"is",
"the",
"needle",
".",
"mixed",
"may",
"be",
"larger",
"than",
"lower",
".",
"Returns",
"whether",
"there",
"was",
"a",
"match",
"and",
"if",
"yes",
"the",
"byte",
"size",
"of",
"the",
"match",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/bits.go#L59-L75 |
150,313 | google/zoekt | query/parse.go | parseStringLiteral | func parseStringLiteral(in []byte) (lit []byte, n int, err error) {
left := in[1:]
found := false
loop:
for len(left) > 0 {
c := left[0]
left = left[1:]
switch c {
case '"':
found = true
break loop
case '\\':
// TODO - other escape sequences.
if len(left) == 0 {
return nil, 0, fmt.Errorf("query: missing char after \\")
}
c = left[0]
left = left[1:]
lit = append(lit, c)
default:
lit = append(lit, c)
}
}
if !found {
return nil, 0, fmt.Errorf("query: unterminated quoted string")
}
return lit, len(in) - len(left), nil
} | go | func parseStringLiteral(in []byte) (lit []byte, n int, err error) {
left := in[1:]
found := false
loop:
for len(left) > 0 {
c := left[0]
left = left[1:]
switch c {
case '"':
found = true
break loop
case '\\':
// TODO - other escape sequences.
if len(left) == 0 {
return nil, 0, fmt.Errorf("query: missing char after \\")
}
c = left[0]
left = left[1:]
lit = append(lit, c)
default:
lit = append(lit, c)
}
}
if !found {
return nil, 0, fmt.Errorf("query: unterminated quoted string")
}
return lit, len(in) - len(left), nil
} | [
"func",
"parseStringLiteral",
"(",
"in",
"[",
"]",
"byte",
")",
"(",
"lit",
"[",
"]",
"byte",
",",
"n",
"int",
",",
"err",
"error",
")",
"{",
"left",
":=",
"in",
"[",
"1",
":",
"]",
"\n",
"found",
":=",
"false",
"\n\n",
"loop",
":",
"for",
"len",
"(",
"left",
")",
">",
"0",
"{",
"c",
":=",
"left",
"[",
"0",
"]",
"\n",
"left",
"=",
"left",
"[",
"1",
":",
"]",
"\n",
"switch",
"c",
"{",
"case",
"'\"'",
":",
"found",
"=",
"true",
"\n",
"break",
"loop",
"\n",
"case",
"'\\\\'",
":",
"// TODO - other escape sequences.",
"if",
"len",
"(",
"left",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\\",
"\"",
")",
"\n",
"}",
"\n",
"c",
"=",
"left",
"[",
"0",
"]",
"\n",
"left",
"=",
"left",
"[",
"1",
":",
"]",
"\n\n",
"lit",
"=",
"append",
"(",
"lit",
",",
"c",
")",
"\n",
"default",
":",
"lit",
"=",
"append",
"(",
"lit",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"lit",
",",
"len",
"(",
"in",
")",
"-",
"len",
"(",
"left",
")",
",",
"nil",
"\n",
"}"
] | // parseStringLiteral parses a string literal, consumes the starting
// quote too. | [
"parseStringLiteral",
"parses",
"a",
"string",
"literal",
"consumes",
"the",
"starting",
"quote",
"too",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/parse.go#L37-L66 |
150,314 | google/zoekt | query/parse.go | Parse | func Parse(qStr string) (Q, error) {
b := []byte(qStr)
qs, _, err := parseExprList(b)
if err != nil {
return nil, err
}
q, err := parseOperators(qs)
if err != nil {
return nil, err
}
return Simplify(q), nil
} | go | func Parse(qStr string) (Q, error) {
b := []byte(qStr)
qs, _, err := parseExprList(b)
if err != nil {
return nil, err
}
q, err := parseOperators(qs)
if err != nil {
return nil, err
}
return Simplify(q), nil
} | [
"func",
"Parse",
"(",
"qStr",
"string",
")",
"(",
"Q",
",",
"error",
")",
"{",
"b",
":=",
"[",
"]",
"byte",
"(",
"qStr",
")",
"\n\n",
"qs",
",",
"_",
",",
"err",
":=",
"parseExprList",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"q",
",",
"err",
":=",
"parseOperators",
"(",
"qs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"Simplify",
"(",
"q",
")",
",",
"nil",
"\n",
"}"
] | // Parse parses a string into a query. | [
"Parse",
"parses",
"a",
"string",
"into",
"a",
"query",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/parse.go#L81-L95 |
150,315 | google/zoekt | query/parse.go | regexpQuery | func regexpQuery(text string, content, file bool) (Q, error) {
var expr Q
r, err := syntax.Parse(text, syntax.ClassNL|syntax.PerlX|syntax.UnicodeGroups)
if err != nil {
return nil, err
}
if r.Op == syntax.OpLiteral {
expr = &Substring{
Pattern: string(r.Rune),
FileName: file,
Content: content,
}
} else {
expr = &Regexp{
Regexp: r,
FileName: file,
Content: content,
}
}
return expr, nil
} | go | func regexpQuery(text string, content, file bool) (Q, error) {
var expr Q
r, err := syntax.Parse(text, syntax.ClassNL|syntax.PerlX|syntax.UnicodeGroups)
if err != nil {
return nil, err
}
if r.Op == syntax.OpLiteral {
expr = &Substring{
Pattern: string(r.Rune),
FileName: file,
Content: content,
}
} else {
expr = &Regexp{
Regexp: r,
FileName: file,
Content: content,
}
}
return expr, nil
} | [
"func",
"regexpQuery",
"(",
"text",
"string",
",",
"content",
",",
"file",
"bool",
")",
"(",
"Q",
",",
"error",
")",
"{",
"var",
"expr",
"Q",
"\n\n",
"r",
",",
"err",
":=",
"syntax",
".",
"Parse",
"(",
"text",
",",
"syntax",
".",
"ClassNL",
"|",
"syntax",
".",
"PerlX",
"|",
"syntax",
".",
"UnicodeGroups",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Op",
"==",
"syntax",
".",
"OpLiteral",
"{",
"expr",
"=",
"&",
"Substring",
"{",
"Pattern",
":",
"string",
"(",
"r",
".",
"Rune",
")",
",",
"FileName",
":",
"file",
",",
"Content",
":",
"content",
",",
"}",
"\n",
"}",
"else",
"{",
"expr",
"=",
"&",
"Regexp",
"{",
"Regexp",
":",
"r",
",",
"FileName",
":",
"file",
",",
"Content",
":",
"content",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"expr",
",",
"nil",
"\n",
"}"
] | // regexpQuery parses an atom into either a regular expression, or a
// simple substring atom. | [
"regexpQuery",
"parses",
"an",
"atom",
"into",
"either",
"a",
"regular",
"expression",
"or",
"a",
"simple",
"substring",
"atom",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/parse.go#L197-L220 |
150,316 | google/zoekt | query/parse.go | parseOperators | func parseOperators(in []Q) (Q, error) {
top := &Or{}
cur := &And{}
seenOr := false
for _, q := range in {
if _, ok := q.(*orOperator); ok {
seenOr = true
if len(cur.Children) == 0 {
return nil, fmt.Errorf("query: OR operator should have operand")
}
top.Children = append(top.Children, cur)
cur = &And{}
} else {
cur.Children = append(cur.Children, q)
}
}
if seenOr && len(cur.Children) == 0 {
return nil, fmt.Errorf("query: OR operator should have operand")
}
top.Children = append(top.Children, cur)
return top, nil
} | go | func parseOperators(in []Q) (Q, error) {
top := &Or{}
cur := &And{}
seenOr := false
for _, q := range in {
if _, ok := q.(*orOperator); ok {
seenOr = true
if len(cur.Children) == 0 {
return nil, fmt.Errorf("query: OR operator should have operand")
}
top.Children = append(top.Children, cur)
cur = &And{}
} else {
cur.Children = append(cur.Children, q)
}
}
if seenOr && len(cur.Children) == 0 {
return nil, fmt.Errorf("query: OR operator should have operand")
}
top.Children = append(top.Children, cur)
return top, nil
} | [
"func",
"parseOperators",
"(",
"in",
"[",
"]",
"Q",
")",
"(",
"Q",
",",
"error",
")",
"{",
"top",
":=",
"&",
"Or",
"{",
"}",
"\n",
"cur",
":=",
"&",
"And",
"{",
"}",
"\n\n",
"seenOr",
":=",
"false",
"\n",
"for",
"_",
",",
"q",
":=",
"range",
"in",
"{",
"if",
"_",
",",
"ok",
":=",
"q",
".",
"(",
"*",
"orOperator",
")",
";",
"ok",
"{",
"seenOr",
"=",
"true",
"\n",
"if",
"len",
"(",
"cur",
".",
"Children",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"top",
".",
"Children",
"=",
"append",
"(",
"top",
".",
"Children",
",",
"cur",
")",
"\n",
"cur",
"=",
"&",
"And",
"{",
"}",
"\n",
"}",
"else",
"{",
"cur",
".",
"Children",
"=",
"append",
"(",
"cur",
".",
"Children",
",",
"q",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"seenOr",
"&&",
"len",
"(",
"cur",
".",
"Children",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"top",
".",
"Children",
"=",
"append",
"(",
"top",
".",
"Children",
",",
"cur",
")",
"\n",
"return",
"top",
",",
"nil",
"\n",
"}"
] | // parseOperators interprets the orOperator in a list of queries. | [
"parseOperators",
"interprets",
"the",
"orOperator",
"in",
"a",
"list",
"of",
"queries",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/parse.go#L223-L246 |
150,317 | google/zoekt | query/parse.go | parseExprList | func parseExprList(in []byte) ([]Q, int, error) {
b := in[:]
var qs []Q
for len(b) > 0 {
for len(b) > 0 && isSpace(b[0]) {
b = b[1:]
}
tok, _ := nextToken(b)
if tok != nil && tok.Type == tokParenClose {
break
} else if tok != nil && tok.Type == tokOr {
qs = append(qs, &orOperator{})
b = b[len(tok.Input):]
continue
}
q, n, err := parseExpr(b)
if err != nil {
return nil, 0, err
}
if q == nil {
// eof or a ')'
break
}
qs = append(qs, q)
b = b[n:]
}
setCase := "auto"
newQS := qs[:0]
for _, q := range qs {
if sc, ok := q.(*caseQ); ok {
setCase = sc.Flavor
} else {
newQS = append(newQS, q)
}
}
qs = mapQueryList(newQS, func(q Q) Q {
if sc, ok := q.(setCaser); ok {
sc.setCase(setCase)
}
return q
})
return qs, len(in) - len(b), nil
} | go | func parseExprList(in []byte) ([]Q, int, error) {
b := in[:]
var qs []Q
for len(b) > 0 {
for len(b) > 0 && isSpace(b[0]) {
b = b[1:]
}
tok, _ := nextToken(b)
if tok != nil && tok.Type == tokParenClose {
break
} else if tok != nil && tok.Type == tokOr {
qs = append(qs, &orOperator{})
b = b[len(tok.Input):]
continue
}
q, n, err := parseExpr(b)
if err != nil {
return nil, 0, err
}
if q == nil {
// eof or a ')'
break
}
qs = append(qs, q)
b = b[n:]
}
setCase := "auto"
newQS := qs[:0]
for _, q := range qs {
if sc, ok := q.(*caseQ); ok {
setCase = sc.Flavor
} else {
newQS = append(newQS, q)
}
}
qs = mapQueryList(newQS, func(q Q) Q {
if sc, ok := q.(setCaser); ok {
sc.setCase(setCase)
}
return q
})
return qs, len(in) - len(b), nil
} | [
"func",
"parseExprList",
"(",
"in",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"Q",
",",
"int",
",",
"error",
")",
"{",
"b",
":=",
"in",
"[",
":",
"]",
"\n",
"var",
"qs",
"[",
"]",
"Q",
"\n",
"for",
"len",
"(",
"b",
")",
">",
"0",
"{",
"for",
"len",
"(",
"b",
")",
">",
"0",
"&&",
"isSpace",
"(",
"b",
"[",
"0",
"]",
")",
"{",
"b",
"=",
"b",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"tok",
",",
"_",
":=",
"nextToken",
"(",
"b",
")",
"\n",
"if",
"tok",
"!=",
"nil",
"&&",
"tok",
".",
"Type",
"==",
"tokParenClose",
"{",
"break",
"\n",
"}",
"else",
"if",
"tok",
"!=",
"nil",
"&&",
"tok",
".",
"Type",
"==",
"tokOr",
"{",
"qs",
"=",
"append",
"(",
"qs",
",",
"&",
"orOperator",
"{",
"}",
")",
"\n",
"b",
"=",
"b",
"[",
"len",
"(",
"tok",
".",
"Input",
")",
":",
"]",
"\n",
"continue",
"\n",
"}",
"\n\n",
"q",
",",
"n",
",",
"err",
":=",
"parseExpr",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"q",
"==",
"nil",
"{",
"// eof or a ')'",
"break",
"\n",
"}",
"\n",
"qs",
"=",
"append",
"(",
"qs",
",",
"q",
")",
"\n",
"b",
"=",
"b",
"[",
"n",
":",
"]",
"\n",
"}",
"\n\n",
"setCase",
":=",
"\"",
"\"",
"\n",
"newQS",
":=",
"qs",
"[",
":",
"0",
"]",
"\n",
"for",
"_",
",",
"q",
":=",
"range",
"qs",
"{",
"if",
"sc",
",",
"ok",
":=",
"q",
".",
"(",
"*",
"caseQ",
")",
";",
"ok",
"{",
"setCase",
"=",
"sc",
".",
"Flavor",
"\n",
"}",
"else",
"{",
"newQS",
"=",
"append",
"(",
"newQS",
",",
"q",
")",
"\n",
"}",
"\n",
"}",
"\n",
"qs",
"=",
"mapQueryList",
"(",
"newQS",
",",
"func",
"(",
"q",
"Q",
")",
"Q",
"{",
"if",
"sc",
",",
"ok",
":=",
"q",
".",
"(",
"setCaser",
")",
";",
"ok",
"{",
"sc",
".",
"setCase",
"(",
"setCase",
")",
"\n",
"}",
"\n",
"return",
"q",
"\n",
"}",
")",
"\n",
"return",
"qs",
",",
"len",
"(",
"in",
")",
"-",
"len",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
] | // parseExprList parses a list of query expressions. It is the
// workhorse of the Parse function. | [
"parseExprList",
"parses",
"a",
"list",
"of",
"query",
"expressions",
".",
"It",
"is",
"the",
"workhorse",
"of",
"the",
"Parse",
"function",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/parse.go#L250-L295 |
150,318 | google/zoekt | query/parse.go | nextToken | func nextToken(in []byte) (*token, error) {
left := in[:]
parenCount := 0
var cur token
if len(left) == 0 {
return nil, nil
}
if left[0] == '-' {
return &token{
Type: tokNegate,
Text: []byte{'-'},
Input: in[:1],
}, nil
}
foundSpace := false
loop:
for len(left) > 0 {
c := left[0]
switch c {
case '(':
parenCount++
cur.Text = append(cur.Text, c)
left = left[1:]
case ')':
if parenCount == 0 {
if len(cur.Text) == 0 {
cur.Text = []byte{')'}
left = left[1:]
}
break loop
}
cur.Text = append(cur.Text, c)
left = left[1:]
parenCount--
case '"':
t, n, err := parseStringLiteral(left)
if err != nil {
return nil, err
}
cur.Text = append(cur.Text, t...)
left = left[n:]
case '\\':
left = left[1:]
if len(left) == 0 {
return nil, fmt.Errorf("query: lone \\ at end")
}
c := left[0]
cur.Text = append(cur.Text, '\\', c)
left = left[1:]
case ' ', '\n', '\t':
if parenCount > 0 {
foundSpace = true
}
break loop
default:
cur.Text = append(cur.Text, c)
left = left[1:]
}
}
if len(cur.Text) == 0 {
return nil, nil
}
if foundSpace && cur.Text[0] == '(' {
cur.Text = cur.Text[:1]
cur.Input = in[:1]
} else {
cur.Input = in[:len(in)-len(left)]
}
cur.setType()
return &cur, nil
} | go | func nextToken(in []byte) (*token, error) {
left := in[:]
parenCount := 0
var cur token
if len(left) == 0 {
return nil, nil
}
if left[0] == '-' {
return &token{
Type: tokNegate,
Text: []byte{'-'},
Input: in[:1],
}, nil
}
foundSpace := false
loop:
for len(left) > 0 {
c := left[0]
switch c {
case '(':
parenCount++
cur.Text = append(cur.Text, c)
left = left[1:]
case ')':
if parenCount == 0 {
if len(cur.Text) == 0 {
cur.Text = []byte{')'}
left = left[1:]
}
break loop
}
cur.Text = append(cur.Text, c)
left = left[1:]
parenCount--
case '"':
t, n, err := parseStringLiteral(left)
if err != nil {
return nil, err
}
cur.Text = append(cur.Text, t...)
left = left[n:]
case '\\':
left = left[1:]
if len(left) == 0 {
return nil, fmt.Errorf("query: lone \\ at end")
}
c := left[0]
cur.Text = append(cur.Text, '\\', c)
left = left[1:]
case ' ', '\n', '\t':
if parenCount > 0 {
foundSpace = true
}
break loop
default:
cur.Text = append(cur.Text, c)
left = left[1:]
}
}
if len(cur.Text) == 0 {
return nil, nil
}
if foundSpace && cur.Text[0] == '(' {
cur.Text = cur.Text[:1]
cur.Input = in[:1]
} else {
cur.Input = in[:len(in)-len(left)]
}
cur.setType()
return &cur, nil
} | [
"func",
"nextToken",
"(",
"in",
"[",
"]",
"byte",
")",
"(",
"*",
"token",
",",
"error",
")",
"{",
"left",
":=",
"in",
"[",
":",
"]",
"\n",
"parenCount",
":=",
"0",
"\n",
"var",
"cur",
"token",
"\n",
"if",
"len",
"(",
"left",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"left",
"[",
"0",
"]",
"==",
"'-'",
"{",
"return",
"&",
"token",
"{",
"Type",
":",
"tokNegate",
",",
"Text",
":",
"[",
"]",
"byte",
"{",
"'-'",
"}",
",",
"Input",
":",
"in",
"[",
":",
"1",
"]",
",",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"foundSpace",
":=",
"false",
"\n\n",
"loop",
":",
"for",
"len",
"(",
"left",
")",
">",
"0",
"{",
"c",
":=",
"left",
"[",
"0",
"]",
"\n",
"switch",
"c",
"{",
"case",
"'('",
":",
"parenCount",
"++",
"\n",
"cur",
".",
"Text",
"=",
"append",
"(",
"cur",
".",
"Text",
",",
"c",
")",
"\n",
"left",
"=",
"left",
"[",
"1",
":",
"]",
"\n",
"case",
"')'",
":",
"if",
"parenCount",
"==",
"0",
"{",
"if",
"len",
"(",
"cur",
".",
"Text",
")",
"==",
"0",
"{",
"cur",
".",
"Text",
"=",
"[",
"]",
"byte",
"{",
"')'",
"}",
"\n",
"left",
"=",
"left",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"break",
"loop",
"\n",
"}",
"\n\n",
"cur",
".",
"Text",
"=",
"append",
"(",
"cur",
".",
"Text",
",",
"c",
")",
"\n",
"left",
"=",
"left",
"[",
"1",
":",
"]",
"\n",
"parenCount",
"--",
"\n\n",
"case",
"'\"'",
":",
"t",
",",
"n",
",",
"err",
":=",
"parseStringLiteral",
"(",
"left",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cur",
".",
"Text",
"=",
"append",
"(",
"cur",
".",
"Text",
",",
"t",
"...",
")",
"\n",
"left",
"=",
"left",
"[",
"n",
":",
"]",
"\n",
"case",
"'\\\\'",
":",
"left",
"=",
"left",
"[",
"1",
":",
"]",
"\n",
"if",
"len",
"(",
"left",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\\",
"\"",
")",
"\n",
"}",
"\n",
"c",
":=",
"left",
"[",
"0",
"]",
"\n",
"cur",
".",
"Text",
"=",
"append",
"(",
"cur",
".",
"Text",
",",
"'\\\\'",
",",
"c",
")",
"\n",
"left",
"=",
"left",
"[",
"1",
":",
"]",
"\n\n",
"case",
"' '",
",",
"'\\n'",
",",
"'\\t'",
":",
"if",
"parenCount",
">",
"0",
"{",
"foundSpace",
"=",
"true",
"\n",
"}",
"\n",
"break",
"loop",
"\n",
"default",
":",
"cur",
".",
"Text",
"=",
"append",
"(",
"cur",
".",
"Text",
",",
"c",
")",
"\n",
"left",
"=",
"left",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"cur",
".",
"Text",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"foundSpace",
"&&",
"cur",
".",
"Text",
"[",
"0",
"]",
"==",
"'('",
"{",
"cur",
".",
"Text",
"=",
"cur",
".",
"Text",
"[",
":",
"1",
"]",
"\n",
"cur",
".",
"Input",
"=",
"in",
"[",
":",
"1",
"]",
"\n",
"}",
"else",
"{",
"cur",
".",
"Input",
"=",
"in",
"[",
":",
"len",
"(",
"in",
")",
"-",
"len",
"(",
"left",
")",
"]",
"\n",
"}",
"\n",
"cur",
".",
"setType",
"(",
")",
"\n",
"return",
"&",
"cur",
",",
"nil",
"\n",
"}"
] | // nextToken returns the next token from the given input. | [
"nextToken",
"returns",
"the",
"next",
"token",
"from",
"the",
"given",
"input",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/parse.go#L393-L471 |
150,319 | google/zoekt | gitindex/repocache.go | NewRepoCache | func NewRepoCache(dir string) *RepoCache {
return &RepoCache{
baseDir: dir,
repos: make(map[string]*git.Repository),
}
} | go | func NewRepoCache(dir string) *RepoCache {
return &RepoCache{
baseDir: dir,
repos: make(map[string]*git.Repository),
}
} | [
"func",
"NewRepoCache",
"(",
"dir",
"string",
")",
"*",
"RepoCache",
"{",
"return",
"&",
"RepoCache",
"{",
"baseDir",
":",
"dir",
",",
"repos",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"git",
".",
"Repository",
")",
",",
"}",
"\n",
"}"
] | // NewRepoCache creates a new RepoCache rooted at the given directory. | [
"NewRepoCache",
"creates",
"a",
"new",
"RepoCache",
"rooted",
"at",
"the",
"given",
"directory",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/repocache.go#L37-L42 |
150,320 | google/zoekt | gitindex/repocache.go | Path | func Path(baseDir string, name string) string {
key := repoKeyStr(name)
return filepath.Join(baseDir, key)
} | go | func Path(baseDir string, name string) string {
key := repoKeyStr(name)
return filepath.Join(baseDir, key)
} | [
"func",
"Path",
"(",
"baseDir",
"string",
",",
"name",
"string",
")",
"string",
"{",
"key",
":=",
"repoKeyStr",
"(",
"name",
")",
"\n",
"return",
"filepath",
".",
"Join",
"(",
"baseDir",
",",
"key",
")",
"\n",
"}"
] | // Path returns the absolute path of the bare repository. | [
"Path",
"returns",
"the",
"absolute",
"path",
"of",
"the",
"bare",
"repository",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/repocache.go#L56-L59 |
150,321 | google/zoekt | gitindex/repocache.go | Open | func (rc *RepoCache) Open(u *url.URL) (*git.Repository, error) {
dir := rc.Path(u)
rc.reposMu.Lock()
defer rc.reposMu.Unlock()
key := repoKey(u)
r := rc.repos[key]
if r != nil {
return r, nil
}
repo, err := git.PlainOpen(dir)
if err == nil {
rc.repos[key] = repo
}
return repo, err
} | go | func (rc *RepoCache) Open(u *url.URL) (*git.Repository, error) {
dir := rc.Path(u)
rc.reposMu.Lock()
defer rc.reposMu.Unlock()
key := repoKey(u)
r := rc.repos[key]
if r != nil {
return r, nil
}
repo, err := git.PlainOpen(dir)
if err == nil {
rc.repos[key] = repo
}
return repo, err
} | [
"func",
"(",
"rc",
"*",
"RepoCache",
")",
"Open",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"*",
"git",
".",
"Repository",
",",
"error",
")",
"{",
"dir",
":=",
"rc",
".",
"Path",
"(",
"u",
")",
"\n",
"rc",
".",
"reposMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"rc",
".",
"reposMu",
".",
"Unlock",
"(",
")",
"\n\n",
"key",
":=",
"repoKey",
"(",
"u",
")",
"\n",
"r",
":=",
"rc",
".",
"repos",
"[",
"key",
"]",
"\n",
"if",
"r",
"!=",
"nil",
"{",
"return",
"r",
",",
"nil",
"\n",
"}",
"\n\n",
"repo",
",",
"err",
":=",
"git",
".",
"PlainOpen",
"(",
"dir",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"rc",
".",
"repos",
"[",
"key",
"]",
"=",
"repo",
"\n",
"}",
"\n",
"return",
"repo",
",",
"err",
"\n",
"}"
] | // Open opens a git repository. The cache retains a pointer to the
// repository. | [
"Open",
"opens",
"a",
"git",
"repository",
".",
"The",
"cache",
"retains",
"a",
"pointer",
"to",
"the",
"repository",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/repocache.go#L68-L84 |
150,322 | google/zoekt | gitindex/repocache.go | ListRepos | func ListRepos(baseDir string, u *url.URL) ([]string, error) {
key := filepath.Join(u.Host, u.Path)
var paths []string
walk := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
return nil
}
if strings.HasSuffix(path, ".git") && !strings.HasSuffix(path, "/.git") {
_, err := git.PlainOpen(path)
if err == nil {
p, err := filepath.Rel(baseDir, path)
if err == nil {
paths = append(paths, p)
}
}
return filepath.SkipDir
}
return nil
}
if err := filepath.Walk(filepath.Join(baseDir, key), walk); err != nil {
return nil, err
}
return paths, nil
} | go | func ListRepos(baseDir string, u *url.URL) ([]string, error) {
key := filepath.Join(u.Host, u.Path)
var paths []string
walk := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
return nil
}
if strings.HasSuffix(path, ".git") && !strings.HasSuffix(path, "/.git") {
_, err := git.PlainOpen(path)
if err == nil {
p, err := filepath.Rel(baseDir, path)
if err == nil {
paths = append(paths, p)
}
}
return filepath.SkipDir
}
return nil
}
if err := filepath.Walk(filepath.Join(baseDir, key), walk); err != nil {
return nil, err
}
return paths, nil
} | [
"func",
"ListRepos",
"(",
"baseDir",
"string",
",",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"key",
":=",
"filepath",
".",
"Join",
"(",
"u",
".",
"Host",
",",
"u",
".",
"Path",
")",
"\n\n",
"var",
"paths",
"[",
"]",
"string",
"\n",
"walk",
":=",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"info",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"path",
",",
"\"",
"\"",
")",
"&&",
"!",
"strings",
".",
"HasSuffix",
"(",
"path",
",",
"\"",
"\"",
")",
"{",
"_",
",",
"err",
":=",
"git",
".",
"PlainOpen",
"(",
"path",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"p",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"baseDir",
",",
"path",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"paths",
"=",
"append",
"(",
"paths",
",",
"p",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"filepath",
".",
"SkipDir",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"filepath",
".",
"Join",
"(",
"baseDir",
",",
"key",
")",
",",
"walk",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"paths",
",",
"nil",
"\n",
"}"
] | // ListRepos returns paths to repos on disk that start with the given
// URL prefix. The paths are relative to baseDir, and typically
// include a ".git" suffix. | [
"ListRepos",
"returns",
"paths",
"to",
"repos",
"on",
"disk",
"that",
"start",
"with",
"the",
"given",
"URL",
"prefix",
".",
"The",
"paths",
"are",
"relative",
"to",
"baseDir",
"and",
"typically",
"include",
"a",
".",
"git",
"suffix",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/repocache.go#L89-L117 |
150,323 | google/zoekt | cmd/zoekt-mirror-gitiles/cgit.go | getCGitRepos | func getCGitRepos(u *url.URL, filter func(string) bool) (map[string]*crawlTarget, error) {
c, err := normalizedGet(u)
if err != nil {
return nil, err
}
pages := map[string]*crawlTarget{}
for _, m := range cgitRepoEntryRE.FindAllSubmatch(c, -1) {
nm := strings.TrimSuffix(string(m[1]), ".git")
if !filter(nm) {
continue
}
relUrl := string(m[2])
u, err := u.Parse(relUrl)
if err != nil {
log.Printf("ignoring u.Parse(%q): %v", relUrl, err)
continue
}
pages[nm] = &crawlTarget{
webURL: u.String(),
webURLType: "cgit",
}
}
// TODO - parallel?
for _, target := range pages {
u, _ := url.Parse(target.webURL)
c, err := cgitCloneURL(u)
if err != nil {
log.Printf("ignoring cgitCloneURL(%s): %v", u, c)
continue
}
target.cloneURL = c.String()
}
return pages, nil
} | go | func getCGitRepos(u *url.URL, filter func(string) bool) (map[string]*crawlTarget, error) {
c, err := normalizedGet(u)
if err != nil {
return nil, err
}
pages := map[string]*crawlTarget{}
for _, m := range cgitRepoEntryRE.FindAllSubmatch(c, -1) {
nm := strings.TrimSuffix(string(m[1]), ".git")
if !filter(nm) {
continue
}
relUrl := string(m[2])
u, err := u.Parse(relUrl)
if err != nil {
log.Printf("ignoring u.Parse(%q): %v", relUrl, err)
continue
}
pages[nm] = &crawlTarget{
webURL: u.String(),
webURLType: "cgit",
}
}
// TODO - parallel?
for _, target := range pages {
u, _ := url.Parse(target.webURL)
c, err := cgitCloneURL(u)
if err != nil {
log.Printf("ignoring cgitCloneURL(%s): %v", u, c)
continue
}
target.cloneURL = c.String()
}
return pages, nil
} | [
"func",
"getCGitRepos",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"filter",
"func",
"(",
"string",
")",
"bool",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"crawlTarget",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"normalizedGet",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"pages",
":=",
"map",
"[",
"string",
"]",
"*",
"crawlTarget",
"{",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"cgitRepoEntryRE",
".",
"FindAllSubmatch",
"(",
"c",
",",
"-",
"1",
")",
"{",
"nm",
":=",
"strings",
".",
"TrimSuffix",
"(",
"string",
"(",
"m",
"[",
"1",
"]",
")",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"!",
"filter",
"(",
"nm",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"relUrl",
":=",
"string",
"(",
"m",
"[",
"2",
"]",
")",
"\n\n",
"u",
",",
"err",
":=",
"u",
".",
"Parse",
"(",
"relUrl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"relUrl",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"pages",
"[",
"nm",
"]",
"=",
"&",
"crawlTarget",
"{",
"webURL",
":",
"u",
".",
"String",
"(",
")",
",",
"webURLType",
":",
"\"",
"\"",
",",
"}",
"\n",
"}",
"\n\n",
"// TODO - parallel?",
"for",
"_",
",",
"target",
":=",
"range",
"pages",
"{",
"u",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"target",
".",
"webURL",
")",
"\n",
"c",
",",
"err",
":=",
"cgitCloneURL",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"u",
",",
"c",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"target",
".",
"cloneURL",
"=",
"c",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"pages",
",",
"nil",
"\n",
"}"
] | // getCGitRepos finds repo names from the CGit index page hosted at
// URL `u`. | [
"getCGitRepos",
"finds",
"repo",
"names",
"from",
"the",
"CGit",
"index",
"page",
"hosted",
"at",
"URL",
"u",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-mirror-gitiles/cgit.go#L54-L93 |
150,324 | google/zoekt | indexfile_linux.go | NewIndexFile | func NewIndexFile(f *os.File) (IndexFile, error) {
defer f.Close()
fi, err := f.Stat()
if err != nil {
return nil, err
}
sz := fi.Size()
if sz >= maxUInt32 {
return nil, fmt.Errorf("file %s too large: %d", f.Name(), sz)
}
r := &mmapedIndexFile{
name: f.Name(),
size: uint32(sz),
}
rounded := (r.size + 4095) &^ 4095
r.data, err = syscall.Mmap(int(f.Fd()), 0, int(rounded), syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return nil, err
}
return r, err
} | go | func NewIndexFile(f *os.File) (IndexFile, error) {
defer f.Close()
fi, err := f.Stat()
if err != nil {
return nil, err
}
sz := fi.Size()
if sz >= maxUInt32 {
return nil, fmt.Errorf("file %s too large: %d", f.Name(), sz)
}
r := &mmapedIndexFile{
name: f.Name(),
size: uint32(sz),
}
rounded := (r.size + 4095) &^ 4095
r.data, err = syscall.Mmap(int(f.Fd()), 0, int(rounded), syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return nil, err
}
return r, err
} | [
"func",
"NewIndexFile",
"(",
"f",
"*",
"os",
".",
"File",
")",
"(",
"IndexFile",
",",
"error",
")",
"{",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"fi",
",",
"err",
":=",
"f",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"sz",
":=",
"fi",
".",
"Size",
"(",
")",
"\n",
"if",
"sz",
">=",
"maxUInt32",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
".",
"Name",
"(",
")",
",",
"sz",
")",
"\n",
"}",
"\n",
"r",
":=",
"&",
"mmapedIndexFile",
"{",
"name",
":",
"f",
".",
"Name",
"(",
")",
",",
"size",
":",
"uint32",
"(",
"sz",
")",
",",
"}",
"\n\n",
"rounded",
":=",
"(",
"r",
".",
"size",
"+",
"4095",
")",
"&^",
"4095",
"\n",
"r",
".",
"data",
",",
"err",
"=",
"syscall",
".",
"Mmap",
"(",
"int",
"(",
"f",
".",
"Fd",
"(",
")",
")",
",",
"0",
",",
"int",
"(",
"rounded",
")",
",",
"syscall",
".",
"PROT_READ",
",",
"syscall",
".",
"MAP_SHARED",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"r",
",",
"err",
"\n",
"}"
] | // NewIndexFile returns a new index file. The index file takes
// ownership of the passed in file, and may close it. | [
"NewIndexFile",
"returns",
"a",
"new",
"index",
"file",
".",
"The",
"index",
"file",
"takes",
"ownership",
"of",
"the",
"passed",
"in",
"file",
"and",
"may",
"close",
"it",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/indexfile_linux.go#L50-L74 |
150,325 | google/zoekt | gitindex/filter.go | Include | func (f *Filter) Include(name string) bool {
if f.inc != nil {
if !f.inc.MatchString(name) {
return false
}
}
if f.exc != nil {
if f.exc.MatchString(name) {
return false
}
}
return true
} | go | func (f *Filter) Include(name string) bool {
if f.inc != nil {
if !f.inc.MatchString(name) {
return false
}
}
if f.exc != nil {
if f.exc.MatchString(name) {
return false
}
}
return true
} | [
"func",
"(",
"f",
"*",
"Filter",
")",
"Include",
"(",
"name",
"string",
")",
"bool",
"{",
"if",
"f",
".",
"inc",
"!=",
"nil",
"{",
"if",
"!",
"f",
".",
"inc",
".",
"MatchString",
"(",
"name",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"f",
".",
"exc",
"!=",
"nil",
"{",
"if",
"f",
".",
"exc",
".",
"MatchString",
"(",
"name",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Include returns true if the name passes the filter. | [
"Include",
"returns",
"true",
"if",
"the",
"name",
"passes",
"the",
"filter",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/filter.go#L25-L37 |
150,326 | google/zoekt | gitindex/filter.go | NewFilter | func NewFilter(includeRegex, excludeRegex string) (*Filter, error) {
f := &Filter{}
var err error
if includeRegex != "" {
f.inc, err = regexp.Compile(includeRegex)
if err != nil {
return nil, err
}
}
if excludeRegex != "" {
f.exc, err = regexp.Compile(excludeRegex)
if err != nil {
return nil, err
}
}
return f, nil
} | go | func NewFilter(includeRegex, excludeRegex string) (*Filter, error) {
f := &Filter{}
var err error
if includeRegex != "" {
f.inc, err = regexp.Compile(includeRegex)
if err != nil {
return nil, err
}
}
if excludeRegex != "" {
f.exc, err = regexp.Compile(excludeRegex)
if err != nil {
return nil, err
}
}
return f, nil
} | [
"func",
"NewFilter",
"(",
"includeRegex",
",",
"excludeRegex",
"string",
")",
"(",
"*",
"Filter",
",",
"error",
")",
"{",
"f",
":=",
"&",
"Filter",
"{",
"}",
"\n",
"var",
"err",
"error",
"\n",
"if",
"includeRegex",
"!=",
"\"",
"\"",
"{",
"f",
".",
"inc",
",",
"err",
"=",
"regexp",
".",
"Compile",
"(",
"includeRegex",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"excludeRegex",
"!=",
"\"",
"\"",
"{",
"f",
".",
"exc",
",",
"err",
"=",
"regexp",
".",
"Compile",
"(",
"excludeRegex",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"f",
",",
"nil",
"\n",
"}"
] | // NewFilter creates a new filter. | [
"NewFilter",
"creates",
"a",
"new",
"filter",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/filter.go#L40-L58 |
150,327 | google/zoekt | matchiter.go | matchContent | func (m *candidateMatch) matchContent(content []byte) bool {
if m.caseSensitive {
comp := bytes.Equal(m.substrBytes, content[m.byteOffset:m.byteOffset+uint32(len(m.substrBytes))])
m.byteMatchSz = uint32(len(m.substrBytes))
return comp
} else {
// It is tempting to try a simple ASCII based
// comparison if possible, but we need more
// information. Simple ASCII chars have unicode upper
// case variants (the ASCII 'k' has the Kelvin symbol
// as upper case variant). We can only degrade to
// ASCII if we are sure that both the corpus and the
// query is ASCII only
sz, ok := caseFoldingEqualsRunes(m.substrLowered, content[m.byteOffset:])
m.byteMatchSz = uint32(sz)
return ok
}
} | go | func (m *candidateMatch) matchContent(content []byte) bool {
if m.caseSensitive {
comp := bytes.Equal(m.substrBytes, content[m.byteOffset:m.byteOffset+uint32(len(m.substrBytes))])
m.byteMatchSz = uint32(len(m.substrBytes))
return comp
} else {
// It is tempting to try a simple ASCII based
// comparison if possible, but we need more
// information. Simple ASCII chars have unicode upper
// case variants (the ASCII 'k' has the Kelvin symbol
// as upper case variant). We can only degrade to
// ASCII if we are sure that both the corpus and the
// query is ASCII only
sz, ok := caseFoldingEqualsRunes(m.substrLowered, content[m.byteOffset:])
m.byteMatchSz = uint32(sz)
return ok
}
} | [
"func",
"(",
"m",
"*",
"candidateMatch",
")",
"matchContent",
"(",
"content",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"m",
".",
"caseSensitive",
"{",
"comp",
":=",
"bytes",
".",
"Equal",
"(",
"m",
".",
"substrBytes",
",",
"content",
"[",
"m",
".",
"byteOffset",
":",
"m",
".",
"byteOffset",
"+",
"uint32",
"(",
"len",
"(",
"m",
".",
"substrBytes",
")",
")",
"]",
")",
"\n\n",
"m",
".",
"byteMatchSz",
"=",
"uint32",
"(",
"len",
"(",
"m",
".",
"substrBytes",
")",
")",
"\n",
"return",
"comp",
"\n",
"}",
"else",
"{",
"// It is tempting to try a simple ASCII based",
"// comparison if possible, but we need more",
"// information. Simple ASCII chars have unicode upper",
"// case variants (the ASCII 'k' has the Kelvin symbol",
"// as upper case variant). We can only degrade to",
"// ASCII if we are sure that both the corpus and the",
"// query is ASCII only",
"sz",
",",
"ok",
":=",
"caseFoldingEqualsRunes",
"(",
"m",
".",
"substrLowered",
",",
"content",
"[",
"m",
".",
"byteOffset",
":",
"]",
")",
"\n",
"m",
".",
"byteMatchSz",
"=",
"uint32",
"(",
"sz",
")",
"\n",
"return",
"ok",
"\n",
"}",
"\n",
"}"
] | // Matches content against the substring, and populates byteMatchSz on success | [
"Matches",
"content",
"against",
"the",
"substring",
"and",
"populates",
"byteMatchSz",
"on",
"success"
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/matchiter.go#L43-L61 |
150,328 | google/zoekt | eval.go | gatherBranches | func (d *indexData) gatherBranches(docID uint32, mt matchTree, known map[matchTree]bool) []string {
foundBranchQuery := false
var branches []string
visitMatches(mt, known, func(mt matchTree) {
bq, ok := mt.(*branchQueryMatchTree)
if ok {
foundBranchQuery = true
branches = append(branches,
d.branchNames[uint(bq.mask)])
}
})
if !foundBranchQuery {
mask := d.fileBranchMasks[docID]
id := uint32(1)
for mask != 0 {
if mask&0x1 != 0 {
branches = append(branches, d.branchNames[uint(id)])
}
id <<= 1
mask >>= 1
}
}
return branches
} | go | func (d *indexData) gatherBranches(docID uint32, mt matchTree, known map[matchTree]bool) []string {
foundBranchQuery := false
var branches []string
visitMatches(mt, known, func(mt matchTree) {
bq, ok := mt.(*branchQueryMatchTree)
if ok {
foundBranchQuery = true
branches = append(branches,
d.branchNames[uint(bq.mask)])
}
})
if !foundBranchQuery {
mask := d.fileBranchMasks[docID]
id := uint32(1)
for mask != 0 {
if mask&0x1 != 0 {
branches = append(branches, d.branchNames[uint(id)])
}
id <<= 1
mask >>= 1
}
}
return branches
} | [
"func",
"(",
"d",
"*",
"indexData",
")",
"gatherBranches",
"(",
"docID",
"uint32",
",",
"mt",
"matchTree",
",",
"known",
"map",
"[",
"matchTree",
"]",
"bool",
")",
"[",
"]",
"string",
"{",
"foundBranchQuery",
":=",
"false",
"\n",
"var",
"branches",
"[",
"]",
"string",
"\n\n",
"visitMatches",
"(",
"mt",
",",
"known",
",",
"func",
"(",
"mt",
"matchTree",
")",
"{",
"bq",
",",
"ok",
":=",
"mt",
".",
"(",
"*",
"branchQueryMatchTree",
")",
"\n",
"if",
"ok",
"{",
"foundBranchQuery",
"=",
"true",
"\n",
"branches",
"=",
"append",
"(",
"branches",
",",
"d",
".",
"branchNames",
"[",
"uint",
"(",
"bq",
".",
"mask",
")",
"]",
")",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"if",
"!",
"foundBranchQuery",
"{",
"mask",
":=",
"d",
".",
"fileBranchMasks",
"[",
"docID",
"]",
"\n",
"id",
":=",
"uint32",
"(",
"1",
")",
"\n",
"for",
"mask",
"!=",
"0",
"{",
"if",
"mask",
"&",
"0x1",
"!=",
"0",
"{",
"branches",
"=",
"append",
"(",
"branches",
",",
"d",
".",
"branchNames",
"[",
"uint",
"(",
"id",
")",
"]",
")",
"\n",
"}",
"\n",
"id",
"<<=",
"1",
"\n",
"mask",
">>=",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"branches",
"\n",
"}"
] | // gatherBranches returns a list of branch names. | [
"gatherBranches",
"returns",
"a",
"list",
"of",
"branch",
"names",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/eval.go#L366-L391 |
150,329 | google/zoekt | gitindex/clone.go | CloneRepo | func CloneRepo(destDir, name, cloneURL string, settings map[string]string) (string, error) {
parent := filepath.Join(destDir, filepath.Dir(name))
if err := os.MkdirAll(parent, 0755); err != nil {
return "", err
}
repoDest := filepath.Join(parent, filepath.Base(name)+".git")
if _, err := os.Lstat(repoDest); err == nil {
return "", nil
}
var keys []string
for k := range settings {
keys = append(keys, k)
}
sort.Strings(keys)
var config []string
for _, k := range keys {
if settings[k] != "" {
config = append(config, "--config", k+"="+settings[k])
}
}
cmd := exec.Command(
"git", "clone", "--bare", "--verbose", "--progress",
// Only fetch branch heads, and ignore note branches.
"--config", "remote.origin.fetch=+refs/heads/*:refs/heads/*")
cmd.Args = append(cmd.Args, config...)
cmd.Args = append(cmd.Args, cloneURL, repoDest)
// Prevent prompting
cmd.Stdin = &bytes.Buffer{}
log.Println("running:", cmd.Args)
if err := cmd.Run(); err != nil {
return "", err
}
return repoDest, nil
} | go | func CloneRepo(destDir, name, cloneURL string, settings map[string]string) (string, error) {
parent := filepath.Join(destDir, filepath.Dir(name))
if err := os.MkdirAll(parent, 0755); err != nil {
return "", err
}
repoDest := filepath.Join(parent, filepath.Base(name)+".git")
if _, err := os.Lstat(repoDest); err == nil {
return "", nil
}
var keys []string
for k := range settings {
keys = append(keys, k)
}
sort.Strings(keys)
var config []string
for _, k := range keys {
if settings[k] != "" {
config = append(config, "--config", k+"="+settings[k])
}
}
cmd := exec.Command(
"git", "clone", "--bare", "--verbose", "--progress",
// Only fetch branch heads, and ignore note branches.
"--config", "remote.origin.fetch=+refs/heads/*:refs/heads/*")
cmd.Args = append(cmd.Args, config...)
cmd.Args = append(cmd.Args, cloneURL, repoDest)
// Prevent prompting
cmd.Stdin = &bytes.Buffer{}
log.Println("running:", cmd.Args)
if err := cmd.Run(); err != nil {
return "", err
}
return repoDest, nil
} | [
"func",
"CloneRepo",
"(",
"destDir",
",",
"name",
",",
"cloneURL",
"string",
",",
"settings",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"parent",
":=",
"filepath",
".",
"Join",
"(",
"destDir",
",",
"filepath",
".",
"Dir",
"(",
"name",
")",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"parent",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"repoDest",
":=",
"filepath",
".",
"Join",
"(",
"parent",
",",
"filepath",
".",
"Base",
"(",
"name",
")",
"+",
"\"",
"\"",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"repoDest",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"keys",
"[",
"]",
"string",
"\n",
"for",
"k",
":=",
"range",
"settings",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n\n",
"var",
"config",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"if",
"settings",
"[",
"k",
"]",
"!=",
"\"",
"\"",
"{",
"config",
"=",
"append",
"(",
"config",
",",
"\"",
"\"",
",",
"k",
"+",
"\"",
"\"",
"+",
"settings",
"[",
"k",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"// Only fetch branch heads, and ignore note branches.",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Args",
"=",
"append",
"(",
"cmd",
".",
"Args",
",",
"config",
"...",
")",
"\n",
"cmd",
".",
"Args",
"=",
"append",
"(",
"cmd",
".",
"Args",
",",
"cloneURL",
",",
"repoDest",
")",
"\n\n",
"// Prevent prompting",
"cmd",
".",
"Stdin",
"=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"cmd",
".",
"Args",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"repoDest",
",",
"nil",
"\n",
"}"
] | // CloneRepo clones one repository, adding the given config
// settings. It returns the bare repo directory. The `name` argument
// determines where the repo is stored relative to `destDir`. Returns
// the directory of the repository. | [
"CloneRepo",
"clones",
"one",
"repository",
"adding",
"the",
"given",
"config",
"settings",
".",
"It",
"returns",
"the",
"bare",
"repo",
"directory",
".",
"The",
"name",
"argument",
"determines",
"where",
"the",
"repo",
"is",
"stored",
"relative",
"to",
"destDir",
".",
"Returns",
"the",
"directory",
"of",
"the",
"repository",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/clone.go#L30-L68 |
150,330 | google/zoekt | build/builder.go | HashOptions | func (o *Options) HashOptions() string {
hasher := sha1.New()
hasher.Write([]byte(o.CTags))
hasher.Write([]byte(fmt.Sprintf("%t", o.CTagsMustSucceed)))
hasher.Write([]byte(fmt.Sprintf("%d", o.SizeMax)))
hasher.Write([]byte(fmt.Sprintf("%q", o.LargeFiles)))
return fmt.Sprintf("%x", hasher.Sum(nil))
} | go | func (o *Options) HashOptions() string {
hasher := sha1.New()
hasher.Write([]byte(o.CTags))
hasher.Write([]byte(fmt.Sprintf("%t", o.CTagsMustSucceed)))
hasher.Write([]byte(fmt.Sprintf("%d", o.SizeMax)))
hasher.Write([]byte(fmt.Sprintf("%q", o.LargeFiles)))
return fmt.Sprintf("%x", hasher.Sum(nil))
} | [
"func",
"(",
"o",
"*",
"Options",
")",
"HashOptions",
"(",
")",
"string",
"{",
"hasher",
":=",
"sha1",
".",
"New",
"(",
")",
"\n\n",
"hasher",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"o",
".",
"CTags",
")",
")",
"\n",
"hasher",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"o",
".",
"CTagsMustSucceed",
")",
")",
")",
"\n",
"hasher",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"o",
".",
"SizeMax",
")",
")",
")",
"\n",
"hasher",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"o",
".",
"LargeFiles",
")",
")",
")",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hasher",
".",
"Sum",
"(",
"nil",
")",
")",
"\n",
"}"
] | // HashOptions creates a hash of the options that affect an index. | [
"HashOptions",
"creates",
"a",
"hash",
"of",
"the",
"options",
"that",
"affect",
"an",
"index",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/build/builder.go#L84-L93 |
150,331 | google/zoekt | build/builder.go | SetDefaults | func (o *Options) SetDefaults() {
if o.CTags == "" {
ctags, err := exec.LookPath("universal-ctags")
if err == nil {
o.CTags = ctags
}
}
if o.CTags == "" {
ctags, err := exec.LookPath("ctags-exuberant")
if err == nil {
o.CTags = ctags
}
}
if o.Parallelism == 0 {
o.Parallelism = 1
}
if o.SizeMax == 0 {
o.SizeMax = 128 << 10
}
if o.ShardMax == 0 {
o.ShardMax = 128 << 20
}
if o.RepositoryDescription.Name == "" && o.RepositoryDescription.URL != "" {
parsed, _ := url.Parse(o.RepositoryDescription.URL)
if parsed != nil {
o.RepositoryDescription.Name = filepath.Join(parsed.Host, parsed.Path)
}
}
} | go | func (o *Options) SetDefaults() {
if o.CTags == "" {
ctags, err := exec.LookPath("universal-ctags")
if err == nil {
o.CTags = ctags
}
}
if o.CTags == "" {
ctags, err := exec.LookPath("ctags-exuberant")
if err == nil {
o.CTags = ctags
}
}
if o.Parallelism == 0 {
o.Parallelism = 1
}
if o.SizeMax == 0 {
o.SizeMax = 128 << 10
}
if o.ShardMax == 0 {
o.ShardMax = 128 << 20
}
if o.RepositoryDescription.Name == "" && o.RepositoryDescription.URL != "" {
parsed, _ := url.Parse(o.RepositoryDescription.URL)
if parsed != nil {
o.RepositoryDescription.Name = filepath.Join(parsed.Host, parsed.Path)
}
}
} | [
"func",
"(",
"o",
"*",
"Options",
")",
"SetDefaults",
"(",
")",
"{",
"if",
"o",
".",
"CTags",
"==",
"\"",
"\"",
"{",
"ctags",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"o",
".",
"CTags",
"=",
"ctags",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"CTags",
"==",
"\"",
"\"",
"{",
"ctags",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"o",
".",
"CTags",
"=",
"ctags",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"o",
".",
"Parallelism",
"==",
"0",
"{",
"o",
".",
"Parallelism",
"=",
"1",
"\n",
"}",
"\n",
"if",
"o",
".",
"SizeMax",
"==",
"0",
"{",
"o",
".",
"SizeMax",
"=",
"128",
"<<",
"10",
"\n",
"}",
"\n",
"if",
"o",
".",
"ShardMax",
"==",
"0",
"{",
"o",
".",
"ShardMax",
"=",
"128",
"<<",
"20",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"RepositoryDescription",
".",
"Name",
"==",
"\"",
"\"",
"&&",
"o",
".",
"RepositoryDescription",
".",
"URL",
"!=",
"\"",
"\"",
"{",
"parsed",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"o",
".",
"RepositoryDescription",
".",
"URL",
")",
"\n",
"if",
"parsed",
"!=",
"nil",
"{",
"o",
".",
"RepositoryDescription",
".",
"Name",
"=",
"filepath",
".",
"Join",
"(",
"parsed",
".",
"Host",
",",
"parsed",
".",
"Path",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // SetDefaults sets reasonable default options. | [
"SetDefaults",
"sets",
"reasonable",
"default",
"options",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/build/builder.go#L123-L153 |
150,332 | google/zoekt | build/builder.go | shardName | func (o *Options) shardName(n int) string {
abs := url.QueryEscape(o.RepositoryDescription.Name)
if len(abs) > 200 {
abs = abs[:200] + hashString(abs)[:8]
}
return filepath.Join(o.IndexDir,
fmt.Sprintf("%s_v%d.%05d.zoekt", abs, zoekt.IndexFormatVersion, n))
} | go | func (o *Options) shardName(n int) string {
abs := url.QueryEscape(o.RepositoryDescription.Name)
if len(abs) > 200 {
abs = abs[:200] + hashString(abs)[:8]
}
return filepath.Join(o.IndexDir,
fmt.Sprintf("%s_v%d.%05d.zoekt", abs, zoekt.IndexFormatVersion, n))
} | [
"func",
"(",
"o",
"*",
"Options",
")",
"shardName",
"(",
"n",
"int",
")",
"string",
"{",
"abs",
":=",
"url",
".",
"QueryEscape",
"(",
"o",
".",
"RepositoryDescription",
".",
"Name",
")",
"\n",
"if",
"len",
"(",
"abs",
")",
">",
"200",
"{",
"abs",
"=",
"abs",
"[",
":",
"200",
"]",
"+",
"hashString",
"(",
"abs",
")",
"[",
":",
"8",
"]",
"\n",
"}",
"\n",
"return",
"filepath",
".",
"Join",
"(",
"o",
".",
"IndexDir",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"abs",
",",
"zoekt",
".",
"IndexFormatVersion",
",",
"n",
")",
")",
"\n",
"}"
] | // ShardName returns the name the given index shard. | [
"ShardName",
"returns",
"the",
"name",
"the",
"given",
"index",
"shard",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/build/builder.go#L162-L169 |
150,333 | google/zoekt | build/builder.go | IndexVersions | func (o *Options) IndexVersions() []zoekt.RepositoryBranch {
fn := o.shardName(0)
f, err := os.Open(fn)
if err != nil {
return nil
}
iFile, err := zoekt.NewIndexFile(f)
if err != nil {
return nil
}
defer iFile.Close()
repo, index, err := zoekt.ReadMetadata(iFile)
if err != nil {
return nil
}
if index.IndexFeatureVersion != zoekt.FeatureVersion {
return nil
}
if repo.IndexOptions != o.HashOptions() {
return nil
}
return repo.Branches
} | go | func (o *Options) IndexVersions() []zoekt.RepositoryBranch {
fn := o.shardName(0)
f, err := os.Open(fn)
if err != nil {
return nil
}
iFile, err := zoekt.NewIndexFile(f)
if err != nil {
return nil
}
defer iFile.Close()
repo, index, err := zoekt.ReadMetadata(iFile)
if err != nil {
return nil
}
if index.IndexFeatureVersion != zoekt.FeatureVersion {
return nil
}
if repo.IndexOptions != o.HashOptions() {
return nil
}
return repo.Branches
} | [
"func",
"(",
"o",
"*",
"Options",
")",
"IndexVersions",
"(",
")",
"[",
"]",
"zoekt",
".",
"RepositoryBranch",
"{",
"fn",
":=",
"o",
".",
"shardName",
"(",
"0",
")",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"fn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"iFile",
",",
"err",
":=",
"zoekt",
".",
"NewIndexFile",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"defer",
"iFile",
".",
"Close",
"(",
")",
"\n\n",
"repo",
",",
"index",
",",
"err",
":=",
"zoekt",
".",
"ReadMetadata",
"(",
"iFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"index",
".",
"IndexFeatureVersion",
"!=",
"zoekt",
".",
"FeatureVersion",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"repo",
".",
"IndexOptions",
"!=",
"o",
".",
"HashOptions",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"repo",
".",
"Branches",
"\n",
"}"
] | // IndexVersions returns the versions as present in the index, for
// implementing incremental indexing. | [
"IndexVersions",
"returns",
"the",
"versions",
"as",
"present",
"in",
"the",
"index",
"for",
"implementing",
"incremental",
"indexing",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/build/builder.go#L173-L201 |
150,334 | google/zoekt | build/builder.go | IgnoreSizeMax | func (o *Options) IgnoreSizeMax(name string) bool {
for _, pattern := range o.LargeFiles {
pattern = strings.TrimSpace(pattern)
m, _ := filepath.Match(pattern, name)
if m {
return true
}
}
return false
} | go | func (o *Options) IgnoreSizeMax(name string) bool {
for _, pattern := range o.LargeFiles {
pattern = strings.TrimSpace(pattern)
m, _ := filepath.Match(pattern, name)
if m {
return true
}
}
return false
} | [
"func",
"(",
"o",
"*",
"Options",
")",
"IgnoreSizeMax",
"(",
"name",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"pattern",
":=",
"range",
"o",
".",
"LargeFiles",
"{",
"pattern",
"=",
"strings",
".",
"TrimSpace",
"(",
"pattern",
")",
"\n",
"m",
",",
"_",
":=",
"filepath",
".",
"Match",
"(",
"pattern",
",",
"name",
")",
"\n",
"if",
"m",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // IgnoreSizeMax determines whether the max size should be ignored. | [
"IgnoreSizeMax",
"determines",
"whether",
"the",
"max",
"size",
"should",
"be",
"ignored",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/build/builder.go#L204-L214 |
150,335 | google/zoekt | build/builder.go | NewBuilder | func NewBuilder(opts Options) (*Builder, error) {
opts.SetDefaults()
if opts.RepositoryDescription.Name == "" {
return nil, fmt.Errorf("builder: must set Name")
}
b := &Builder{
opts: opts,
throttle: make(chan int, opts.Parallelism),
finishedShards: map[string]string{},
}
if b.opts.CTags == "" && b.opts.CTagsMustSucceed {
return nil, fmt.Errorf("ctags binary not found, but CTagsMustSucceed set")
}
if strings.Contains(opts.CTags, "universal-ctags") {
parser, err := ctags.NewParser(opts.CTags)
if err != nil && opts.CTagsMustSucceed {
return nil, fmt.Errorf("ctags.NewParser: %v", err)
}
b.parser = parser
}
if _, err := b.newShardBuilder(); err != nil {
return nil, err
}
return b, nil
} | go | func NewBuilder(opts Options) (*Builder, error) {
opts.SetDefaults()
if opts.RepositoryDescription.Name == "" {
return nil, fmt.Errorf("builder: must set Name")
}
b := &Builder{
opts: opts,
throttle: make(chan int, opts.Parallelism),
finishedShards: map[string]string{},
}
if b.opts.CTags == "" && b.opts.CTagsMustSucceed {
return nil, fmt.Errorf("ctags binary not found, but CTagsMustSucceed set")
}
if strings.Contains(opts.CTags, "universal-ctags") {
parser, err := ctags.NewParser(opts.CTags)
if err != nil && opts.CTagsMustSucceed {
return nil, fmt.Errorf("ctags.NewParser: %v", err)
}
b.parser = parser
}
if _, err := b.newShardBuilder(); err != nil {
return nil, err
}
return b, nil
} | [
"func",
"NewBuilder",
"(",
"opts",
"Options",
")",
"(",
"*",
"Builder",
",",
"error",
")",
"{",
"opts",
".",
"SetDefaults",
"(",
")",
"\n",
"if",
"opts",
".",
"RepositoryDescription",
".",
"Name",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"b",
":=",
"&",
"Builder",
"{",
"opts",
":",
"opts",
",",
"throttle",
":",
"make",
"(",
"chan",
"int",
",",
"opts",
".",
"Parallelism",
")",
",",
"finishedShards",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"}",
"\n\n",
"if",
"b",
".",
"opts",
".",
"CTags",
"==",
"\"",
"\"",
"&&",
"b",
".",
"opts",
".",
"CTagsMustSucceed",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"Contains",
"(",
"opts",
".",
"CTags",
",",
"\"",
"\"",
")",
"{",
"parser",
",",
"err",
":=",
"ctags",
".",
"NewParser",
"(",
"opts",
".",
"CTags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"opts",
".",
"CTagsMustSucceed",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"b",
".",
"parser",
"=",
"parser",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"b",
".",
"newShardBuilder",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"b",
",",
"nil",
"\n",
"}"
] | // NewBuilder creates a new Builder instance. | [
"NewBuilder",
"creates",
"a",
"new",
"Builder",
"instance",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/build/builder.go#L217-L246 |
150,336 | google/zoekt | build/builder.go | AddFile | func (b *Builder) AddFile(name string, content []byte) error {
return b.Add(zoekt.Document{Name: name, Content: content})
} | go | func (b *Builder) AddFile(name string, content []byte) error {
return b.Add(zoekt.Document{Name: name, Content: content})
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"AddFile",
"(",
"name",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"b",
".",
"Add",
"(",
"zoekt",
".",
"Document",
"{",
"Name",
":",
"name",
",",
"Content",
":",
"content",
"}",
")",
"\n",
"}"
] | // AddFile is a convenience wrapper for the Add method | [
"AddFile",
"is",
"a",
"convenience",
"wrapper",
"for",
"the",
"Add",
"method"
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/build/builder.go#L249-L251 |
150,337 | google/zoekt | build/builder.go | Finish | func (b *Builder) Finish() error {
b.flush()
b.building.Wait()
if b.buildError != nil {
for tmp := range b.finishedShards {
os.Remove(tmp)
}
return b.buildError
}
for tmp, final := range b.finishedShards {
if err := os.Rename(tmp, final); err != nil {
b.buildError = err
}
}
if b.nextShardNum > 0 {
b.deleteRemainingShards()
}
return b.buildError
} | go | func (b *Builder) Finish() error {
b.flush()
b.building.Wait()
if b.buildError != nil {
for tmp := range b.finishedShards {
os.Remove(tmp)
}
return b.buildError
}
for tmp, final := range b.finishedShards {
if err := os.Rename(tmp, final); err != nil {
b.buildError = err
}
}
if b.nextShardNum > 0 {
b.deleteRemainingShards()
}
return b.buildError
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Finish",
"(",
")",
"error",
"{",
"b",
".",
"flush",
"(",
")",
"\n",
"b",
".",
"building",
".",
"Wait",
"(",
")",
"\n\n",
"if",
"b",
".",
"buildError",
"!=",
"nil",
"{",
"for",
"tmp",
":=",
"range",
"b",
".",
"finishedShards",
"{",
"os",
".",
"Remove",
"(",
"tmp",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"buildError",
"\n",
"}",
"\n\n",
"for",
"tmp",
",",
"final",
":=",
"range",
"b",
".",
"finishedShards",
"{",
"if",
"err",
":=",
"os",
".",
"Rename",
"(",
"tmp",
",",
"final",
")",
";",
"err",
"!=",
"nil",
"{",
"b",
".",
"buildError",
"=",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"b",
".",
"nextShardNum",
">",
"0",
"{",
"b",
".",
"deleteRemainingShards",
"(",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"buildError",
"\n",
"}"
] | // Finish creates a last shard from the buffered documents, and clears
// stale shards from previous runs | [
"Finish",
"creates",
"a",
"last",
"shard",
"from",
"the",
"buffered",
"documents",
"and",
"clears",
"stale",
"shards",
"from",
"previous",
"runs"
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/build/builder.go#L276-L297 |
150,338 | google/zoekt | shards/shards.go | NewDirectorySearcher | func NewDirectorySearcher(dir string) (zoekt.Searcher, error) {
ss := newShardedSearcher(int64(runtime.NumCPU()))
tl := &throttledLoader{
ss: ss,
throttle: make(chan struct{}, runtime.NumCPU()),
}
_, err := NewDirectoryWatcher(dir, tl)
if err != nil {
return nil, err
}
return ss, nil
} | go | func NewDirectorySearcher(dir string) (zoekt.Searcher, error) {
ss := newShardedSearcher(int64(runtime.NumCPU()))
tl := &throttledLoader{
ss: ss,
throttle: make(chan struct{}, runtime.NumCPU()),
}
_, err := NewDirectoryWatcher(dir, tl)
if err != nil {
return nil, err
}
return ss, nil
} | [
"func",
"NewDirectorySearcher",
"(",
"dir",
"string",
")",
"(",
"zoekt",
".",
"Searcher",
",",
"error",
")",
"{",
"ss",
":=",
"newShardedSearcher",
"(",
"int64",
"(",
"runtime",
".",
"NumCPU",
"(",
")",
")",
")",
"\n",
"tl",
":=",
"&",
"throttledLoader",
"{",
"ss",
":",
"ss",
",",
"throttle",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"runtime",
".",
"NumCPU",
"(",
")",
")",
",",
"}",
"\n",
"_",
",",
"err",
":=",
"NewDirectoryWatcher",
"(",
"dir",
",",
"tl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ss",
",",
"nil",
"\n",
"}"
] | // NewDirectorySearcher returns a searcher instance that loads all
// shards corresponding to a glob into memory. | [
"NewDirectorySearcher",
"returns",
"a",
"searcher",
"instance",
"that",
"loads",
"all",
"shards",
"corresponding",
"to",
"a",
"glob",
"into",
"memory",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/shards/shards.go#L61-L73 |
150,339 | google/zoekt | shards/shards.go | Close | func (ss *shardedSearcher) Close() {
ss.lock(context.Background())
defer ss.unlock()
for _, s := range ss.shards {
s.Close()
}
} | go | func (ss *shardedSearcher) Close() {
ss.lock(context.Background())
defer ss.unlock()
for _, s := range ss.shards {
s.Close()
}
} | [
"func",
"(",
"ss",
"*",
"shardedSearcher",
")",
"Close",
"(",
")",
"{",
"ss",
".",
"lock",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"defer",
"ss",
".",
"unlock",
"(",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"ss",
".",
"shards",
"{",
"s",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Close closes references to open files. It may be called only once. | [
"Close",
"closes",
"references",
"to",
"open",
"files",
".",
"It",
"may",
"be",
"called",
"only",
"once",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/shards/shards.go#L102-L108 |
150,340 | google/zoekt | shards/shards.go | getShards | func (s *shardedSearcher) getShards() []rankedShard {
var res []rankedShard
for _, sh := range s.shards {
res = append(res, sh)
}
// TODO: precompute this.
sort.Slice(res, func(i, j int) bool {
return res[i].rank > res[j].rank
})
return res
} | go | func (s *shardedSearcher) getShards() []rankedShard {
var res []rankedShard
for _, sh := range s.shards {
res = append(res, sh)
}
// TODO: precompute this.
sort.Slice(res, func(i, j int) bool {
return res[i].rank > res[j].rank
})
return res
} | [
"func",
"(",
"s",
"*",
"shardedSearcher",
")",
"getShards",
"(",
")",
"[",
"]",
"rankedShard",
"{",
"var",
"res",
"[",
"]",
"rankedShard",
"\n",
"for",
"_",
",",
"sh",
":=",
"range",
"s",
".",
"shards",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"sh",
")",
"\n",
"}",
"\n",
"// TODO: precompute this.",
"sort",
".",
"Slice",
"(",
"res",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"res",
"[",
"i",
"]",
".",
"rank",
">",
"res",
"[",
"j",
"]",
".",
"rank",
"\n",
"}",
")",
"\n",
"return",
"res",
"\n",
"}"
] | // getShards returns the currently loaded shards. The shards must be
// accessed under a rlock call. The shards are sorted by decreasing
// rank. | [
"getShards",
"returns",
"the",
"currently",
"loaded",
"shards",
".",
"The",
"shards",
"must",
"be",
"accessed",
"under",
"a",
"rlock",
"call",
".",
"The",
"shards",
"are",
"sorted",
"by",
"decreasing",
"rank",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/shards/shards.go#L322-L332 |
150,341 | google/zoekt | gitindex/index.go | RepoModTime | func RepoModTime(dir string) (time.Time, error) {
var last time.Time
refDir := filepath.Join(dir, "refs")
if _, err := os.Lstat(refDir); err == nil {
if err := filepath.Walk(refDir,
func(name string, fi os.FileInfo, err error) error {
if !fi.IsDir() && last.Before(fi.ModTime()) {
last = fi.ModTime()
}
return nil
}); err != nil {
return last, err
}
}
// git gc compresses refs into the following file:
for _, fn := range []string{"info/refs", "packed-refs"} {
if fi, err := os.Lstat(filepath.Join(dir, fn)); err == nil && !fi.IsDir() && last.Before(fi.ModTime()) {
last = fi.ModTime()
}
}
return last, nil
} | go | func RepoModTime(dir string) (time.Time, error) {
var last time.Time
refDir := filepath.Join(dir, "refs")
if _, err := os.Lstat(refDir); err == nil {
if err := filepath.Walk(refDir,
func(name string, fi os.FileInfo, err error) error {
if !fi.IsDir() && last.Before(fi.ModTime()) {
last = fi.ModTime()
}
return nil
}); err != nil {
return last, err
}
}
// git gc compresses refs into the following file:
for _, fn := range []string{"info/refs", "packed-refs"} {
if fi, err := os.Lstat(filepath.Join(dir, fn)); err == nil && !fi.IsDir() && last.Before(fi.ModTime()) {
last = fi.ModTime()
}
}
return last, nil
} | [
"func",
"RepoModTime",
"(",
"dir",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"var",
"last",
"time",
".",
"Time",
"\n",
"refDir",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"refDir",
")",
";",
"err",
"==",
"nil",
"{",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"refDir",
",",
"func",
"(",
"name",
"string",
",",
"fi",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"&&",
"last",
".",
"Before",
"(",
"fi",
".",
"ModTime",
"(",
")",
")",
"{",
"last",
"=",
"fi",
".",
"ModTime",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"last",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// git gc compresses refs into the following file:",
"for",
"_",
",",
"fn",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"{",
"if",
"fi",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"fn",
")",
")",
";",
"err",
"==",
"nil",
"&&",
"!",
"fi",
".",
"IsDir",
"(",
")",
"&&",
"last",
".",
"Before",
"(",
"fi",
".",
"ModTime",
"(",
")",
")",
"{",
"last",
"=",
"fi",
".",
"ModTime",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"last",
",",
"nil",
"\n",
"}"
] | // RepoModTime returns the time of last fetch of a git repository. | [
"RepoModTime",
"returns",
"the",
"time",
"of",
"last",
"fetch",
"of",
"a",
"git",
"repository",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/index.go#L45-L68 |
150,342 | google/zoekt | gitindex/index.go | setTemplates | func setTemplates(repo *zoekt.Repository, u *url.URL, typ string) error {
repo.URL = u.String()
switch typ {
case "gitiles":
/// eg. https://gerrit.googlesource.com/gitiles/+/master/tools/run_dev.sh#20
repo.CommitURLTemplate = u.String() + "/+/{{.Version}}"
repo.FileURLTemplate = u.String() + "/+/{{.Version}}/{{.Path}}"
repo.LineFragmentTemplate = "#{{.LineNumber}}"
case "github":
// eg. https://github.com/hanwen/go-fuse/blob/notify/genversion.sh#L10
repo.CommitURLTemplate = u.String() + "/commit/{{.Version}}"
repo.FileURLTemplate = u.String() + "/blob/{{.Version}}/{{.Path}}"
repo.LineFragmentTemplate = "#L{{.LineNumber}}"
case "cgit":
// http://git.savannah.gnu.org/cgit/lilypond.git/tree/elisp/lilypond-mode.el?h=dev/philh&id=b2ca0fefe3018477aaca23b6f672c7199ba5238e#n100
repo.CommitURLTemplate = u.String() + "/commit/?id={{.Version}}"
repo.FileURLTemplate = u.String() + "/tree/{{.Path}}/?id={{.Version}}"
repo.LineFragmentTemplate = "#n{{.LineNumber}}"
case "gitweb":
// https://gerrit.libreoffice.org/gitweb?p=online.git;a=blob;f=Makefile.am;h=cfcfd7c36fbae10e269653dc57a9b68c92d4c10b;hb=848145503bf7b98ce4a4aa0a858a0d71dd0dbb26#l10
repo.FileURLTemplate = u.String() + ";a=blob;f={{.Path}};hb={{.Version}}"
repo.CommitURLTemplate = u.String() + ";a=commit;h={{.Version}}"
repo.LineFragmentTemplate = "#l{{.LineNumber}}"
case "source.bazel.build":
// https://source.bazel.build/bazel/+/57bc201346e61c62a921c1cbf32ad24f185c10c9
// https://source.bazel.build/bazel/+/57bc201346e61c62a921c1cbf32ad24f185c10c9:tools/cpp/BUILD.empty;l=10
repo.CommitURLTemplate = u.String() + "/+/{{.Version}}"
repo.FileURLTemplate = u.String() + "/+/{{.Version}}:{{.Path}}"
repo.LineFragmentTemplate = ";l={{.LineNumber}}"
case "bitbucket-server":
// https://<bitbucketserver-host>/projects/<project>/repos/<repo>/commits/5be7ca73b898bf17a08e607918accfdeafe1e0bc
// https://<bitbucketserver-host>/projects/<project>/repos/<repo>/browse/<file>?at=5be7ca73b898bf17a08e607918accfdeafe1e0bc
repo.CommitURLTemplate = u.String() + "/commits/{{.Version}}"
repo.FileURLTemplate = u.String() + "/{{.Path}}?at={{.Version}}"
repo.LineFragmentTemplate = "#{{.LineNumber}}"
case "gitlab":
repo.CommitURLTemplate = u.String() + "/commit/{{.Version}}"
repo.FileURLTemplate = u.String() + "/blob/{{.Version}}/{{.Path}}"
repo.LineFragmentTemplate = "#L{{.LineNumber}}"
default:
return fmt.Errorf("URL scheme type %q unknown", typ)
}
return nil
} | go | func setTemplates(repo *zoekt.Repository, u *url.URL, typ string) error {
repo.URL = u.String()
switch typ {
case "gitiles":
/// eg. https://gerrit.googlesource.com/gitiles/+/master/tools/run_dev.sh#20
repo.CommitURLTemplate = u.String() + "/+/{{.Version}}"
repo.FileURLTemplate = u.String() + "/+/{{.Version}}/{{.Path}}"
repo.LineFragmentTemplate = "#{{.LineNumber}}"
case "github":
// eg. https://github.com/hanwen/go-fuse/blob/notify/genversion.sh#L10
repo.CommitURLTemplate = u.String() + "/commit/{{.Version}}"
repo.FileURLTemplate = u.String() + "/blob/{{.Version}}/{{.Path}}"
repo.LineFragmentTemplate = "#L{{.LineNumber}}"
case "cgit":
// http://git.savannah.gnu.org/cgit/lilypond.git/tree/elisp/lilypond-mode.el?h=dev/philh&id=b2ca0fefe3018477aaca23b6f672c7199ba5238e#n100
repo.CommitURLTemplate = u.String() + "/commit/?id={{.Version}}"
repo.FileURLTemplate = u.String() + "/tree/{{.Path}}/?id={{.Version}}"
repo.LineFragmentTemplate = "#n{{.LineNumber}}"
case "gitweb":
// https://gerrit.libreoffice.org/gitweb?p=online.git;a=blob;f=Makefile.am;h=cfcfd7c36fbae10e269653dc57a9b68c92d4c10b;hb=848145503bf7b98ce4a4aa0a858a0d71dd0dbb26#l10
repo.FileURLTemplate = u.String() + ";a=blob;f={{.Path}};hb={{.Version}}"
repo.CommitURLTemplate = u.String() + ";a=commit;h={{.Version}}"
repo.LineFragmentTemplate = "#l{{.LineNumber}}"
case "source.bazel.build":
// https://source.bazel.build/bazel/+/57bc201346e61c62a921c1cbf32ad24f185c10c9
// https://source.bazel.build/bazel/+/57bc201346e61c62a921c1cbf32ad24f185c10c9:tools/cpp/BUILD.empty;l=10
repo.CommitURLTemplate = u.String() + "/+/{{.Version}}"
repo.FileURLTemplate = u.String() + "/+/{{.Version}}:{{.Path}}"
repo.LineFragmentTemplate = ";l={{.LineNumber}}"
case "bitbucket-server":
// https://<bitbucketserver-host>/projects/<project>/repos/<repo>/commits/5be7ca73b898bf17a08e607918accfdeafe1e0bc
// https://<bitbucketserver-host>/projects/<project>/repos/<repo>/browse/<file>?at=5be7ca73b898bf17a08e607918accfdeafe1e0bc
repo.CommitURLTemplate = u.String() + "/commits/{{.Version}}"
repo.FileURLTemplate = u.String() + "/{{.Path}}?at={{.Version}}"
repo.LineFragmentTemplate = "#{{.LineNumber}}"
case "gitlab":
repo.CommitURLTemplate = u.String() + "/commit/{{.Version}}"
repo.FileURLTemplate = u.String() + "/blob/{{.Version}}/{{.Path}}"
repo.LineFragmentTemplate = "#L{{.LineNumber}}"
default:
return fmt.Errorf("URL scheme type %q unknown", typ)
}
return nil
} | [
"func",
"setTemplates",
"(",
"repo",
"*",
"zoekt",
".",
"Repository",
",",
"u",
"*",
"url",
".",
"URL",
",",
"typ",
"string",
")",
"error",
"{",
"repo",
".",
"URL",
"=",
"u",
".",
"String",
"(",
")",
"\n",
"switch",
"typ",
"{",
"case",
"\"",
"\"",
":",
"/// eg. https://gerrit.googlesource.com/gitiles/+/master/tools/run_dev.sh#20",
"repo",
".",
"CommitURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"FileURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"LineFragmentTemplate",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"// eg. https://github.com/hanwen/go-fuse/blob/notify/genversion.sh#L10",
"repo",
".",
"CommitURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"FileURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"LineFragmentTemplate",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"// http://git.savannah.gnu.org/cgit/lilypond.git/tree/elisp/lilypond-mode.el?h=dev/philh&id=b2ca0fefe3018477aaca23b6f672c7199ba5238e#n100",
"repo",
".",
"CommitURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"FileURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"LineFragmentTemplate",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"// https://gerrit.libreoffice.org/gitweb?p=online.git;a=blob;f=Makefile.am;h=cfcfd7c36fbae10e269653dc57a9b68c92d4c10b;hb=848145503bf7b98ce4a4aa0a858a0d71dd0dbb26#l10",
"repo",
".",
"FileURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"CommitURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"LineFragmentTemplate",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"// https://source.bazel.build/bazel/+/57bc201346e61c62a921c1cbf32ad24f185c10c9",
"// https://source.bazel.build/bazel/+/57bc201346e61c62a921c1cbf32ad24f185c10c9:tools/cpp/BUILD.empty;l=10",
"repo",
".",
"CommitURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"FileURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"LineFragmentTemplate",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"// https://<bitbucketserver-host>/projects/<project>/repos/<repo>/commits/5be7ca73b898bf17a08e607918accfdeafe1e0bc",
"// https://<bitbucketserver-host>/projects/<project>/repos/<repo>/browse/<file>?at=5be7ca73b898bf17a08e607918accfdeafe1e0bc",
"repo",
".",
"CommitURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"FileURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"LineFragmentTemplate",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"repo",
".",
"CommitURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"FileURLTemplate",
"=",
"u",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"repo",
".",
"LineFragmentTemplate",
"=",
"\"",
"\"",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"typ",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // setTemplates fills in URL templates for known git hosting
// sites. | [
"setTemplates",
"fills",
"in",
"URL",
"templates",
"for",
"known",
"git",
"hosting",
"sites",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/index.go#L111-L154 |
150,343 | google/zoekt | gitindex/index.go | getCommit | func getCommit(repo *git.Repository, prefix, ref string) (*object.Commit, error) {
sha1, err := repo.ResolveRevision(plumbing.Revision(ref))
// ref might be a branch name (e.g. "master") add branch prefix and try again.
if err != nil {
sha1, err = repo.ResolveRevision(plumbing.Revision(filepath.Join(prefix, ref)))
}
if err != nil {
return nil, err
}
commitObj, err := repo.CommitObject(*sha1)
if err != nil {
return nil, err
}
return commitObj, nil
} | go | func getCommit(repo *git.Repository, prefix, ref string) (*object.Commit, error) {
sha1, err := repo.ResolveRevision(plumbing.Revision(ref))
// ref might be a branch name (e.g. "master") add branch prefix and try again.
if err != nil {
sha1, err = repo.ResolveRevision(plumbing.Revision(filepath.Join(prefix, ref)))
}
if err != nil {
return nil, err
}
commitObj, err := repo.CommitObject(*sha1)
if err != nil {
return nil, err
}
return commitObj, nil
} | [
"func",
"getCommit",
"(",
"repo",
"*",
"git",
".",
"Repository",
",",
"prefix",
",",
"ref",
"string",
")",
"(",
"*",
"object",
".",
"Commit",
",",
"error",
")",
"{",
"sha1",
",",
"err",
":=",
"repo",
".",
"ResolveRevision",
"(",
"plumbing",
".",
"Revision",
"(",
"ref",
")",
")",
"\n",
"// ref might be a branch name (e.g. \"master\") add branch prefix and try again.",
"if",
"err",
"!=",
"nil",
"{",
"sha1",
",",
"err",
"=",
"repo",
".",
"ResolveRevision",
"(",
"plumbing",
".",
"Revision",
"(",
"filepath",
".",
"Join",
"(",
"prefix",
",",
"ref",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"commitObj",
",",
"err",
":=",
"repo",
".",
"CommitObject",
"(",
"*",
"sha1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"commitObj",
",",
"nil",
"\n",
"}"
] | // getCommit returns a tree object for the given reference. | [
"getCommit",
"returns",
"a",
"tree",
"object",
"for",
"the",
"given",
"reference",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/index.go#L157-L172 |
150,344 | google/zoekt | gitindex/index.go | SetTemplatesFromOrigin | func SetTemplatesFromOrigin(desc *zoekt.Repository, u *url.URL) error {
desc.Name = filepath.Join(u.Host, strings.TrimSuffix(u.Path, ".git"))
if strings.HasSuffix(u.Host, ".googlesource.com") {
return setTemplates(desc, u, "gitiles")
} else if u.Host == "github.com" {
u.Path = strings.TrimSuffix(u.Path, ".git")
return setTemplates(desc, u, "github")
} else {
return fmt.Errorf("unknown git hosting site %q", u)
}
} | go | func SetTemplatesFromOrigin(desc *zoekt.Repository, u *url.URL) error {
desc.Name = filepath.Join(u.Host, strings.TrimSuffix(u.Path, ".git"))
if strings.HasSuffix(u.Host, ".googlesource.com") {
return setTemplates(desc, u, "gitiles")
} else if u.Host == "github.com" {
u.Path = strings.TrimSuffix(u.Path, ".git")
return setTemplates(desc, u, "github")
} else {
return fmt.Errorf("unknown git hosting site %q", u)
}
} | [
"func",
"SetTemplatesFromOrigin",
"(",
"desc",
"*",
"zoekt",
".",
"Repository",
",",
"u",
"*",
"url",
".",
"URL",
")",
"error",
"{",
"desc",
".",
"Name",
"=",
"filepath",
".",
"Join",
"(",
"u",
".",
"Host",
",",
"strings",
".",
"TrimSuffix",
"(",
"u",
".",
"Path",
",",
"\"",
"\"",
")",
")",
"\n\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"u",
".",
"Host",
",",
"\"",
"\"",
")",
"{",
"return",
"setTemplates",
"(",
"desc",
",",
"u",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"u",
".",
"Host",
"==",
"\"",
"\"",
"{",
"u",
".",
"Path",
"=",
"strings",
".",
"TrimSuffix",
"(",
"u",
".",
"Path",
",",
"\"",
"\"",
")",
"\n",
"return",
"setTemplates",
"(",
"desc",
",",
"u",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"u",
")",
"\n",
"}",
"\n",
"}"
] | // SetTemplates fills in templates based on the origin URL. | [
"SetTemplates",
"fills",
"in",
"templates",
"based",
"on",
"the",
"origin",
"URL",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/index.go#L273-L284 |
150,345 | google/zoekt | matchtree.go | prepare | func (t *bruteForceMatchTree) prepare(doc uint32) {
t.docID = doc
t.firstDone = true
} | go | func (t *bruteForceMatchTree) prepare(doc uint32) {
t.docID = doc
t.firstDone = true
} | [
"func",
"(",
"t",
"*",
"bruteForceMatchTree",
")",
"prepare",
"(",
"doc",
"uint32",
")",
"{",
"t",
".",
"docID",
"=",
"doc",
"\n",
"t",
".",
"firstDone",
"=",
"true",
"\n",
"}"
] | // all prepare methods | [
"all",
"prepare",
"methods"
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/matchtree.go#L146-L149 |
150,346 | google/zoekt | ctags/parse.go | Parse | func Parse(in string) (*Entry, error) {
fields := strings.Split(in, "\t")
e := Entry{}
if len(fields) < 3 {
return nil, fmt.Errorf("too few fields: %q", in)
}
e.Sym = fields[0]
e.Path = fields[1]
lstr := fields[2]
if len(lstr) < 2 {
return nil, fmt.Errorf("got %q for linenum field", lstr)
}
l, err := strconv.ParseInt(lstr[:len(lstr)-2], 10, 64)
if err != nil {
return nil, err
}
e.Line = int(l)
e.Kind = fields[3]
field:
for _, f := range fields[3:] {
if string(f) == "file:" {
e.FileLimited = true
}
for _, p := range []string{"class", "enum"} {
if strings.HasPrefix(f, p+":") {
e.Parent = strings.TrimPrefix(f, p+":")
e.ParentType = p
continue field
}
}
}
return &e, nil
} | go | func Parse(in string) (*Entry, error) {
fields := strings.Split(in, "\t")
e := Entry{}
if len(fields) < 3 {
return nil, fmt.Errorf("too few fields: %q", in)
}
e.Sym = fields[0]
e.Path = fields[1]
lstr := fields[2]
if len(lstr) < 2 {
return nil, fmt.Errorf("got %q for linenum field", lstr)
}
l, err := strconv.ParseInt(lstr[:len(lstr)-2], 10, 64)
if err != nil {
return nil, err
}
e.Line = int(l)
e.Kind = fields[3]
field:
for _, f := range fields[3:] {
if string(f) == "file:" {
e.FileLimited = true
}
for _, p := range []string{"class", "enum"} {
if strings.HasPrefix(f, p+":") {
e.Parent = strings.TrimPrefix(f, p+":")
e.ParentType = p
continue field
}
}
}
return &e, nil
} | [
"func",
"Parse",
"(",
"in",
"string",
")",
"(",
"*",
"Entry",
",",
"error",
")",
"{",
"fields",
":=",
"strings",
".",
"Split",
"(",
"in",
",",
"\"",
"\\t",
"\"",
")",
"\n",
"e",
":=",
"Entry",
"{",
"}",
"\n\n",
"if",
"len",
"(",
"fields",
")",
"<",
"3",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"in",
")",
"\n",
"}",
"\n\n",
"e",
".",
"Sym",
"=",
"fields",
"[",
"0",
"]",
"\n",
"e",
".",
"Path",
"=",
"fields",
"[",
"1",
"]",
"\n\n",
"lstr",
":=",
"fields",
"[",
"2",
"]",
"\n",
"if",
"len",
"(",
"lstr",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"lstr",
")",
"\n",
"}",
"\n\n",
"l",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"lstr",
"[",
":",
"len",
"(",
"lstr",
")",
"-",
"2",
"]",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"e",
".",
"Line",
"=",
"int",
"(",
"l",
")",
"\n",
"e",
".",
"Kind",
"=",
"fields",
"[",
"3",
"]",
"\n\n",
"field",
":",
"for",
"_",
",",
"f",
":=",
"range",
"fields",
"[",
"3",
":",
"]",
"{",
"if",
"string",
"(",
"f",
")",
"==",
"\"",
"\"",
"{",
"e",
".",
"FileLimited",
"=",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"f",
",",
"p",
"+",
"\"",
"\"",
")",
"{",
"e",
".",
"Parent",
"=",
"strings",
".",
"TrimPrefix",
"(",
"f",
",",
"p",
"+",
"\"",
"\"",
")",
"\n",
"e",
".",
"ParentType",
"=",
"p",
"\n",
"continue",
"field",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"e",
",",
"nil",
"\n",
"}"
] | // Parse parses a single line of exuberant "ctags -n" output. | [
"Parse",
"parses",
"a",
"single",
"line",
"of",
"exuberant",
"ctags",
"-",
"n",
"output",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/ctags/parse.go#L36-L73 |
150,347 | google/zoekt | query/query.go | Map | func Map(q Q, f func(q Q) Q) Q {
switch s := q.(type) {
case *And:
q = &And{Children: mapQueryList(s.Children, f)}
case *Or:
q = &Or{Children: mapQueryList(s.Children, f)}
case *Not:
q = &Not{Child: Map(s.Child, f)}
}
return f(q)
} | go | func Map(q Q, f func(q Q) Q) Q {
switch s := q.(type) {
case *And:
q = &And{Children: mapQueryList(s.Children, f)}
case *Or:
q = &Or{Children: mapQueryList(s.Children, f)}
case *Not:
q = &Not{Child: Map(s.Child, f)}
}
return f(q)
} | [
"func",
"Map",
"(",
"q",
"Q",
",",
"f",
"func",
"(",
"q",
"Q",
")",
"Q",
")",
"Q",
"{",
"switch",
"s",
":=",
"q",
".",
"(",
"type",
")",
"{",
"case",
"*",
"And",
":",
"q",
"=",
"&",
"And",
"{",
"Children",
":",
"mapQueryList",
"(",
"s",
".",
"Children",
",",
"f",
")",
"}",
"\n",
"case",
"*",
"Or",
":",
"q",
"=",
"&",
"Or",
"{",
"Children",
":",
"mapQueryList",
"(",
"s",
".",
"Children",
",",
"f",
")",
"}",
"\n",
"case",
"*",
"Not",
":",
"q",
"=",
"&",
"Not",
"{",
"Child",
":",
"Map",
"(",
"s",
".",
"Child",
",",
"f",
")",
"}",
"\n",
"}",
"\n",
"return",
"f",
"(",
"q",
")",
"\n",
"}"
] | // Map runs f over the q. | [
"Map",
"runs",
"f",
"over",
"the",
"q",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/query.go#L346-L356 |
150,348 | google/zoekt | query/query.go | VisitAtoms | func VisitAtoms(q Q, v func(q Q)) {
Map(q, func(iQ Q) Q {
switch iQ.(type) {
case *And:
case *Or:
case *Not:
default:
v(iQ)
}
return iQ
})
} | go | func VisitAtoms(q Q, v func(q Q)) {
Map(q, func(iQ Q) Q {
switch iQ.(type) {
case *And:
case *Or:
case *Not:
default:
v(iQ)
}
return iQ
})
} | [
"func",
"VisitAtoms",
"(",
"q",
"Q",
",",
"v",
"func",
"(",
"q",
"Q",
")",
")",
"{",
"Map",
"(",
"q",
",",
"func",
"(",
"iQ",
"Q",
")",
"Q",
"{",
"switch",
"iQ",
".",
"(",
"type",
")",
"{",
"case",
"*",
"And",
":",
"case",
"*",
"Or",
":",
"case",
"*",
"Not",
":",
"default",
":",
"v",
"(",
"iQ",
")",
"\n",
"}",
"\n",
"return",
"iQ",
"\n",
"}",
")",
"\n",
"}"
] | // VisitAtoms runs `v` on all atom queries within `q`. | [
"VisitAtoms",
"runs",
"v",
"on",
"all",
"atom",
"queries",
"within",
"q",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/query.go#L383-L394 |
150,349 | google/zoekt | indexbuilder.go | ContentSize | func (b *IndexBuilder) ContentSize() uint32 {
// Add the name too so we don't skip building index if we have
// lots of empty files.
return b.contentPostings.endByte + b.namePostings.endByte
} | go | func (b *IndexBuilder) ContentSize() uint32 {
// Add the name too so we don't skip building index if we have
// lots of empty files.
return b.contentPostings.endByte + b.namePostings.endByte
} | [
"func",
"(",
"b",
"*",
"IndexBuilder",
")",
"ContentSize",
"(",
")",
"uint32",
"{",
"// Add the name too so we don't skip building index if we have",
"// lots of empty files.",
"return",
"b",
".",
"contentPostings",
".",
"endByte",
"+",
"b",
".",
"namePostings",
".",
"endByte",
"\n",
"}"
] | // ContentSize returns the number of content bytes so far ingested. | [
"ContentSize",
"returns",
"the",
"number",
"of",
"content",
"bytes",
"so",
"far",
"ingested",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/indexbuilder.go#L186-L190 |
150,350 | google/zoekt | indexbuilder.go | NewIndexBuilder | func NewIndexBuilder(r *Repository) (*IndexBuilder, error) {
b := &IndexBuilder{
contentPostings: newPostingsBuilder(),
namePostings: newPostingsBuilder(),
languageMap: map[string]byte{},
}
if r == nil {
r = &Repository{}
}
if err := b.setRepository(r); err != nil {
return nil, err
}
return b, nil
} | go | func NewIndexBuilder(r *Repository) (*IndexBuilder, error) {
b := &IndexBuilder{
contentPostings: newPostingsBuilder(),
namePostings: newPostingsBuilder(),
languageMap: map[string]byte{},
}
if r == nil {
r = &Repository{}
}
if err := b.setRepository(r); err != nil {
return nil, err
}
return b, nil
} | [
"func",
"NewIndexBuilder",
"(",
"r",
"*",
"Repository",
")",
"(",
"*",
"IndexBuilder",
",",
"error",
")",
"{",
"b",
":=",
"&",
"IndexBuilder",
"{",
"contentPostings",
":",
"newPostingsBuilder",
"(",
")",
",",
"namePostings",
":",
"newPostingsBuilder",
"(",
")",
",",
"languageMap",
":",
"map",
"[",
"string",
"]",
"byte",
"{",
"}",
",",
"}",
"\n\n",
"if",
"r",
"==",
"nil",
"{",
"r",
"=",
"&",
"Repository",
"{",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"b",
".",
"setRepository",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}"
] | // NewIndexBuilder creates a fresh IndexBuilder. The passed in
// Repository contains repo metadata, and may be set to nil. | [
"NewIndexBuilder",
"creates",
"a",
"fresh",
"IndexBuilder",
".",
"The",
"passed",
"in",
"Repository",
"contains",
"repo",
"metadata",
"and",
"may",
"be",
"set",
"to",
"nil",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/indexbuilder.go#L194-L208 |
150,351 | google/zoekt | indexbuilder.go | AddFile | func (b *IndexBuilder) AddFile(name string, content []byte) error {
return b.Add(Document{Name: name, Content: content})
} | go | func (b *IndexBuilder) AddFile(name string, content []byte) error {
return b.Add(Document{Name: name, Content: content})
} | [
"func",
"(",
"b",
"*",
"IndexBuilder",
")",
"AddFile",
"(",
"name",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"b",
".",
"Add",
"(",
"Document",
"{",
"Name",
":",
"name",
",",
"Content",
":",
"content",
"}",
")",
"\n",
"}"
] | // AddFile is a convenience wrapper for Add | [
"AddFile",
"is",
"a",
"convenience",
"wrapper",
"for",
"Add"
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/indexbuilder.go#L271-L273 |
150,352 | google/zoekt | indexbuilder.go | CheckText | func CheckText(content []byte) error {
if len(content) == 0 {
return nil
}
if len(content) < ngramSize {
return fmt.Errorf("file size smaller than %d", ngramSize)
}
trigrams := map[ngram]struct{}{}
var cur [3]rune
byteCount := 0
for len(content) > 0 {
if content[0] == 0 {
return fmt.Errorf("binary data at byte offset %d", byteCount)
}
r, sz := utf8.DecodeRune(content)
content = content[sz:]
byteCount += sz
cur[0], cur[1], cur[2] = cur[1], cur[2], r
if cur[0] == 0 {
// start of file.
continue
}
trigrams[runesToNGram(cur)] = struct{}{}
if len(trigrams) > maxTrigramCount {
// probably not text.
return fmt.Errorf("number of trigrams exceeds %d", maxTrigramCount)
}
}
return nil
} | go | func CheckText(content []byte) error {
if len(content) == 0 {
return nil
}
if len(content) < ngramSize {
return fmt.Errorf("file size smaller than %d", ngramSize)
}
trigrams := map[ngram]struct{}{}
var cur [3]rune
byteCount := 0
for len(content) > 0 {
if content[0] == 0 {
return fmt.Errorf("binary data at byte offset %d", byteCount)
}
r, sz := utf8.DecodeRune(content)
content = content[sz:]
byteCount += sz
cur[0], cur[1], cur[2] = cur[1], cur[2], r
if cur[0] == 0 {
// start of file.
continue
}
trigrams[runesToNGram(cur)] = struct{}{}
if len(trigrams) > maxTrigramCount {
// probably not text.
return fmt.Errorf("number of trigrams exceeds %d", maxTrigramCount)
}
}
return nil
} | [
"func",
"CheckText",
"(",
"content",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"content",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"content",
")",
"<",
"ngramSize",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ngramSize",
")",
"\n",
"}",
"\n\n",
"trigrams",
":=",
"map",
"[",
"ngram",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"var",
"cur",
"[",
"3",
"]",
"rune",
"\n",
"byteCount",
":=",
"0",
"\n",
"for",
"len",
"(",
"content",
")",
">",
"0",
"{",
"if",
"content",
"[",
"0",
"]",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"byteCount",
")",
"\n",
"}",
"\n\n",
"r",
",",
"sz",
":=",
"utf8",
".",
"DecodeRune",
"(",
"content",
")",
"\n",
"content",
"=",
"content",
"[",
"sz",
":",
"]",
"\n",
"byteCount",
"+=",
"sz",
"\n\n",
"cur",
"[",
"0",
"]",
",",
"cur",
"[",
"1",
"]",
",",
"cur",
"[",
"2",
"]",
"=",
"cur",
"[",
"1",
"]",
",",
"cur",
"[",
"2",
"]",
",",
"r",
"\n",
"if",
"cur",
"[",
"0",
"]",
"==",
"0",
"{",
"// start of file.",
"continue",
"\n",
"}",
"\n\n",
"trigrams",
"[",
"runesToNGram",
"(",
"cur",
")",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"if",
"len",
"(",
"trigrams",
")",
">",
"maxTrigramCount",
"{",
"// probably not text.",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"maxTrigramCount",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CheckText returns a reason why the given contents are probably not source texts. | [
"CheckText",
"returns",
"a",
"reason",
"why",
"the",
"given",
"contents",
"are",
"probably",
"not",
"source",
"texts",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/indexbuilder.go#L278-L313 |
150,353 | google/zoekt | read.go | ReadMetadata | func ReadMetadata(inf IndexFile) (*Repository, *IndexMetadata, error) {
rd := &reader{r: inf}
var toc indexTOC
if err := rd.readTOC(&toc); err != nil {
return nil, nil, err
}
var md IndexMetadata
if err := rd.readJSON(&md, &toc.metaData); err != nil {
return nil, nil, err
}
var repo Repository
if err := rd.readJSON(&repo, &toc.repoMetaData); err != nil {
return nil, nil, err
}
return &repo, &md, nil
} | go | func ReadMetadata(inf IndexFile) (*Repository, *IndexMetadata, error) {
rd := &reader{r: inf}
var toc indexTOC
if err := rd.readTOC(&toc); err != nil {
return nil, nil, err
}
var md IndexMetadata
if err := rd.readJSON(&md, &toc.metaData); err != nil {
return nil, nil, err
}
var repo Repository
if err := rd.readJSON(&repo, &toc.repoMetaData); err != nil {
return nil, nil, err
}
return &repo, &md, nil
} | [
"func",
"ReadMetadata",
"(",
"inf",
"IndexFile",
")",
"(",
"*",
"Repository",
",",
"*",
"IndexMetadata",
",",
"error",
")",
"{",
"rd",
":=",
"&",
"reader",
"{",
"r",
":",
"inf",
"}",
"\n",
"var",
"toc",
"indexTOC",
"\n",
"if",
"err",
":=",
"rd",
".",
"readTOC",
"(",
"&",
"toc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"md",
"IndexMetadata",
"\n",
"if",
"err",
":=",
"rd",
".",
"readJSON",
"(",
"&",
"md",
",",
"&",
"toc",
".",
"metaData",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"repo",
"Repository",
"\n",
"if",
"err",
":=",
"rd",
".",
"readJSON",
"(",
"&",
"repo",
",",
"&",
"toc",
".",
"repoMetaData",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"repo",
",",
"&",
"md",
",",
"nil",
"\n",
"}"
] | // ReadMetadata returns the metadata of index shard without reading
// the index data. The IndexFile is not closed. | [
"ReadMetadata",
"returns",
"the",
"metadata",
"of",
"index",
"shard",
"without",
"reading",
"the",
"index",
"data",
".",
"The",
"IndexFile",
"is",
"not",
"closed",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/read.go#L364-L382 |
150,354 | google/zoekt | gitindex/tree.go | subURL | func (w *repoWalker) subURL(relURL string) (*url.URL, error) {
if w.repoURL == nil {
return nil, fmt.Errorf("no URL for base repo")
}
if strings.HasPrefix(relURL, "../") {
u := *w.repoURL
u.Path = path.Join(u.Path, relURL)
return &u, nil
}
return url.Parse(relURL)
} | go | func (w *repoWalker) subURL(relURL string) (*url.URL, error) {
if w.repoURL == nil {
return nil, fmt.Errorf("no URL for base repo")
}
if strings.HasPrefix(relURL, "../") {
u := *w.repoURL
u.Path = path.Join(u.Path, relURL)
return &u, nil
}
return url.Parse(relURL)
} | [
"func",
"(",
"w",
"*",
"repoWalker",
")",
"subURL",
"(",
"relURL",
"string",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"if",
"w",
".",
"repoURL",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"relURL",
",",
"\"",
"\"",
")",
"{",
"u",
":=",
"*",
"w",
".",
"repoURL",
"\n",
"u",
".",
"Path",
"=",
"path",
".",
"Join",
"(",
"u",
".",
"Path",
",",
"relURL",
")",
"\n",
"return",
"&",
"u",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"url",
".",
"Parse",
"(",
"relURL",
")",
"\n",
"}"
] | // subURL returns the URL for a submodule. | [
"subURL",
"returns",
"the",
"URL",
"for",
"a",
"submodule",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/tree.go#L52-L63 |
150,355 | google/zoekt | gitindex/tree.go | newRepoWalker | func newRepoWalker(r *git.Repository, repoURL string, repoCache *RepoCache) *repoWalker {
u, _ := url.Parse(repoURL)
return &repoWalker{
repo: r,
repoURL: u,
tree: map[fileKey]BlobLocation{},
repoCache: repoCache,
subRepoVersions: map[string]plumbing.Hash{},
ignoreMissingSubmodules: true,
}
} | go | func newRepoWalker(r *git.Repository, repoURL string, repoCache *RepoCache) *repoWalker {
u, _ := url.Parse(repoURL)
return &repoWalker{
repo: r,
repoURL: u,
tree: map[fileKey]BlobLocation{},
repoCache: repoCache,
subRepoVersions: map[string]plumbing.Hash{},
ignoreMissingSubmodules: true,
}
} | [
"func",
"newRepoWalker",
"(",
"r",
"*",
"git",
".",
"Repository",
",",
"repoURL",
"string",
",",
"repoCache",
"*",
"RepoCache",
")",
"*",
"repoWalker",
"{",
"u",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"repoURL",
")",
"\n",
"return",
"&",
"repoWalker",
"{",
"repo",
":",
"r",
",",
"repoURL",
":",
"u",
",",
"tree",
":",
"map",
"[",
"fileKey",
"]",
"BlobLocation",
"{",
"}",
",",
"repoCache",
":",
"repoCache",
",",
"subRepoVersions",
":",
"map",
"[",
"string",
"]",
"plumbing",
".",
"Hash",
"{",
"}",
",",
"ignoreMissingSubmodules",
":",
"true",
",",
"}",
"\n",
"}"
] | // newRepoWalker creates a new repoWalker. | [
"newRepoWalker",
"creates",
"a",
"new",
"repoWalker",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/tree.go#L66-L76 |
150,356 | google/zoekt | gitindex/tree.go | parseModuleMap | func (rw *repoWalker) parseModuleMap(t *object.Tree) error {
modEntry, _ := t.File(".gitmodules")
if modEntry != nil {
c, err := blobContents(&modEntry.Blob)
if err != nil {
return err
}
mods, err := ParseGitModules(c)
if err != nil {
return err
}
rw.submodules = map[string]*SubmoduleEntry{}
for _, entry := range mods {
rw.submodules[entry.Path] = entry
}
}
return nil
} | go | func (rw *repoWalker) parseModuleMap(t *object.Tree) error {
modEntry, _ := t.File(".gitmodules")
if modEntry != nil {
c, err := blobContents(&modEntry.Blob)
if err != nil {
return err
}
mods, err := ParseGitModules(c)
if err != nil {
return err
}
rw.submodules = map[string]*SubmoduleEntry{}
for _, entry := range mods {
rw.submodules[entry.Path] = entry
}
}
return nil
} | [
"func",
"(",
"rw",
"*",
"repoWalker",
")",
"parseModuleMap",
"(",
"t",
"*",
"object",
".",
"Tree",
")",
"error",
"{",
"modEntry",
",",
"_",
":=",
"t",
".",
"File",
"(",
"\"",
"\"",
")",
"\n",
"if",
"modEntry",
"!=",
"nil",
"{",
"c",
",",
"err",
":=",
"blobContents",
"(",
"&",
"modEntry",
".",
"Blob",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"mods",
",",
"err",
":=",
"ParseGitModules",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"rw",
".",
"submodules",
"=",
"map",
"[",
"string",
"]",
"*",
"SubmoduleEntry",
"{",
"}",
"\n",
"for",
"_",
",",
"entry",
":=",
"range",
"mods",
"{",
"rw",
".",
"submodules",
"[",
"entry",
".",
"Path",
"]",
"=",
"entry",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // parseModuleMap initializes rw.submodules. | [
"parseModuleMap",
"initializes",
"rw",
".",
"submodules",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/tree.go#L79-L96 |
150,357 | google/zoekt | gitindex/tree.go | TreeToFiles | func TreeToFiles(r *git.Repository, t *object.Tree,
repoURL string, repoCache *RepoCache) (map[fileKey]BlobLocation, map[string]plumbing.Hash, error) {
rw := newRepoWalker(r, repoURL, repoCache)
if err := rw.parseModuleMap(t); err != nil {
return nil, nil, err
}
tw := object.NewTreeWalker(t, true, make(map[plumbing.Hash]bool))
defer tw.Close()
for {
name, entry, err := tw.Next()
if err == io.EOF {
break
}
if err := rw.handleEntry(name, &entry); err != nil {
return nil, nil, err
}
}
return rw.tree, rw.subRepoVersions, nil
} | go | func TreeToFiles(r *git.Repository, t *object.Tree,
repoURL string, repoCache *RepoCache) (map[fileKey]BlobLocation, map[string]plumbing.Hash, error) {
rw := newRepoWalker(r, repoURL, repoCache)
if err := rw.parseModuleMap(t); err != nil {
return nil, nil, err
}
tw := object.NewTreeWalker(t, true, make(map[plumbing.Hash]bool))
defer tw.Close()
for {
name, entry, err := tw.Next()
if err == io.EOF {
break
}
if err := rw.handleEntry(name, &entry); err != nil {
return nil, nil, err
}
}
return rw.tree, rw.subRepoVersions, nil
} | [
"func",
"TreeToFiles",
"(",
"r",
"*",
"git",
".",
"Repository",
",",
"t",
"*",
"object",
".",
"Tree",
",",
"repoURL",
"string",
",",
"repoCache",
"*",
"RepoCache",
")",
"(",
"map",
"[",
"fileKey",
"]",
"BlobLocation",
",",
"map",
"[",
"string",
"]",
"plumbing",
".",
"Hash",
",",
"error",
")",
"{",
"rw",
":=",
"newRepoWalker",
"(",
"r",
",",
"repoURL",
",",
"repoCache",
")",
"\n\n",
"if",
"err",
":=",
"rw",
".",
"parseModuleMap",
"(",
"t",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tw",
":=",
"object",
".",
"NewTreeWalker",
"(",
"t",
",",
"true",
",",
"make",
"(",
"map",
"[",
"plumbing",
".",
"Hash",
"]",
"bool",
")",
")",
"\n",
"defer",
"tw",
".",
"Close",
"(",
")",
"\n",
"for",
"{",
"name",
",",
"entry",
",",
"err",
":=",
"tw",
".",
"Next",
"(",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n",
"if",
"err",
":=",
"rw",
".",
"handleEntry",
"(",
"name",
",",
"&",
"entry",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"rw",
".",
"tree",
",",
"rw",
".",
"subRepoVersions",
",",
"nil",
"\n",
"}"
] | // TreeToFiles fetches the blob SHA1s for a tree. If repoCache is
// non-nil, recurse into submodules. In addition, it returns a mapping
// that indicates in which repo each SHA1 can be found. | [
"TreeToFiles",
"fetches",
"the",
"blob",
"SHA1s",
"for",
"a",
"tree",
".",
"If",
"repoCache",
"is",
"non",
"-",
"nil",
"recurse",
"into",
"submodules",
".",
"In",
"addition",
"it",
"returns",
"a",
"mapping",
"that",
"indicates",
"in",
"which",
"repo",
"each",
"SHA1",
"can",
"be",
"found",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/gitindex/tree.go#L101-L121 |
150,358 | google/zoekt | cmd/zoekt-archive-index/main.go | stripComponents | func stripComponents(path string, count int) string {
for i := 0; path != "" && i < count; i++ {
i := strings.Index(path, "/")
if i < 0 {
return ""
}
path = path[i+1:]
}
return path
} | go | func stripComponents(path string, count int) string {
for i := 0; path != "" && i < count; i++ {
i := strings.Index(path, "/")
if i < 0 {
return ""
}
path = path[i+1:]
}
return path
} | [
"func",
"stripComponents",
"(",
"path",
"string",
",",
"count",
"int",
")",
"string",
"{",
"for",
"i",
":=",
"0",
";",
"path",
"!=",
"\"",
"\"",
"&&",
"i",
"<",
"count",
";",
"i",
"++",
"{",
"i",
":=",
"strings",
".",
"Index",
"(",
"path",
",",
"\"",
"\"",
")",
"\n",
"if",
"i",
"<",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"path",
"=",
"path",
"[",
"i",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"return",
"path",
"\n",
"}"
] | // stripComponents removes the specified number of leading path
// elements. Pathnames with fewer elements will return the empty string. | [
"stripComponents",
"removes",
"the",
"specified",
"number",
"of",
"leading",
"path",
"elements",
".",
"Pathnames",
"with",
"fewer",
"elements",
"will",
"return",
"the",
"empty",
"string",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-archive-index/main.go#L29-L38 |
150,359 | google/zoekt | cmd/zoekt-archive-index/archive.go | openArchive | func openArchive(u string) (Archive, error) {
var (
r io.Reader
closer io.Closer
)
if strings.HasPrefix(u, "https://") || strings.HasPrefix(u, "http://") {
resp, err := http.Get(u)
if err != nil {
return nil, err
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
b, err := ioutil.ReadAll(io.LimitReader(resp.Body, 1024))
resp.Body.Close()
if err != nil {
return nil, err
}
return nil, &url.Error{
Op: "Get",
URL: u,
Err: fmt.Errorf("%s: %s", resp.Status, string(b)),
}
}
closer = resp.Body
r = resp.Body
if resp.Header.Get("Content-Type") == "application/x-gzip" {
r, err = gzip.NewReader(r)
if err != nil {
resp.Body.Close()
return nil, err
}
}
} else if u == "-" {
r = os.Stdin
} else {
f, err := os.Open(u)
if err != nil {
return nil, err
}
closer = f
r = f
}
return &tarArchive{
tr: tar.NewReader(r),
closer: closer,
}, nil
} | go | func openArchive(u string) (Archive, error) {
var (
r io.Reader
closer io.Closer
)
if strings.HasPrefix(u, "https://") || strings.HasPrefix(u, "http://") {
resp, err := http.Get(u)
if err != nil {
return nil, err
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
b, err := ioutil.ReadAll(io.LimitReader(resp.Body, 1024))
resp.Body.Close()
if err != nil {
return nil, err
}
return nil, &url.Error{
Op: "Get",
URL: u,
Err: fmt.Errorf("%s: %s", resp.Status, string(b)),
}
}
closer = resp.Body
r = resp.Body
if resp.Header.Get("Content-Type") == "application/x-gzip" {
r, err = gzip.NewReader(r)
if err != nil {
resp.Body.Close()
return nil, err
}
}
} else if u == "-" {
r = os.Stdin
} else {
f, err := os.Open(u)
if err != nil {
return nil, err
}
closer = f
r = f
}
return &tarArchive{
tr: tar.NewReader(r),
closer: closer,
}, nil
} | [
"func",
"openArchive",
"(",
"u",
"string",
")",
"(",
"Archive",
",",
"error",
")",
"{",
"var",
"(",
"r",
"io",
".",
"Reader",
"\n",
"closer",
"io",
".",
"Closer",
"\n",
")",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"u",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"HasPrefix",
"(",
"u",
",",
"\"",
"\"",
")",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"resp",
".",
"StatusCode",
"<",
"200",
"||",
"resp",
".",
"StatusCode",
">=",
"300",
"{",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"io",
".",
"LimitReader",
"(",
"resp",
".",
"Body",
",",
"1024",
")",
")",
"\n",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"&",
"url",
".",
"Error",
"{",
"Op",
":",
"\"",
"\"",
",",
"URL",
":",
"u",
",",
"Err",
":",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Status",
",",
"string",
"(",
"b",
")",
")",
",",
"}",
"\n",
"}",
"\n",
"closer",
"=",
"resp",
".",
"Body",
"\n",
"r",
"=",
"resp",
".",
"Body",
"\n",
"if",
"resp",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"{",
"r",
",",
"err",
"=",
"gzip",
".",
"NewReader",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"u",
"==",
"\"",
"\"",
"{",
"r",
"=",
"os",
".",
"Stdin",
"\n",
"}",
"else",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"closer",
"=",
"f",
"\n",
"r",
"=",
"f",
"\n",
"}",
"\n\n",
"return",
"&",
"tarArchive",
"{",
"tr",
":",
"tar",
".",
"NewReader",
"(",
"r",
")",
",",
"closer",
":",
"closer",
",",
"}",
",",
"nil",
"\n",
"}"
] | // openArchive opens the tar at the URL or filepath u. Also supported is tgz
// files over http. | [
"openArchive",
"opens",
"the",
"tar",
"at",
"the",
"URL",
"or",
"filepath",
"u",
".",
"Also",
"supported",
"is",
"tgz",
"files",
"over",
"http",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-archive-index/archive.go#L60-L107 |
150,360 | google/zoekt | cmd/zoekt-repo-index/main.go | iterateManifest | func iterateManifest(mf *manifest.Manifest,
baseURL url.URL, revPrefix string,
cache *gitindex.RepoCache) (map[fileKey]gitindex.BlobLocation, map[string]plumbing.Hash, error) {
allFiles := map[fileKey]gitindex.BlobLocation{}
allVersions := map[string]plumbing.Hash{}
for _, p := range mf.Project {
rev := mf.ProjectRevision(&p)
projURL := baseURL
projURL.Path = path.Join(projURL.Path, p.Name)
topRepo, err := cache.Open(&projURL)
if err != nil {
return nil, nil, err
}
ref, err := topRepo.Reference(plumbing.ReferenceName(revPrefix+rev), true)
if err != nil {
return nil, nil, err
}
commit, err := topRepo.CommitObject(ref.Hash())
if err != nil {
return nil, nil, err
}
if err != nil {
return nil, nil, err
}
allVersions[p.GetPath()] = commit.Hash
tree, err := commit.Tree()
if err != nil {
return nil, nil, err
}
files, versions, err := gitindex.TreeToFiles(topRepo, tree, projURL.String(), cache)
if err != nil {
return nil, nil, err
}
for key, repo := range files {
allFiles[fileKey{
SubRepoPath: filepath.Join(p.GetPath(), key.SubRepoPath),
Path: key.Path,
ID: key.ID,
}] = repo
}
for path, version := range versions {
allVersions[filepath.Join(p.GetPath(), path)] = version
}
}
return allFiles, allVersions, nil
} | go | func iterateManifest(mf *manifest.Manifest,
baseURL url.URL, revPrefix string,
cache *gitindex.RepoCache) (map[fileKey]gitindex.BlobLocation, map[string]plumbing.Hash, error) {
allFiles := map[fileKey]gitindex.BlobLocation{}
allVersions := map[string]plumbing.Hash{}
for _, p := range mf.Project {
rev := mf.ProjectRevision(&p)
projURL := baseURL
projURL.Path = path.Join(projURL.Path, p.Name)
topRepo, err := cache.Open(&projURL)
if err != nil {
return nil, nil, err
}
ref, err := topRepo.Reference(plumbing.ReferenceName(revPrefix+rev), true)
if err != nil {
return nil, nil, err
}
commit, err := topRepo.CommitObject(ref.Hash())
if err != nil {
return nil, nil, err
}
if err != nil {
return nil, nil, err
}
allVersions[p.GetPath()] = commit.Hash
tree, err := commit.Tree()
if err != nil {
return nil, nil, err
}
files, versions, err := gitindex.TreeToFiles(topRepo, tree, projURL.String(), cache)
if err != nil {
return nil, nil, err
}
for key, repo := range files {
allFiles[fileKey{
SubRepoPath: filepath.Join(p.GetPath(), key.SubRepoPath),
Path: key.Path,
ID: key.ID,
}] = repo
}
for path, version := range versions {
allVersions[filepath.Join(p.GetPath(), path)] = version
}
}
return allFiles, allVersions, nil
} | [
"func",
"iterateManifest",
"(",
"mf",
"*",
"manifest",
".",
"Manifest",
",",
"baseURL",
"url",
".",
"URL",
",",
"revPrefix",
"string",
",",
"cache",
"*",
"gitindex",
".",
"RepoCache",
")",
"(",
"map",
"[",
"fileKey",
"]",
"gitindex",
".",
"BlobLocation",
",",
"map",
"[",
"string",
"]",
"plumbing",
".",
"Hash",
",",
"error",
")",
"{",
"allFiles",
":=",
"map",
"[",
"fileKey",
"]",
"gitindex",
".",
"BlobLocation",
"{",
"}",
"\n",
"allVersions",
":=",
"map",
"[",
"string",
"]",
"plumbing",
".",
"Hash",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"mf",
".",
"Project",
"{",
"rev",
":=",
"mf",
".",
"ProjectRevision",
"(",
"&",
"p",
")",
"\n\n",
"projURL",
":=",
"baseURL",
"\n",
"projURL",
".",
"Path",
"=",
"path",
".",
"Join",
"(",
"projURL",
".",
"Path",
",",
"p",
".",
"Name",
")",
"\n\n",
"topRepo",
",",
"err",
":=",
"cache",
".",
"Open",
"(",
"&",
"projURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ref",
",",
"err",
":=",
"topRepo",
".",
"Reference",
"(",
"plumbing",
".",
"ReferenceName",
"(",
"revPrefix",
"+",
"rev",
")",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"commit",
",",
"err",
":=",
"topRepo",
".",
"CommitObject",
"(",
"ref",
".",
"Hash",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"allVersions",
"[",
"p",
".",
"GetPath",
"(",
")",
"]",
"=",
"commit",
".",
"Hash",
"\n\n",
"tree",
",",
"err",
":=",
"commit",
".",
"Tree",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"files",
",",
"versions",
",",
"err",
":=",
"gitindex",
".",
"TreeToFiles",
"(",
"topRepo",
",",
"tree",
",",
"projURL",
".",
"String",
"(",
")",
",",
"cache",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"key",
",",
"repo",
":=",
"range",
"files",
"{",
"allFiles",
"[",
"fileKey",
"{",
"SubRepoPath",
":",
"filepath",
".",
"Join",
"(",
"p",
".",
"GetPath",
"(",
")",
",",
"key",
".",
"SubRepoPath",
")",
",",
"Path",
":",
"key",
".",
"Path",
",",
"ID",
":",
"key",
".",
"ID",
",",
"}",
"]",
"=",
"repo",
"\n",
"}",
"\n\n",
"for",
"path",
",",
"version",
":=",
"range",
"versions",
"{",
"allVersions",
"[",
"filepath",
".",
"Join",
"(",
"p",
".",
"GetPath",
"(",
")",
",",
"path",
")",
"]",
"=",
"version",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"allFiles",
",",
"allVersions",
",",
"nil",
"\n",
"}"
] | // iterateManifest constructs a complete tree from the given Manifest. | [
"iterateManifest",
"constructs",
"a",
"complete",
"tree",
"from",
"the",
"given",
"Manifest",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-repo-index/main.go#L325-L380 |
150,361 | google/zoekt | ctags/json.go | NewParser | func NewParser(bin string) (Parser, error) {
if strings.Contains(bin, "universal-ctags") {
// todo: restart, parallelization.
proc, err := newProcess(bin)
if err != nil {
return nil, err
}
return &lockedParser{p: proc}, nil
}
log.Fatal("not implemented")
return nil, nil
} | go | func NewParser(bin string) (Parser, error) {
if strings.Contains(bin, "universal-ctags") {
// todo: restart, parallelization.
proc, err := newProcess(bin)
if err != nil {
return nil, err
}
return &lockedParser{p: proc}, nil
}
log.Fatal("not implemented")
return nil, nil
} | [
"func",
"NewParser",
"(",
"bin",
"string",
")",
"(",
"Parser",
",",
"error",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"bin",
",",
"\"",
"\"",
")",
"{",
"// todo: restart, parallelization.",
"proc",
",",
"err",
":=",
"newProcess",
"(",
"bin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"lockedParser",
"{",
"p",
":",
"proc",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"log",
".",
"Fatal",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // NewParser creates a parser that is implemented by the given
// universal-ctags binary. The parser is safe for concurrent use. | [
"NewParser",
"creates",
"a",
"parser",
"that",
"is",
"implemented",
"by",
"the",
"given",
"universal",
"-",
"ctags",
"binary",
".",
"The",
"parser",
"is",
"safe",
"for",
"concurrent",
"use",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/ctags/json.go#L207-L219 |
150,362 | google/zoekt | contentprovider.go | setDocument | func (p *contentProvider) setDocument(docID uint32) {
fileStart := p.id.boundaries[docID]
p.idx = docID
p.fileSize = p.id.boundaries[docID+1] - fileStart
p._nl = nil
p._sects = nil
p._data = nil
} | go | func (p *contentProvider) setDocument(docID uint32) {
fileStart := p.id.boundaries[docID]
p.idx = docID
p.fileSize = p.id.boundaries[docID+1] - fileStart
p._nl = nil
p._sects = nil
p._data = nil
} | [
"func",
"(",
"p",
"*",
"contentProvider",
")",
"setDocument",
"(",
"docID",
"uint32",
")",
"{",
"fileStart",
":=",
"p",
".",
"id",
".",
"boundaries",
"[",
"docID",
"]",
"\n\n",
"p",
".",
"idx",
"=",
"docID",
"\n",
"p",
".",
"fileSize",
"=",
"p",
".",
"id",
".",
"boundaries",
"[",
"docID",
"+",
"1",
"]",
"-",
"fileStart",
"\n\n",
"p",
".",
"_nl",
"=",
"nil",
"\n",
"p",
".",
"_sects",
"=",
"nil",
"\n",
"p",
".",
"_data",
"=",
"nil",
"\n",
"}"
] | // setDocument skips to the given document. | [
"setDocument",
"skips",
"to",
"the",
"given",
"document",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/contentprovider.go#L44-L53 |
150,363 | google/zoekt | query/regexp.go | RegexpToQuery | func RegexpToQuery(r *syntax.Regexp, minTextSize int) Q {
q := regexpToQueryRecursive(r, minTextSize)
q = Simplify(q)
return q
} | go | func RegexpToQuery(r *syntax.Regexp, minTextSize int) Q {
q := regexpToQueryRecursive(r, minTextSize)
q = Simplify(q)
return q
} | [
"func",
"RegexpToQuery",
"(",
"r",
"*",
"syntax",
".",
"Regexp",
",",
"minTextSize",
"int",
")",
"Q",
"{",
"q",
":=",
"regexpToQueryRecursive",
"(",
"r",
",",
"minTextSize",
")",
"\n",
"q",
"=",
"Simplify",
"(",
"q",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // RegexpToQuery tries to distill a substring search query that
// matches a superset of the regexp. | [
"RegexpToQuery",
"tries",
"to",
"distill",
"a",
"substring",
"search",
"query",
"that",
"matches",
"a",
"superset",
"of",
"the",
"regexp",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/query/regexp.go#L48-L52 |
150,364 | google/zoekt | cmd/zoekt-indexserver/main.go | periodicFetch | func periodicFetch(repoDir, indexDir string, opts *Options, pendingRepos chan<- string) {
t := time.NewTicker(opts.fetchInterval)
for {
repos, err := gitindex.FindGitRepos(repoDir)
if err != nil {
log.Println(err)
continue
}
if len(repos) == 0 {
log.Printf("no repos found under %s", repoDir)
}
// TODO: Randomize to make sure quota throttling hits everyone.
later := map[string]struct{}{}
for _, dir := range repos {
if ok := fetchGitRepo(dir); !ok {
later[dir] = struct{}{}
} else {
pendingRepos <- dir
}
}
for r := range later {
pendingRepos <- r
}
<-t.C
}
} | go | func periodicFetch(repoDir, indexDir string, opts *Options, pendingRepos chan<- string) {
t := time.NewTicker(opts.fetchInterval)
for {
repos, err := gitindex.FindGitRepos(repoDir)
if err != nil {
log.Println(err)
continue
}
if len(repos) == 0 {
log.Printf("no repos found under %s", repoDir)
}
// TODO: Randomize to make sure quota throttling hits everyone.
later := map[string]struct{}{}
for _, dir := range repos {
if ok := fetchGitRepo(dir); !ok {
later[dir] = struct{}{}
} else {
pendingRepos <- dir
}
}
for r := range later {
pendingRepos <- r
}
<-t.C
}
} | [
"func",
"periodicFetch",
"(",
"repoDir",
",",
"indexDir",
"string",
",",
"opts",
"*",
"Options",
",",
"pendingRepos",
"chan",
"<-",
"string",
")",
"{",
"t",
":=",
"time",
".",
"NewTicker",
"(",
"opts",
".",
"fetchInterval",
")",
"\n",
"for",
"{",
"repos",
",",
"err",
":=",
"gitindex",
".",
"FindGitRepos",
"(",
"repoDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"len",
"(",
"repos",
")",
"==",
"0",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"repoDir",
")",
"\n",
"}",
"\n\n",
"// TODO: Randomize to make sure quota throttling hits everyone.",
"later",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"dir",
":=",
"range",
"repos",
"{",
"if",
"ok",
":=",
"fetchGitRepo",
"(",
"dir",
")",
";",
"!",
"ok",
"{",
"later",
"[",
"dir",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"else",
"{",
"pendingRepos",
"<-",
"dir",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"r",
":=",
"range",
"later",
"{",
"pendingRepos",
"<-",
"r",
"\n",
"}",
"\n\n",
"<-",
"t",
".",
"C",
"\n",
"}",
"\n",
"}"
] | // periodicFetch runs git-fetch every once in a while. Results are
// posted on pendingRepos. | [
"periodicFetch",
"runs",
"git",
"-",
"fetch",
"every",
"once",
"in",
"a",
"while",
".",
"Results",
"are",
"posted",
"on",
"pendingRepos",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-indexserver/main.go#L95-L124 |
150,365 | google/zoekt | cmd/zoekt-indexserver/main.go | fetchGitRepo | func fetchGitRepo(dir string) bool {
cmd := exec.Command("git", "--git-dir", dir, "fetch", "origin")
outBuf := &bytes.Buffer{}
errBuf := &bytes.Buffer{}
// Prevent prompting
cmd.Stdin = &bytes.Buffer{}
cmd.Stderr = errBuf
cmd.Stdout = outBuf
if err := cmd.Run(); err != nil {
log.Printf("command %s failed: %v\nOUT: %s\nERR: %s",
cmd.Args, err, outBuf.String(), errBuf.String())
} else {
return len(outBuf.Bytes()) != 0
}
return false
} | go | func fetchGitRepo(dir string) bool {
cmd := exec.Command("git", "--git-dir", dir, "fetch", "origin")
outBuf := &bytes.Buffer{}
errBuf := &bytes.Buffer{}
// Prevent prompting
cmd.Stdin = &bytes.Buffer{}
cmd.Stderr = errBuf
cmd.Stdout = outBuf
if err := cmd.Run(); err != nil {
log.Printf("command %s failed: %v\nOUT: %s\nERR: %s",
cmd.Args, err, outBuf.String(), errBuf.String())
} else {
return len(outBuf.Bytes()) != 0
}
return false
} | [
"func",
"fetchGitRepo",
"(",
"dir",
"string",
")",
"bool",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"dir",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"outBuf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"errBuf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n\n",
"// Prevent prompting",
"cmd",
".",
"Stdin",
"=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"cmd",
".",
"Stderr",
"=",
"errBuf",
"\n",
"cmd",
".",
"Stdout",
"=",
"outBuf",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"cmd",
".",
"Args",
",",
"err",
",",
"outBuf",
".",
"String",
"(",
")",
",",
"errBuf",
".",
"String",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"return",
"len",
"(",
"outBuf",
".",
"Bytes",
"(",
")",
")",
"!=",
"0",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // fetchGitRepo runs git-fetch, and returns true if there was an
// update. | [
"fetchGitRepo",
"runs",
"git",
"-",
"fetch",
"and",
"returns",
"true",
"if",
"there",
"was",
"an",
"update",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-indexserver/main.go#L128-L144 |
150,366 | google/zoekt | cmd/zoekt-indexserver/main.go | indexPendingRepos | func indexPendingRepos(indexDir, repoDir string, opts *Options, repos <-chan string) {
for dir := range repos {
args := []string{
"-require_ctags",
fmt.Sprintf("-parallelism=%d", opts.cpuCount),
"-repo_cache", repoDir,
"-index", indexDir,
"-incremental",
}
args = append(args, opts.indexFlags...)
args = append(args, dir)
cmd := exec.Command("zoekt-git-index", args...)
loggedRun(cmd)
}
} | go | func indexPendingRepos(indexDir, repoDir string, opts *Options, repos <-chan string) {
for dir := range repos {
args := []string{
"-require_ctags",
fmt.Sprintf("-parallelism=%d", opts.cpuCount),
"-repo_cache", repoDir,
"-index", indexDir,
"-incremental",
}
args = append(args, opts.indexFlags...)
args = append(args, dir)
cmd := exec.Command("zoekt-git-index", args...)
loggedRun(cmd)
}
} | [
"func",
"indexPendingRepos",
"(",
"indexDir",
",",
"repoDir",
"string",
",",
"opts",
"*",
"Options",
",",
"repos",
"<-",
"chan",
"string",
")",
"{",
"for",
"dir",
":=",
"range",
"repos",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"opts",
".",
"cpuCount",
")",
",",
"\"",
"\"",
",",
"repoDir",
",",
"\"",
"\"",
",",
"indexDir",
",",
"\"",
"\"",
",",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"opts",
".",
"indexFlags",
"...",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"dir",
")",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"loggedRun",
"(",
"cmd",
")",
"\n",
"}",
"\n",
"}"
] | // indexPendingRepos consumes the directories on the repos channel and
// indexes them, sequentially. | [
"indexPendingRepos",
"consumes",
"the",
"directories",
"on",
"the",
"repos",
"channel",
"and",
"indexes",
"them",
"sequentially",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-indexserver/main.go#L148-L162 |
150,367 | google/zoekt | cmd/zoekt-indexserver/main.go | deleteLogs | func deleteLogs(logDir string, maxAge time.Duration) {
fs, err := filepath.Glob(filepath.Join(logDir, "*"))
if err != nil {
log.Fatalf("filepath.Glob(%s): %v", logDir, err)
}
threshold := time.Now().Add(-maxAge)
for _, fn := range fs {
if fi, err := os.Lstat(fn); err == nil && fi.ModTime().Before(threshold) {
os.Remove(fn)
}
}
} | go | func deleteLogs(logDir string, maxAge time.Duration) {
fs, err := filepath.Glob(filepath.Join(logDir, "*"))
if err != nil {
log.Fatalf("filepath.Glob(%s): %v", logDir, err)
}
threshold := time.Now().Add(-maxAge)
for _, fn := range fs {
if fi, err := os.Lstat(fn); err == nil && fi.ModTime().Before(threshold) {
os.Remove(fn)
}
}
} | [
"func",
"deleteLogs",
"(",
"logDir",
"string",
",",
"maxAge",
"time",
".",
"Duration",
")",
"{",
"fs",
",",
"err",
":=",
"filepath",
".",
"Glob",
"(",
"filepath",
".",
"Join",
"(",
"logDir",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"logDir",
",",
"err",
")",
"\n",
"}",
"\n\n",
"threshold",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"-",
"maxAge",
")",
"\n",
"for",
"_",
",",
"fn",
":=",
"range",
"fs",
"{",
"if",
"fi",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"fn",
")",
";",
"err",
"==",
"nil",
"&&",
"fi",
".",
"ModTime",
"(",
")",
".",
"Before",
"(",
"threshold",
")",
"{",
"os",
".",
"Remove",
"(",
"fn",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // deleteLogs deletes old logs. | [
"deleteLogs",
"deletes",
"old",
"logs",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-indexserver/main.go#L165-L177 |
150,368 | google/zoekt | cmd/zoekt-indexserver/main.go | deleteIfOrphan | func deleteIfOrphan(repoDir string, fn string) error {
f, err := os.Open(fn)
if err != nil {
return nil
}
defer f.Close()
ifile, err := zoekt.NewIndexFile(f)
if err != nil {
return nil
}
defer ifile.Close()
repo, _, err := zoekt.ReadMetadata(ifile)
if err != nil {
return nil
}
_, err = os.Stat(repo.Source)
if os.IsNotExist(err) {
log.Printf("deleting orphan shard %s; source %q not found", fn, repo.Source)
return os.Remove(fn)
}
return err
} | go | func deleteIfOrphan(repoDir string, fn string) error {
f, err := os.Open(fn)
if err != nil {
return nil
}
defer f.Close()
ifile, err := zoekt.NewIndexFile(f)
if err != nil {
return nil
}
defer ifile.Close()
repo, _, err := zoekt.ReadMetadata(ifile)
if err != nil {
return nil
}
_, err = os.Stat(repo.Source)
if os.IsNotExist(err) {
log.Printf("deleting orphan shard %s; source %q not found", fn, repo.Source)
return os.Remove(fn)
}
return err
} | [
"func",
"deleteIfOrphan",
"(",
"repoDir",
"string",
",",
"fn",
"string",
")",
"error",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"fn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"ifile",
",",
"err",
":=",
"zoekt",
".",
"NewIndexFile",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"defer",
"ifile",
".",
"Close",
"(",
")",
"\n\n",
"repo",
",",
"_",
",",
"err",
":=",
"zoekt",
".",
"ReadMetadata",
"(",
"ifile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"os",
".",
"Stat",
"(",
"repo",
".",
"Source",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"fn",
",",
"repo",
".",
"Source",
")",
"\n",
"return",
"os",
".",
"Remove",
"(",
"fn",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Delete the shard if its corresponding git repo can't be found. | [
"Delete",
"the",
"shard",
"if",
"its",
"corresponding",
"git",
"repo",
"can",
"t",
"be",
"found",
"."
] | 3493be98f11f3ca46cdb973a968f09f7cacc645d | https://github.com/google/zoekt/blob/3493be98f11f3ca46cdb973a968f09f7cacc645d/cmd/zoekt-indexserver/main.go#L188-L213 |
150,369 | derekparker/trie | trie.go | New | func New() *Trie {
return &Trie{
root: &Node{children: make(map[rune]*Node), depth: 0},
size: 0,
}
} | go | func New() *Trie {
return &Trie{
root: &Node{children: make(map[rune]*Node), depth: 0},
size: 0,
}
} | [
"func",
"New",
"(",
")",
"*",
"Trie",
"{",
"return",
"&",
"Trie",
"{",
"root",
":",
"&",
"Node",
"{",
"children",
":",
"make",
"(",
"map",
"[",
"rune",
"]",
"*",
"Node",
")",
",",
"depth",
":",
"0",
"}",
",",
"size",
":",
"0",
",",
"}",
"\n",
"}"
] | // Creates a new Trie with an initialized root Node. | [
"Creates",
"a",
"new",
"Trie",
"with",
"an",
"initialized",
"root",
"Node",
"."
] | 1ce4922c7ad906a094c6298977755068ba76ad31 | https://github.com/derekparker/trie/blob/1ce4922c7ad906a094c6298977755068ba76ad31/trie.go#L38-L43 |
150,370 | derekparker/trie | trie.go | Find | func (t *Trie) Find(key string) (*Node, bool) {
node := findNode(t.Root(), []rune(key))
if node == nil {
return nil, false
}
node, ok := node.Children()[nul]
if !ok || !node.term {
return nil, false
}
return node, true
} | go | func (t *Trie) Find(key string) (*Node, bool) {
node := findNode(t.Root(), []rune(key))
if node == nil {
return nil, false
}
node, ok := node.Children()[nul]
if !ok || !node.term {
return nil, false
}
return node, true
} | [
"func",
"(",
"t",
"*",
"Trie",
")",
"Find",
"(",
"key",
"string",
")",
"(",
"*",
"Node",
",",
"bool",
")",
"{",
"node",
":=",
"findNode",
"(",
"t",
".",
"Root",
"(",
")",
",",
"[",
"]",
"rune",
"(",
"key",
")",
")",
"\n",
"if",
"node",
"==",
"nil",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"node",
",",
"ok",
":=",
"node",
".",
"Children",
"(",
")",
"[",
"nul",
"]",
"\n",
"if",
"!",
"ok",
"||",
"!",
"node",
".",
"term",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"node",
",",
"true",
"\n",
"}"
] | // Finds and returns meta data associated
// with `key`. | [
"Finds",
"and",
"returns",
"meta",
"data",
"associated",
"with",
"key",
"."
] | 1ce4922c7ad906a094c6298977755068ba76ad31 | https://github.com/derekparker/trie/blob/1ce4922c7ad906a094c6298977755068ba76ad31/trie.go#L78-L90 |
150,371 | derekparker/trie | trie.go | Remove | func (t *Trie) Remove(key string) {
var (
i int
rs = []rune(key)
node = findNode(t.Root(), []rune(key))
)
t.mu.Lock()
defer t.mu.Unlock()
t.size--
for n := node.Parent(); n != nil; n = n.Parent() {
i++
if len(n.Children()) > 1 {
r := rs[len(rs)-i]
n.RemoveChild(r)
break
}
}
} | go | func (t *Trie) Remove(key string) {
var (
i int
rs = []rune(key)
node = findNode(t.Root(), []rune(key))
)
t.mu.Lock()
defer t.mu.Unlock()
t.size--
for n := node.Parent(); n != nil; n = n.Parent() {
i++
if len(n.Children()) > 1 {
r := rs[len(rs)-i]
n.RemoveChild(r)
break
}
}
} | [
"func",
"(",
"t",
"*",
"Trie",
")",
"Remove",
"(",
"key",
"string",
")",
"{",
"var",
"(",
"i",
"int",
"\n",
"rs",
"=",
"[",
"]",
"rune",
"(",
"key",
")",
"\n",
"node",
"=",
"findNode",
"(",
"t",
".",
"Root",
"(",
")",
",",
"[",
"]",
"rune",
"(",
"key",
")",
")",
"\n",
")",
"\n\n",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"size",
"--",
"\n",
"for",
"n",
":=",
"node",
".",
"Parent",
"(",
")",
";",
"n",
"!=",
"nil",
";",
"n",
"=",
"n",
".",
"Parent",
"(",
")",
"{",
"i",
"++",
"\n",
"if",
"len",
"(",
"n",
".",
"Children",
"(",
")",
")",
">",
"1",
"{",
"r",
":=",
"rs",
"[",
"len",
"(",
"rs",
")",
"-",
"i",
"]",
"\n",
"n",
".",
"RemoveChild",
"(",
"r",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Removes a key from the trie, ensuring that
// all bitmasks up to root are appropriately recalculated. | [
"Removes",
"a",
"key",
"from",
"the",
"trie",
"ensuring",
"that",
"all",
"bitmasks",
"up",
"to",
"root",
"are",
"appropriately",
"recalculated",
"."
] | 1ce4922c7ad906a094c6298977755068ba76ad31 | https://github.com/derekparker/trie/blob/1ce4922c7ad906a094c6298977755068ba76ad31/trie.go#L99-L118 |
150,372 | derekparker/trie | trie.go | FuzzySearch | func (t Trie) FuzzySearch(pre string) []string {
keys := fuzzycollect(t.Root(), []rune(pre))
sort.Sort(ByKeys(keys))
return keys
} | go | func (t Trie) FuzzySearch(pre string) []string {
keys := fuzzycollect(t.Root(), []rune(pre))
sort.Sort(ByKeys(keys))
return keys
} | [
"func",
"(",
"t",
"Trie",
")",
"FuzzySearch",
"(",
"pre",
"string",
")",
"[",
"]",
"string",
"{",
"keys",
":=",
"fuzzycollect",
"(",
"t",
".",
"Root",
"(",
")",
",",
"[",
"]",
"rune",
"(",
"pre",
")",
")",
"\n",
"sort",
".",
"Sort",
"(",
"ByKeys",
"(",
"keys",
")",
")",
"\n",
"return",
"keys",
"\n",
"}"
] | // Performs a fuzzy search against the keys in the trie. | [
"Performs",
"a",
"fuzzy",
"search",
"against",
"the",
"keys",
"in",
"the",
"trie",
"."
] | 1ce4922c7ad906a094c6298977755068ba76ad31 | https://github.com/derekparker/trie/blob/1ce4922c7ad906a094c6298977755068ba76ad31/trie.go#L126-L130 |
150,373 | derekparker/trie | trie.go | PrefixSearch | func (t Trie) PrefixSearch(pre string) []string {
node := findNode(t.Root(), []rune(pre))
if node == nil {
return nil
}
return collect(node)
} | go | func (t Trie) PrefixSearch(pre string) []string {
node := findNode(t.Root(), []rune(pre))
if node == nil {
return nil
}
return collect(node)
} | [
"func",
"(",
"t",
"Trie",
")",
"PrefixSearch",
"(",
"pre",
"string",
")",
"[",
"]",
"string",
"{",
"node",
":=",
"findNode",
"(",
"t",
".",
"Root",
"(",
")",
",",
"[",
"]",
"rune",
"(",
"pre",
")",
")",
"\n",
"if",
"node",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"collect",
"(",
"node",
")",
"\n",
"}"
] | // Performs a prefix search against the keys in the trie. | [
"Performs",
"a",
"prefix",
"search",
"against",
"the",
"keys",
"in",
"the",
"trie",
"."
] | 1ce4922c7ad906a094c6298977755068ba76ad31 | https://github.com/derekparker/trie/blob/1ce4922c7ad906a094c6298977755068ba76ad31/trie.go#L133-L140 |
150,374 | derekparker/trie | trie.go | NewChild | func (n *Node) NewChild(val rune, bitmask uint64, meta interface{}, term bool) *Node {
node := &Node{
val: val,
mask: bitmask,
term: term,
meta: meta,
parent: n,
children: make(map[rune]*Node),
depth: n.depth + 1,
}
n.children[val] = node
n.mask |= bitmask
return node
} | go | func (n *Node) NewChild(val rune, bitmask uint64, meta interface{}, term bool) *Node {
node := &Node{
val: val,
mask: bitmask,
term: term,
meta: meta,
parent: n,
children: make(map[rune]*Node),
depth: n.depth + 1,
}
n.children[val] = node
n.mask |= bitmask
return node
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"NewChild",
"(",
"val",
"rune",
",",
"bitmask",
"uint64",
",",
"meta",
"interface",
"{",
"}",
",",
"term",
"bool",
")",
"*",
"Node",
"{",
"node",
":=",
"&",
"Node",
"{",
"val",
":",
"val",
",",
"mask",
":",
"bitmask",
",",
"term",
":",
"term",
",",
"meta",
":",
"meta",
",",
"parent",
":",
"n",
",",
"children",
":",
"make",
"(",
"map",
"[",
"rune",
"]",
"*",
"Node",
")",
",",
"depth",
":",
"n",
".",
"depth",
"+",
"1",
",",
"}",
"\n",
"n",
".",
"children",
"[",
"val",
"]",
"=",
"node",
"\n",
"n",
".",
"mask",
"|=",
"bitmask",
"\n",
"return",
"node",
"\n",
"}"
] | // Creates and returns a pointer to a new child for the node. | [
"Creates",
"and",
"returns",
"a",
"pointer",
"to",
"a",
"new",
"child",
"for",
"the",
"node",
"."
] | 1ce4922c7ad906a094c6298977755068ba76ad31 | https://github.com/derekparker/trie/blob/1ce4922c7ad906a094c6298977755068ba76ad31/trie.go#L143-L156 |
150,375 | tidwall/sjson | sjson.go | appendStringify | func appendStringify(buf []byte, s string) []byte {
if mustMarshalString(s) {
b, _ := jsongo.Marshal(s)
return append(buf, b...)
}
buf = append(buf, '"')
buf = append(buf, s...)
buf = append(buf, '"')
return buf
} | go | func appendStringify(buf []byte, s string) []byte {
if mustMarshalString(s) {
b, _ := jsongo.Marshal(s)
return append(buf, b...)
}
buf = append(buf, '"')
buf = append(buf, s...)
buf = append(buf, '"')
return buf
} | [
"func",
"appendStringify",
"(",
"buf",
"[",
"]",
"byte",
",",
"s",
"string",
")",
"[",
"]",
"byte",
"{",
"if",
"mustMarshalString",
"(",
"s",
")",
"{",
"b",
",",
"_",
":=",
"jsongo",
".",
"Marshal",
"(",
"s",
")",
"\n",
"return",
"append",
"(",
"buf",
",",
"b",
"...",
")",
"\n",
"}",
"\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"'\"'",
")",
"\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"s",
"...",
")",
"\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"'\"'",
")",
"\n",
"return",
"buf",
"\n",
"}"
] | // appendStringify makes a json string and appends to buf. | [
"appendStringify",
"makes",
"a",
"json",
"string",
"and",
"appends",
"to",
"buf",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L119-L128 |
150,376 | tidwall/sjson | sjson.go | appendBuild | func appendBuild(buf []byte, array bool, paths []pathResult, raw string,
stringify bool) []byte {
if !array {
buf = appendStringify(buf, paths[0].part)
buf = append(buf, ':')
}
if len(paths) > 1 {
n, numeric := atoui(paths[1])
if numeric || (!paths[1].force && paths[1].part == "-1") {
buf = append(buf, '[')
buf = appendRepeat(buf, "null,", n)
buf = appendBuild(buf, true, paths[1:], raw, stringify)
buf = append(buf, ']')
} else {
buf = append(buf, '{')
buf = appendBuild(buf, false, paths[1:], raw, stringify)
buf = append(buf, '}')
}
} else {
if stringify {
buf = appendStringify(buf, raw)
} else {
buf = append(buf, raw...)
}
}
return buf
} | go | func appendBuild(buf []byte, array bool, paths []pathResult, raw string,
stringify bool) []byte {
if !array {
buf = appendStringify(buf, paths[0].part)
buf = append(buf, ':')
}
if len(paths) > 1 {
n, numeric := atoui(paths[1])
if numeric || (!paths[1].force && paths[1].part == "-1") {
buf = append(buf, '[')
buf = appendRepeat(buf, "null,", n)
buf = appendBuild(buf, true, paths[1:], raw, stringify)
buf = append(buf, ']')
} else {
buf = append(buf, '{')
buf = appendBuild(buf, false, paths[1:], raw, stringify)
buf = append(buf, '}')
}
} else {
if stringify {
buf = appendStringify(buf, raw)
} else {
buf = append(buf, raw...)
}
}
return buf
} | [
"func",
"appendBuild",
"(",
"buf",
"[",
"]",
"byte",
",",
"array",
"bool",
",",
"paths",
"[",
"]",
"pathResult",
",",
"raw",
"string",
",",
"stringify",
"bool",
")",
"[",
"]",
"byte",
"{",
"if",
"!",
"array",
"{",
"buf",
"=",
"appendStringify",
"(",
"buf",
",",
"paths",
"[",
"0",
"]",
".",
"part",
")",
"\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"':'",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"paths",
")",
">",
"1",
"{",
"n",
",",
"numeric",
":=",
"atoui",
"(",
"paths",
"[",
"1",
"]",
")",
"\n",
"if",
"numeric",
"||",
"(",
"!",
"paths",
"[",
"1",
"]",
".",
"force",
"&&",
"paths",
"[",
"1",
"]",
".",
"part",
"==",
"\"",
"\"",
")",
"{",
"buf",
"=",
"append",
"(",
"buf",
",",
"'['",
")",
"\n",
"buf",
"=",
"appendRepeat",
"(",
"buf",
",",
"\"",
"\"",
",",
"n",
")",
"\n",
"buf",
"=",
"appendBuild",
"(",
"buf",
",",
"true",
",",
"paths",
"[",
"1",
":",
"]",
",",
"raw",
",",
"stringify",
")",
"\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"']'",
")",
"\n",
"}",
"else",
"{",
"buf",
"=",
"append",
"(",
"buf",
",",
"'{'",
")",
"\n",
"buf",
"=",
"appendBuild",
"(",
"buf",
",",
"false",
",",
"paths",
"[",
"1",
":",
"]",
",",
"raw",
",",
"stringify",
")",
"\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"'}'",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"stringify",
"{",
"buf",
"=",
"appendStringify",
"(",
"buf",
",",
"raw",
")",
"\n",
"}",
"else",
"{",
"buf",
"=",
"append",
"(",
"buf",
",",
"raw",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"buf",
"\n",
"}"
] | // appendBuild builds a json block from a json path. | [
"appendBuild",
"builds",
"a",
"json",
"block",
"from",
"a",
"json",
"path",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L131-L157 |
150,377 | tidwall/sjson | sjson.go | atoui | func atoui(r pathResult) (n int, ok bool) {
if r.force {
return 0, false
}
for i := 0; i < len(r.part); i++ {
if r.part[i] < '0' || r.part[i] > '9' {
return 0, false
}
n = n*10 + int(r.part[i]-'0')
}
return n, true
} | go | func atoui(r pathResult) (n int, ok bool) {
if r.force {
return 0, false
}
for i := 0; i < len(r.part); i++ {
if r.part[i] < '0' || r.part[i] > '9' {
return 0, false
}
n = n*10 + int(r.part[i]-'0')
}
return n, true
} | [
"func",
"atoui",
"(",
"r",
"pathResult",
")",
"(",
"n",
"int",
",",
"ok",
"bool",
")",
"{",
"if",
"r",
".",
"force",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"r",
".",
"part",
")",
";",
"i",
"++",
"{",
"if",
"r",
".",
"part",
"[",
"i",
"]",
"<",
"'0'",
"||",
"r",
".",
"part",
"[",
"i",
"]",
">",
"'9'",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"n",
"=",
"n",
"*",
"10",
"+",
"int",
"(",
"r",
".",
"part",
"[",
"i",
"]",
"-",
"'0'",
")",
"\n",
"}",
"\n",
"return",
"n",
",",
"true",
"\n",
"}"
] | // atoui does a rip conversion of string -> unigned int. | [
"atoui",
"does",
"a",
"rip",
"conversion",
"of",
"string",
"-",
">",
"unigned",
"int",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L160-L171 |
150,378 | tidwall/sjson | sjson.go | appendRepeat | func appendRepeat(buf []byte, s string, n int) []byte {
for i := 0; i < n; i++ {
buf = append(buf, s...)
}
return buf
} | go | func appendRepeat(buf []byte, s string, n int) []byte {
for i := 0; i < n; i++ {
buf = append(buf, s...)
}
return buf
} | [
"func",
"appendRepeat",
"(",
"buf",
"[",
"]",
"byte",
",",
"s",
"string",
",",
"n",
"int",
")",
"[",
"]",
"byte",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"buf",
"=",
"append",
"(",
"buf",
",",
"s",
"...",
")",
"\n",
"}",
"\n",
"return",
"buf",
"\n",
"}"
] | // appendRepeat repeats string "n" times and appends to buf. | [
"appendRepeat",
"repeats",
"string",
"n",
"times",
"and",
"appends",
"to",
"buf",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L174-L179 |
150,379 | tidwall/sjson | sjson.go | trim | func trim(s string) string {
for len(s) > 0 {
if s[0] <= ' ' {
s = s[1:]
continue
}
break
}
for len(s) > 0 {
if s[len(s)-1] <= ' ' {
s = s[:len(s)-1]
continue
}
break
}
return s
} | go | func trim(s string) string {
for len(s) > 0 {
if s[0] <= ' ' {
s = s[1:]
continue
}
break
}
for len(s) > 0 {
if s[len(s)-1] <= ' ' {
s = s[:len(s)-1]
continue
}
break
}
return s
} | [
"func",
"trim",
"(",
"s",
"string",
")",
"string",
"{",
"for",
"len",
"(",
"s",
")",
">",
"0",
"{",
"if",
"s",
"[",
"0",
"]",
"<=",
"' '",
"{",
"s",
"=",
"s",
"[",
"1",
":",
"]",
"\n",
"continue",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"for",
"len",
"(",
"s",
")",
">",
"0",
"{",
"if",
"s",
"[",
"len",
"(",
"s",
")",
"-",
"1",
"]",
"<=",
"' '",
"{",
"s",
"=",
"s",
"[",
":",
"len",
"(",
"s",
")",
"-",
"1",
"]",
"\n",
"continue",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // trim does a rip trim | [
"trim",
"does",
"a",
"rip",
"trim"
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L182-L198 |
150,380 | tidwall/sjson | sjson.go | deleteTailItem | func deleteTailItem(buf []byte) ([]byte, bool) {
loop:
for i := len(buf) - 1; i >= 0; i-- {
// look for either a ',',':','['
switch buf[i] {
case '[':
return buf, true
case ',':
return buf[:i], false
case ':':
// delete tail string
i--
for ; i >= 0; i-- {
if buf[i] == '"' {
i--
for ; i >= 0; i-- {
if buf[i] == '"' {
i--
if i >= 0 && buf[i] == '\\' {
i--
continue
}
for ; i >= 0; i-- {
// look for either a ',','{'
switch buf[i] {
case '{':
return buf[:i+1], true
case ',':
return buf[:i], false
}
}
}
}
break
}
}
break loop
}
}
return buf, false
} | go | func deleteTailItem(buf []byte) ([]byte, bool) {
loop:
for i := len(buf) - 1; i >= 0; i-- {
// look for either a ',',':','['
switch buf[i] {
case '[':
return buf, true
case ',':
return buf[:i], false
case ':':
// delete tail string
i--
for ; i >= 0; i-- {
if buf[i] == '"' {
i--
for ; i >= 0; i-- {
if buf[i] == '"' {
i--
if i >= 0 && buf[i] == '\\' {
i--
continue
}
for ; i >= 0; i-- {
// look for either a ',','{'
switch buf[i] {
case '{':
return buf[:i+1], true
case ',':
return buf[:i], false
}
}
}
}
break
}
}
break loop
}
}
return buf, false
} | [
"func",
"deleteTailItem",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"bool",
")",
"{",
"loop",
":",
"for",
"i",
":=",
"len",
"(",
"buf",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"// look for either a ',',':','['",
"switch",
"buf",
"[",
"i",
"]",
"{",
"case",
"'['",
":",
"return",
"buf",
",",
"true",
"\n",
"case",
"','",
":",
"return",
"buf",
"[",
":",
"i",
"]",
",",
"false",
"\n",
"case",
"':'",
":",
"// delete tail string",
"i",
"--",
"\n",
"for",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"if",
"buf",
"[",
"i",
"]",
"==",
"'\"'",
"{",
"i",
"--",
"\n",
"for",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"if",
"buf",
"[",
"i",
"]",
"==",
"'\"'",
"{",
"i",
"--",
"\n",
"if",
"i",
">=",
"0",
"&&",
"buf",
"[",
"i",
"]",
"==",
"'\\\\'",
"{",
"i",
"--",
"\n",
"continue",
"\n",
"}",
"\n",
"for",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"// look for either a ',','{'",
"switch",
"buf",
"[",
"i",
"]",
"{",
"case",
"'{'",
":",
"return",
"buf",
"[",
":",
"i",
"+",
"1",
"]",
",",
"true",
"\n",
"case",
"','",
":",
"return",
"buf",
"[",
":",
"i",
"]",
",",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"break",
"loop",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"buf",
",",
"false",
"\n",
"}"
] | // deleteTailItem deletes the previous key or comma. | [
"deleteTailItem",
"deletes",
"the",
"previous",
"key",
"or",
"comma",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L201-L241 |
150,381 | tidwall/sjson | sjson.go | SetRaw | func SetRaw(json, path, value string) (string, error) {
return SetRawOptions(json, path, value, nil)
} | go | func SetRaw(json, path, value string) (string, error) {
return SetRawOptions(json, path, value, nil)
} | [
"func",
"SetRaw",
"(",
"json",
",",
"path",
",",
"value",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"SetRawOptions",
"(",
"json",
",",
"path",
",",
"value",
",",
"nil",
")",
"\n",
"}"
] | // SetRaw sets a raw json value for the specified path.
// This function works the same as Set except that the value is set as a
// raw block of json. This allows for setting premarshalled json objects. | [
"SetRaw",
"sets",
"a",
"raw",
"json",
"value",
"for",
"the",
"specified",
"path",
".",
"This",
"function",
"works",
"the",
"same",
"as",
"Set",
"except",
"that",
"the",
"value",
"is",
"set",
"as",
"a",
"raw",
"block",
"of",
"json",
".",
"This",
"allows",
"for",
"setting",
"premarshalled",
"json",
"objects",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L446-L448 |
150,382 | tidwall/sjson | sjson.go | SetRawOptions | func SetRawOptions(json, path, value string, opts *Options) (string, error) {
var optimistic bool
if opts != nil {
optimistic = opts.Optimistic
}
res, err := set(json, path, value, false, false, optimistic, false)
if err == errNoChange {
return json, nil
}
return string(res), err
} | go | func SetRawOptions(json, path, value string, opts *Options) (string, error) {
var optimistic bool
if opts != nil {
optimistic = opts.Optimistic
}
res, err := set(json, path, value, false, false, optimistic, false)
if err == errNoChange {
return json, nil
}
return string(res), err
} | [
"func",
"SetRawOptions",
"(",
"json",
",",
"path",
",",
"value",
"string",
",",
"opts",
"*",
"Options",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"optimistic",
"bool",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"optimistic",
"=",
"opts",
".",
"Optimistic",
"\n",
"}",
"\n",
"res",
",",
"err",
":=",
"set",
"(",
"json",
",",
"path",
",",
"value",
",",
"false",
",",
"false",
",",
"optimistic",
",",
"false",
")",
"\n",
"if",
"err",
"==",
"errNoChange",
"{",
"return",
"json",
",",
"nil",
"\n",
"}",
"\n",
"return",
"string",
"(",
"res",
")",
",",
"err",
"\n",
"}"
] | // SetRawOptions sets a raw json value for the specified path with options.
// This furnction works the same as SetOptions except that the value is set
// as a raw block of json. This allows for setting premarshalled json objects. | [
"SetRawOptions",
"sets",
"a",
"raw",
"json",
"value",
"for",
"the",
"specified",
"path",
"with",
"options",
".",
"This",
"furnction",
"works",
"the",
"same",
"as",
"SetOptions",
"except",
"that",
"the",
"value",
"is",
"set",
"as",
"a",
"raw",
"block",
"of",
"json",
".",
"This",
"allows",
"for",
"setting",
"premarshalled",
"json",
"objects",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L453-L463 |
150,383 | tidwall/sjson | sjson.go | Delete | func Delete(json, path string) (string, error) {
return Set(json, path, dtype{})
} | go | func Delete(json, path string) (string, error) {
return Set(json, path, dtype{})
} | [
"func",
"Delete",
"(",
"json",
",",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"Set",
"(",
"json",
",",
"path",
",",
"dtype",
"{",
"}",
")",
"\n",
"}"
] | // Delete deletes a value from json for the specified path. | [
"Delete",
"deletes",
"a",
"value",
"from",
"json",
"for",
"the",
"specified",
"path",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L475-L477 |
150,384 | tidwall/sjson | sjson.go | DeleteBytes | func DeleteBytes(json []byte, path string) ([]byte, error) {
return SetBytes(json, path, dtype{})
} | go | func DeleteBytes(json []byte, path string) ([]byte, error) {
return SetBytes(json, path, dtype{})
} | [
"func",
"DeleteBytes",
"(",
"json",
"[",
"]",
"byte",
",",
"path",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"SetBytes",
"(",
"json",
",",
"path",
",",
"dtype",
"{",
"}",
")",
"\n",
"}"
] | // DeleteBytes deletes a value from json for the specified path. | [
"DeleteBytes",
"deletes",
"a",
"value",
"from",
"json",
"for",
"the",
"specified",
"path",
"."
] | 25fb082a20e29e83fb7b7ef5f5919166aad1f084 | https://github.com/tidwall/sjson/blob/25fb082a20e29e83fb7b7ef5f5919166aad1f084/sjson.go#L480-L482 |
150,385 | SebastiaanKlippert/go-wkhtmltopdf | wkhtmltopdf.go | NewPageReader | func NewPageReader(input io.Reader) *PageReader {
return &PageReader{
Input: input,
PageOptions: NewPageOptions(),
}
} | go | func NewPageReader(input io.Reader) *PageReader {
return &PageReader{
Input: input,
PageOptions: NewPageOptions(),
}
} | [
"func",
"NewPageReader",
"(",
"input",
"io",
".",
"Reader",
")",
"*",
"PageReader",
"{",
"return",
"&",
"PageReader",
"{",
"Input",
":",
"input",
",",
"PageOptions",
":",
"NewPageOptions",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewPageReader creates a new PageReader from an io.Reader | [
"NewPageReader",
"creates",
"a",
"new",
"PageReader",
"from",
"an",
"io",
".",
"Reader"
] | 72a7793efd38728796273861bb27d590cc33d9d4 | https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/72a7793efd38728796273861bb27d590cc33d9d4/wkhtmltopdf.go#L99-L104 |
150,386 | SebastiaanKlippert/go-wkhtmltopdf | wkhtmltopdf.go | Args | func (po *PageOptions) Args() []string {
return append(append([]string{}, po.pageOptions.Args()...), po.headerAndFooterOptions.Args()...)
} | go | func (po *PageOptions) Args() []string {
return append(append([]string{}, po.pageOptions.Args()...), po.headerAndFooterOptions.Args()...)
} | [
"func",
"(",
"po",
"*",
"PageOptions",
")",
"Args",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"append",
"(",
"append",
"(",
"[",
"]",
"string",
"{",
"}",
",",
"po",
".",
"pageOptions",
".",
"Args",
"(",
")",
"...",
")",
",",
"po",
".",
"headerAndFooterOptions",
".",
"Args",
"(",
")",
"...",
")",
"\n",
"}"
] | // Args returns the argument slice | [
"Args",
"returns",
"the",
"argument",
"slice"
] | 72a7793efd38728796273861bb27d590cc33d9d4 | https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/72a7793efd38728796273861bb27d590cc33d9d4/wkhtmltopdf.go#L119-L121 |
150,387 | SebastiaanKlippert/go-wkhtmltopdf | wkhtmltopdf.go | Args | func (pdfg *PDFGenerator) Args() []string {
args := append([]string{}, pdfg.globalOptions.Args()...)
args = append(args, pdfg.outlineOptions.Args()...)
if pdfg.Cover.Input != "" {
args = append(args, "cover")
args = append(args, pdfg.Cover.Input)
args = append(args, pdfg.Cover.pageOptions.Args()...)
}
if pdfg.TOC.Include {
args = append(args, "toc")
args = append(args, pdfg.TOC.pageOptions.Args()...)
args = append(args, pdfg.TOC.tocOptions.Args()...)
}
for _, page := range pdfg.pages {
args = append(args, "page")
args = append(args, page.InputFile())
args = append(args, page.Args()...)
}
if pdfg.OutputFile != "" {
args = append(args, pdfg.OutputFile)
} else {
args = append(args, "-")
}
return args
} | go | func (pdfg *PDFGenerator) Args() []string {
args := append([]string{}, pdfg.globalOptions.Args()...)
args = append(args, pdfg.outlineOptions.Args()...)
if pdfg.Cover.Input != "" {
args = append(args, "cover")
args = append(args, pdfg.Cover.Input)
args = append(args, pdfg.Cover.pageOptions.Args()...)
}
if pdfg.TOC.Include {
args = append(args, "toc")
args = append(args, pdfg.TOC.pageOptions.Args()...)
args = append(args, pdfg.TOC.tocOptions.Args()...)
}
for _, page := range pdfg.pages {
args = append(args, "page")
args = append(args, page.InputFile())
args = append(args, page.Args()...)
}
if pdfg.OutputFile != "" {
args = append(args, pdfg.OutputFile)
} else {
args = append(args, "-")
}
return args
} | [
"func",
"(",
"pdfg",
"*",
"PDFGenerator",
")",
"Args",
"(",
")",
"[",
"]",
"string",
"{",
"args",
":=",
"append",
"(",
"[",
"]",
"string",
"{",
"}",
",",
"pdfg",
".",
"globalOptions",
".",
"Args",
"(",
")",
"...",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"pdfg",
".",
"outlineOptions",
".",
"Args",
"(",
")",
"...",
")",
"\n",
"if",
"pdfg",
".",
"Cover",
".",
"Input",
"!=",
"\"",
"\"",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"pdfg",
".",
"Cover",
".",
"Input",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"pdfg",
".",
"Cover",
".",
"pageOptions",
".",
"Args",
"(",
")",
"...",
")",
"\n",
"}",
"\n",
"if",
"pdfg",
".",
"TOC",
".",
"Include",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"pdfg",
".",
"TOC",
".",
"pageOptions",
".",
"Args",
"(",
")",
"...",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"pdfg",
".",
"TOC",
".",
"tocOptions",
".",
"Args",
"(",
")",
"...",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"page",
":=",
"range",
"pdfg",
".",
"pages",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"page",
".",
"InputFile",
"(",
")",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"page",
".",
"Args",
"(",
")",
"...",
")",
"\n",
"}",
"\n",
"if",
"pdfg",
".",
"OutputFile",
"!=",
"\"",
"\"",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"pdfg",
".",
"OutputFile",
")",
"\n",
"}",
"else",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"args",
"\n",
"}"
] | //Args returns the commandline arguments as a string slice | [
"Args",
"returns",
"the",
"commandline",
"arguments",
"as",
"a",
"string",
"slice"
] | 72a7793efd38728796273861bb27d590cc33d9d4 | https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/72a7793efd38728796273861bb27d590cc33d9d4/wkhtmltopdf.go#L164-L188 |
150,388 | SebastiaanKlippert/go-wkhtmltopdf | wkhtmltopdf.go | AddPage | func (pdfg *PDFGenerator) AddPage(p page) {
pdfg.pages = append(pdfg.pages, p)
} | go | func (pdfg *PDFGenerator) AddPage(p page) {
pdfg.pages = append(pdfg.pages, p)
} | [
"func",
"(",
"pdfg",
"*",
"PDFGenerator",
")",
"AddPage",
"(",
"p",
"page",
")",
"{",
"pdfg",
".",
"pages",
"=",
"append",
"(",
"pdfg",
".",
"pages",
",",
"p",
")",
"\n",
"}"
] | // AddPage adds a new input page to the document.
// A page is an input HTML page, it can span multiple pages in the output document.
// It is a Page when read from file or URL or a PageReader when read from memory. | [
"AddPage",
"adds",
"a",
"new",
"input",
"page",
"to",
"the",
"document",
".",
"A",
"page",
"is",
"an",
"input",
"HTML",
"page",
"it",
"can",
"span",
"multiple",
"pages",
"in",
"the",
"output",
"document",
".",
"It",
"is",
"a",
"Page",
"when",
"read",
"from",
"file",
"or",
"URL",
"or",
"a",
"PageReader",
"when",
"read",
"from",
"memory",
"."
] | 72a7793efd38728796273861bb27d590cc33d9d4 | https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/72a7793efd38728796273861bb27d590cc33d9d4/wkhtmltopdf.go#L198-L200 |
150,389 | SebastiaanKlippert/go-wkhtmltopdf | wkhtmltopdf.go | WriteFile | func (pdfg *PDFGenerator) WriteFile(filename string) error {
return ioutil.WriteFile(filename, pdfg.Bytes(), 0666)
} | go | func (pdfg *PDFGenerator) WriteFile(filename string) error {
return ioutil.WriteFile(filename, pdfg.Bytes(), 0666)
} | [
"func",
"(",
"pdfg",
"*",
"PDFGenerator",
")",
"WriteFile",
"(",
"filename",
"string",
")",
"error",
"{",
"return",
"ioutil",
".",
"WriteFile",
"(",
"filename",
",",
"pdfg",
".",
"Bytes",
"(",
")",
",",
"0666",
")",
"\n",
"}"
] | // WriteFile writes the contents of the output buffer to a file | [
"WriteFile",
"writes",
"the",
"contents",
"of",
"the",
"output",
"buffer",
"to",
"a",
"file"
] | 72a7793efd38728796273861bb27d590cc33d9d4 | https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/72a7793efd38728796273861bb27d590cc33d9d4/wkhtmltopdf.go#L230-L232 |
150,390 | SebastiaanKlippert/go-wkhtmltopdf | wkhtmltopdf.go | findPath | func (pdfg *PDFGenerator) findPath() error {
const exe = "wkhtmltopdf"
pdfg.binPath = GetPath()
if pdfg.binPath != "" {
// wkhtmltopdf has already already found, return
return nil
}
exeDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return err
}
path, err := exec.LookPath(filepath.Join(exeDir, exe))
if err == nil && path != "" {
binPath.Set(path)
pdfg.binPath = path
return nil
}
path, err = exec.LookPath(exe)
if err == nil && path != "" {
binPath.Set(path)
pdfg.binPath = path
return nil
}
dir := os.Getenv("WKHTMLTOPDF_PATH")
if dir == "" {
return fmt.Errorf("%s not found", exe)
}
path, err = exec.LookPath(filepath.Join(dir, exe))
if err == nil && path != "" {
binPath.Set(path)
pdfg.binPath = path
return nil
}
return fmt.Errorf("%s not found", exe)
} | go | func (pdfg *PDFGenerator) findPath() error {
const exe = "wkhtmltopdf"
pdfg.binPath = GetPath()
if pdfg.binPath != "" {
// wkhtmltopdf has already already found, return
return nil
}
exeDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return err
}
path, err := exec.LookPath(filepath.Join(exeDir, exe))
if err == nil && path != "" {
binPath.Set(path)
pdfg.binPath = path
return nil
}
path, err = exec.LookPath(exe)
if err == nil && path != "" {
binPath.Set(path)
pdfg.binPath = path
return nil
}
dir := os.Getenv("WKHTMLTOPDF_PATH")
if dir == "" {
return fmt.Errorf("%s not found", exe)
}
path, err = exec.LookPath(filepath.Join(dir, exe))
if err == nil && path != "" {
binPath.Set(path)
pdfg.binPath = path
return nil
}
return fmt.Errorf("%s not found", exe)
} | [
"func",
"(",
"pdfg",
"*",
"PDFGenerator",
")",
"findPath",
"(",
")",
"error",
"{",
"const",
"exe",
"=",
"\"",
"\"",
"\n",
"pdfg",
".",
"binPath",
"=",
"GetPath",
"(",
")",
"\n",
"if",
"pdfg",
".",
"binPath",
"!=",
"\"",
"\"",
"{",
"// wkhtmltopdf has already already found, return",
"return",
"nil",
"\n",
"}",
"\n",
"exeDir",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"filepath",
".",
"Dir",
"(",
"os",
".",
"Args",
"[",
"0",
"]",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"path",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"filepath",
".",
"Join",
"(",
"exeDir",
",",
"exe",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"path",
"!=",
"\"",
"\"",
"{",
"binPath",
".",
"Set",
"(",
"path",
")",
"\n",
"pdfg",
".",
"binPath",
"=",
"path",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"path",
",",
"err",
"=",
"exec",
".",
"LookPath",
"(",
"exe",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"path",
"!=",
"\"",
"\"",
"{",
"binPath",
".",
"Set",
"(",
"path",
")",
"\n",
"pdfg",
".",
"binPath",
"=",
"path",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"dir",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"dir",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"exe",
")",
"\n",
"}",
"\n",
"path",
",",
"err",
"=",
"exec",
".",
"LookPath",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"exe",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"path",
"!=",
"\"",
"\"",
"{",
"binPath",
".",
"Set",
"(",
"path",
")",
"\n",
"pdfg",
".",
"binPath",
"=",
"path",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"exe",
")",
"\n",
"}"
] | //findPath finds the path to wkhtmltopdf by
//- first looking in the current dir
//- looking in the PATH and PATHEXT environment dirs
//- using the WKHTMLTOPDF_PATH environment dir
//The path is cached, meaning you can not change the location of wkhtmltopdf in
//a running program once it has been found | [
"findPath",
"finds",
"the",
"path",
"to",
"wkhtmltopdf",
"by",
"-",
"first",
"looking",
"in",
"the",
"current",
"dir",
"-",
"looking",
"in",
"the",
"PATH",
"and",
"PATHEXT",
"environment",
"dirs",
"-",
"using",
"the",
"WKHTMLTOPDF_PATH",
"environment",
"dir",
"The",
"path",
"is",
"cached",
"meaning",
"you",
"can",
"not",
"change",
"the",
"location",
"of",
"wkhtmltopdf",
"in",
"a",
"running",
"program",
"once",
"it",
"has",
"been",
"found"
] | 72a7793efd38728796273861bb27d590cc33d9d4 | https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/72a7793efd38728796273861bb27d590cc33d9d4/wkhtmltopdf.go#L240-L274 |
150,391 | SebastiaanKlippert/go-wkhtmltopdf | wkhtmltopdf.go | NewPDFGenerator | func NewPDFGenerator() (*PDFGenerator, error) {
pdfg := &PDFGenerator{
globalOptions: newGlobalOptions(),
outlineOptions: newOutlineOptions(),
Cover: cover{
pageOptions: newPageOptions(),
},
TOC: toc{
allTocOptions: allTocOptions{
tocOptions: newTocOptions(),
pageOptions: newPageOptions(),
},
},
}
err := pdfg.findPath()
return pdfg, err
} | go | func NewPDFGenerator() (*PDFGenerator, error) {
pdfg := &PDFGenerator{
globalOptions: newGlobalOptions(),
outlineOptions: newOutlineOptions(),
Cover: cover{
pageOptions: newPageOptions(),
},
TOC: toc{
allTocOptions: allTocOptions{
tocOptions: newTocOptions(),
pageOptions: newPageOptions(),
},
},
}
err := pdfg.findPath()
return pdfg, err
} | [
"func",
"NewPDFGenerator",
"(",
")",
"(",
"*",
"PDFGenerator",
",",
"error",
")",
"{",
"pdfg",
":=",
"&",
"PDFGenerator",
"{",
"globalOptions",
":",
"newGlobalOptions",
"(",
")",
",",
"outlineOptions",
":",
"newOutlineOptions",
"(",
")",
",",
"Cover",
":",
"cover",
"{",
"pageOptions",
":",
"newPageOptions",
"(",
")",
",",
"}",
",",
"TOC",
":",
"toc",
"{",
"allTocOptions",
":",
"allTocOptions",
"{",
"tocOptions",
":",
"newTocOptions",
"(",
")",
",",
"pageOptions",
":",
"newPageOptions",
"(",
")",
",",
"}",
",",
"}",
",",
"}",
"\n",
"err",
":=",
"pdfg",
".",
"findPath",
"(",
")",
"\n",
"return",
"pdfg",
",",
"err",
"\n",
"}"
] | // NewPDFGenerator returns a new PDFGenerator struct with all options created and
// checks if wkhtmltopdf can be found on the system | [
"NewPDFGenerator",
"returns",
"a",
"new",
"PDFGenerator",
"struct",
"with",
"all",
"options",
"created",
"and",
"checks",
"if",
"wkhtmltopdf",
"can",
"be",
"found",
"on",
"the",
"system"
] | 72a7793efd38728796273861bb27d590cc33d9d4 | https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/72a7793efd38728796273861bb27d590cc33d9d4/wkhtmltopdf.go#L316-L332 |
150,392 | SebastiaanKlippert/go-wkhtmltopdf | json.go | ToJSON | func (pdfg *PDFGenerator) ToJSON() ([]byte, error) {
jpdf := &jsonPDFGenerator{
TOC: pdfg.TOC,
Cover: pdfg.Cover,
GlobalOptions: pdfg.globalOptions,
OutlineOptions: pdfg.outlineOptions,
}
for _, p := range pdfg.pages {
jp := jsonPage{
InputFile: p.InputFile(),
}
switch tp := p.(type) {
case *Page:
jp.PageOptions = tp.PageOptions
case *PageReader:
jp.PageOptions = tp.PageOptions
}
if p.Reader() != nil {
buf, err := ioutil.ReadAll(p.Reader())
if err != nil {
return nil, err
}
jp.Base64PageData = base64.StdEncoding.EncodeToString(buf)
}
jpdf.Pages = append(jpdf.Pages, jp)
}
return json.Marshal(jpdf)
} | go | func (pdfg *PDFGenerator) ToJSON() ([]byte, error) {
jpdf := &jsonPDFGenerator{
TOC: pdfg.TOC,
Cover: pdfg.Cover,
GlobalOptions: pdfg.globalOptions,
OutlineOptions: pdfg.outlineOptions,
}
for _, p := range pdfg.pages {
jp := jsonPage{
InputFile: p.InputFile(),
}
switch tp := p.(type) {
case *Page:
jp.PageOptions = tp.PageOptions
case *PageReader:
jp.PageOptions = tp.PageOptions
}
if p.Reader() != nil {
buf, err := ioutil.ReadAll(p.Reader())
if err != nil {
return nil, err
}
jp.Base64PageData = base64.StdEncoding.EncodeToString(buf)
}
jpdf.Pages = append(jpdf.Pages, jp)
}
return json.Marshal(jpdf)
} | [
"func",
"(",
"pdfg",
"*",
"PDFGenerator",
")",
"ToJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"jpdf",
":=",
"&",
"jsonPDFGenerator",
"{",
"TOC",
":",
"pdfg",
".",
"TOC",
",",
"Cover",
":",
"pdfg",
".",
"Cover",
",",
"GlobalOptions",
":",
"pdfg",
".",
"globalOptions",
",",
"OutlineOptions",
":",
"pdfg",
".",
"outlineOptions",
",",
"}",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"pdfg",
".",
"pages",
"{",
"jp",
":=",
"jsonPage",
"{",
"InputFile",
":",
"p",
".",
"InputFile",
"(",
")",
",",
"}",
"\n",
"switch",
"tp",
":=",
"p",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Page",
":",
"jp",
".",
"PageOptions",
"=",
"tp",
".",
"PageOptions",
"\n",
"case",
"*",
"PageReader",
":",
"jp",
".",
"PageOptions",
"=",
"tp",
".",
"PageOptions",
"\n",
"}",
"\n",
"if",
"p",
".",
"Reader",
"(",
")",
"!=",
"nil",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"p",
".",
"Reader",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"jp",
".",
"Base64PageData",
"=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"buf",
")",
"\n",
"}",
"\n",
"jpdf",
".",
"Pages",
"=",
"append",
"(",
"jpdf",
".",
"Pages",
",",
"jp",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"jpdf",
")",
"\n",
"}"
] | // ToJSON creates JSON of the complete representation of the PDFGenerator.
// It also saves all pages, for a PageReader page, the content is stored as a Base64 string in the JSON. | [
"ToJSON",
"creates",
"JSON",
"of",
"the",
"complete",
"representation",
"of",
"the",
"PDFGenerator",
".",
"It",
"also",
"saves",
"all",
"pages",
"for",
"a",
"PageReader",
"page",
"the",
"content",
"is",
"stored",
"as",
"a",
"Base64",
"string",
"in",
"the",
"JSON",
"."
] | 72a7793efd38728796273861bb27d590cc33d9d4 | https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/72a7793efd38728796273861bb27d590cc33d9d4/json.go#L28-L57 |
150,393 | matcornic/hermes | examples/main.go | send | func send(smtpConfig smtpAuthentication, options sendOptions, htmlBody string, txtBody string) error {
if smtpConfig.Server == "" {
return errors.New("SMTP server config is empty")
}
if smtpConfig.Port == 0 {
return errors.New("SMTP port config is empty")
}
if smtpConfig.SMTPUser == "" {
return errors.New("SMTP user is empty")
}
if smtpConfig.SenderIdentity == "" {
return errors.New("SMTP sender identity is empty")
}
if smtpConfig.SenderEmail == "" {
return errors.New("SMTP sender email is empty")
}
if options.To == "" {
return errors.New("no receiver emails configured")
}
from := mail.Address{
Name: smtpConfig.SenderIdentity,
Address: smtpConfig.SenderEmail,
}
m := gomail.NewMessage()
m.SetHeader("From", from.String())
m.SetHeader("To", options.To)
m.SetHeader("Subject", options.Subject)
m.SetBody("text/plain", txtBody)
m.AddAlternative("text/html", htmlBody)
d := gomail.NewDialer(smtpConfig.Server, smtpConfig.Port, smtpConfig.SMTPUser, smtpConfig.SMTPPassword)
return d.DialAndSend(m)
} | go | func send(smtpConfig smtpAuthentication, options sendOptions, htmlBody string, txtBody string) error {
if smtpConfig.Server == "" {
return errors.New("SMTP server config is empty")
}
if smtpConfig.Port == 0 {
return errors.New("SMTP port config is empty")
}
if smtpConfig.SMTPUser == "" {
return errors.New("SMTP user is empty")
}
if smtpConfig.SenderIdentity == "" {
return errors.New("SMTP sender identity is empty")
}
if smtpConfig.SenderEmail == "" {
return errors.New("SMTP sender email is empty")
}
if options.To == "" {
return errors.New("no receiver emails configured")
}
from := mail.Address{
Name: smtpConfig.SenderIdentity,
Address: smtpConfig.SenderEmail,
}
m := gomail.NewMessage()
m.SetHeader("From", from.String())
m.SetHeader("To", options.To)
m.SetHeader("Subject", options.Subject)
m.SetBody("text/plain", txtBody)
m.AddAlternative("text/html", htmlBody)
d := gomail.NewDialer(smtpConfig.Server, smtpConfig.Port, smtpConfig.SMTPUser, smtpConfig.SMTPPassword)
return d.DialAndSend(m)
} | [
"func",
"send",
"(",
"smtpConfig",
"smtpAuthentication",
",",
"options",
"sendOptions",
",",
"htmlBody",
"string",
",",
"txtBody",
"string",
")",
"error",
"{",
"if",
"smtpConfig",
".",
"Server",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"smtpConfig",
".",
"Port",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"smtpConfig",
".",
"SMTPUser",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"smtpConfig",
".",
"SenderIdentity",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"smtpConfig",
".",
"SenderEmail",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"options",
".",
"To",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"from",
":=",
"mail",
".",
"Address",
"{",
"Name",
":",
"smtpConfig",
".",
"SenderIdentity",
",",
"Address",
":",
"smtpConfig",
".",
"SenderEmail",
",",
"}",
"\n\n",
"m",
":=",
"gomail",
".",
"NewMessage",
"(",
")",
"\n",
"m",
".",
"SetHeader",
"(",
"\"",
"\"",
",",
"from",
".",
"String",
"(",
")",
")",
"\n",
"m",
".",
"SetHeader",
"(",
"\"",
"\"",
",",
"options",
".",
"To",
")",
"\n",
"m",
".",
"SetHeader",
"(",
"\"",
"\"",
",",
"options",
".",
"Subject",
")",
"\n\n",
"m",
".",
"SetBody",
"(",
"\"",
"\"",
",",
"txtBody",
")",
"\n",
"m",
".",
"AddAlternative",
"(",
"\"",
"\"",
",",
"htmlBody",
")",
"\n\n",
"d",
":=",
"gomail",
".",
"NewDialer",
"(",
"smtpConfig",
".",
"Server",
",",
"smtpConfig",
".",
"Port",
",",
"smtpConfig",
".",
"SMTPUser",
",",
"smtpConfig",
".",
"SMTPPassword",
")",
"\n\n",
"return",
"d",
".",
"DialAndSend",
"(",
"m",
")",
"\n",
"}"
] | // send sends the email | [
"send",
"sends",
"the",
"email"
] | 2f49bb14de85f0ec4940c93252d0e3289a59d5bd | https://github.com/matcornic/hermes/blob/2f49bb14de85f0ec4940c93252d0e3289a59d5bd/examples/main.go#L136-L177 |
150,394 | matcornic/hermes | hermes.go | ToHTML | func (c Markdown) ToHTML() template.HTML {
return template.HTML(blackfriday.Run([]byte(string(c))))
} | go | func (c Markdown) ToHTML() template.HTML {
return template.HTML(blackfriday.Run([]byte(string(c))))
} | [
"func",
"(",
"c",
"Markdown",
")",
"ToHTML",
"(",
")",
"template",
".",
"HTML",
"{",
"return",
"template",
".",
"HTML",
"(",
"blackfriday",
".",
"Run",
"(",
"[",
"]",
"byte",
"(",
"string",
"(",
"c",
")",
")",
")",
")",
"\n",
"}"
] | // ToHTML converts Markdown to HTML | [
"ToHTML",
"converts",
"Markdown",
"to",
"HTML"
] | 2f49bb14de85f0ec4940c93252d0e3289a59d5bd | https://github.com/matcornic/hermes/blob/2f49bb14de85f0ec4940c93252d0e3289a59d5bd/hermes.go#L76-L78 |
150,395 | matcornic/hermes | hermes.go | setDefaultHermesValues | func setDefaultHermesValues(h *Hermes) error {
defaultTextDirection := TDLeftToRight
defaultHermes := Hermes{
Theme: new(Default),
TextDirection: defaultTextDirection,
Product: Product{
Name: "Hermes",
Copyright: "Copyright © 2019 Hermes. All rights reserved.",
TroubleText: "If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.",
},
}
// Merge the given hermes engine configuration with default one
// Default one overrides all zero values
err := mergo.Merge(h, defaultHermes)
if err != nil {
return err
}
if h.TextDirection != TDLeftToRight && h.TextDirection != TDRightToLeft {
h.TextDirection = defaultTextDirection
}
return nil
} | go | func setDefaultHermesValues(h *Hermes) error {
defaultTextDirection := TDLeftToRight
defaultHermes := Hermes{
Theme: new(Default),
TextDirection: defaultTextDirection,
Product: Product{
Name: "Hermes",
Copyright: "Copyright © 2019 Hermes. All rights reserved.",
TroubleText: "If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.",
},
}
// Merge the given hermes engine configuration with default one
// Default one overrides all zero values
err := mergo.Merge(h, defaultHermes)
if err != nil {
return err
}
if h.TextDirection != TDLeftToRight && h.TextDirection != TDRightToLeft {
h.TextDirection = defaultTextDirection
}
return nil
} | [
"func",
"setDefaultHermesValues",
"(",
"h",
"*",
"Hermes",
")",
"error",
"{",
"defaultTextDirection",
":=",
"TDLeftToRight",
"\n",
"defaultHermes",
":=",
"Hermes",
"{",
"Theme",
":",
"new",
"(",
"Default",
")",
",",
"TextDirection",
":",
"defaultTextDirection",
",",
"Product",
":",
"Product",
"{",
"Name",
":",
"\"",
"\"",
",",
"Copyright",
":",
"\"",
",",
"",
"TroubleText",
":",
"\"",
"",
"",
"}",
",",
"}",
"\n",
"// Merge the given hermes engine configuration with default one",
"// Default one overrides all zero values",
"err",
":=",
"mergo",
".",
"Merge",
"(",
"h",
",",
"defaultHermes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"h",
".",
"TextDirection",
"!=",
"TDLeftToRight",
"&&",
"h",
".",
"TextDirection",
"!=",
"TDRightToLeft",
"{",
"h",
".",
"TextDirection",
"=",
"defaultTextDirection",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // default values of the engine | [
"default",
"values",
"of",
"the",
"engine"
] | 2f49bb14de85f0ec4940c93252d0e3289a59d5bd | https://github.com/matcornic/hermes/blob/2f49bb14de85f0ec4940c93252d0e3289a59d5bd/hermes.go#L138-L159 |
150,396 | matcornic/hermes | hermes.go | GenerateHTML | func (h *Hermes) GenerateHTML(email Email) (string, error) {
err := setDefaultHermesValues(h)
if err != nil {
return "", err
}
return h.generateTemplate(email, h.Theme.HTMLTemplate())
} | go | func (h *Hermes) GenerateHTML(email Email) (string, error) {
err := setDefaultHermesValues(h)
if err != nil {
return "", err
}
return h.generateTemplate(email, h.Theme.HTMLTemplate())
} | [
"func",
"(",
"h",
"*",
"Hermes",
")",
"GenerateHTML",
"(",
"email",
"Email",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"setDefaultHermesValues",
"(",
"h",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"h",
".",
"generateTemplate",
"(",
"email",
",",
"h",
".",
"Theme",
".",
"HTMLTemplate",
"(",
")",
")",
"\n",
"}"
] | // GenerateHTML generates the email body from data to an HTML Reader
// This is for modern email clients | [
"GenerateHTML",
"generates",
"the",
"email",
"body",
"from",
"data",
"to",
"an",
"HTML",
"Reader",
"This",
"is",
"for",
"modern",
"email",
"clients"
] | 2f49bb14de85f0ec4940c93252d0e3289a59d5bd | https://github.com/matcornic/hermes/blob/2f49bb14de85f0ec4940c93252d0e3289a59d5bd/hermes.go#L163-L169 |
150,397 | matcornic/hermes | hermes.go | GeneratePlainText | func (h *Hermes) GeneratePlainText(email Email) (string, error) {
err := setDefaultHermesValues(h)
if err != nil {
return "", err
}
template, err := h.generateTemplate(email, h.Theme.PlainTextTemplate())
if err != nil {
return "", err
}
return html2text.FromString(template, html2text.Options{PrettyTables: true})
} | go | func (h *Hermes) GeneratePlainText(email Email) (string, error) {
err := setDefaultHermesValues(h)
if err != nil {
return "", err
}
template, err := h.generateTemplate(email, h.Theme.PlainTextTemplate())
if err != nil {
return "", err
}
return html2text.FromString(template, html2text.Options{PrettyTables: true})
} | [
"func",
"(",
"h",
"*",
"Hermes",
")",
"GeneratePlainText",
"(",
"email",
"Email",
")",
"(",
"string",
",",
"error",
")",
"{",
"err",
":=",
"setDefaultHermesValues",
"(",
"h",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"template",
",",
"err",
":=",
"h",
".",
"generateTemplate",
"(",
"email",
",",
"h",
".",
"Theme",
".",
"PlainTextTemplate",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"html2text",
".",
"FromString",
"(",
"template",
",",
"html2text",
".",
"Options",
"{",
"PrettyTables",
":",
"true",
"}",
")",
"\n",
"}"
] | // GeneratePlainText generates the email body from data
// This is for old email clients | [
"GeneratePlainText",
"generates",
"the",
"email",
"body",
"from",
"data",
"This",
"is",
"for",
"old",
"email",
"clients"
] | 2f49bb14de85f0ec4940c93252d0e3289a59d5bd | https://github.com/matcornic/hermes/blob/2f49bb14de85f0ec4940c93252d0e3289a59d5bd/hermes.go#L173-L183 |
150,398 | jordan-wright/email | pool.go | Send | func (p *Pool) Send(e *Email, timeout time.Duration) (err error) {
start := time.Now()
c := p.get(timeout)
if c == nil {
return p.failedToGet(start)
}
defer func() {
p.maybeReplace(err, c)
}()
recipients, err := addressLists(e.To, e.Cc, e.Bcc)
if err != nil {
return
}
msg, err := e.Bytes()
if err != nil {
return
}
from, err := emailOnly(e.From)
if err != nil {
return
}
if err = c.Mail(from); err != nil {
return
}
for _, recip := range recipients {
if err = c.Rcpt(recip); err != nil {
return
}
}
w, err := c.Data()
if err != nil {
return
}
if _, err = w.Write(msg); err != nil {
return
}
err = w.Close()
return
} | go | func (p *Pool) Send(e *Email, timeout time.Duration) (err error) {
start := time.Now()
c := p.get(timeout)
if c == nil {
return p.failedToGet(start)
}
defer func() {
p.maybeReplace(err, c)
}()
recipients, err := addressLists(e.To, e.Cc, e.Bcc)
if err != nil {
return
}
msg, err := e.Bytes()
if err != nil {
return
}
from, err := emailOnly(e.From)
if err != nil {
return
}
if err = c.Mail(from); err != nil {
return
}
for _, recip := range recipients {
if err = c.Rcpt(recip); err != nil {
return
}
}
w, err := c.Data()
if err != nil {
return
}
if _, err = w.Write(msg); err != nil {
return
}
err = w.Close()
return
} | [
"func",
"(",
"p",
"*",
"Pool",
")",
"Send",
"(",
"e",
"*",
"Email",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"err",
"error",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"c",
":=",
"p",
".",
"get",
"(",
"timeout",
")",
"\n",
"if",
"c",
"==",
"nil",
"{",
"return",
"p",
".",
"failedToGet",
"(",
"start",
")",
"\n",
"}",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"p",
".",
"maybeReplace",
"(",
"err",
",",
"c",
")",
"\n",
"}",
"(",
")",
"\n\n",
"recipients",
",",
"err",
":=",
"addressLists",
"(",
"e",
".",
"To",
",",
"e",
".",
"Cc",
",",
"e",
".",
"Bcc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"msg",
",",
"err",
":=",
"e",
".",
"Bytes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"from",
",",
"err",
":=",
"emailOnly",
"(",
"e",
".",
"From",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"c",
".",
"Mail",
"(",
"from",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"recip",
":=",
"range",
"recipients",
"{",
"if",
"err",
"=",
"c",
".",
"Rcpt",
"(",
"recip",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"w",
",",
"err",
":=",
"c",
".",
"Data",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
"=",
"w",
".",
"Write",
"(",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"err",
"=",
"w",
".",
"Close",
"(",
")",
"\n\n",
"return",
"\n",
"}"
] | // Send sends an email via a connection pulled from the Pool. The timeout may
// be <0 to indicate no timeout. Otherwise reaching the timeout will produce
// and error building a connection that occurred while we were waiting, or
// otherwise ErrTimeout. | [
"Send",
"sends",
"an",
"email",
"via",
"a",
"connection",
"pulled",
"from",
"the",
"Pool",
".",
"The",
"timeout",
"may",
"be",
"<0",
"to",
"indicate",
"no",
"timeout",
".",
"Otherwise",
"reaching",
"the",
"timeout",
"will",
"produce",
"and",
"error",
"building",
"a",
"connection",
"that",
"occurred",
"while",
"we",
"were",
"waiting",
"or",
"otherwise",
"ErrTimeout",
"."
] | 3ea4d25e7cf84fe656d10353672a0eba4b919b6d | https://github.com/jordan-wright/email/blob/3ea4d25e7cf84fe656d10353672a0eba4b919b6d/pool.go#L266-L312 |
150,399 | jordan-wright/email | pool.go | Close | func (p *Pool) Close() {
close(p.closing)
for p.created > 0 {
c := <-p.clients
c.Quit()
p.dec()
}
} | go | func (p *Pool) Close() {
close(p.closing)
for p.created > 0 {
c := <-p.clients
c.Quit()
p.dec()
}
} | [
"func",
"(",
"p",
"*",
"Pool",
")",
"Close",
"(",
")",
"{",
"close",
"(",
"p",
".",
"closing",
")",
"\n\n",
"for",
"p",
".",
"created",
">",
"0",
"{",
"c",
":=",
"<-",
"p",
".",
"clients",
"\n",
"c",
".",
"Quit",
"(",
")",
"\n",
"p",
".",
"dec",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Close immediately changes the pool's state so no new connections will be
// created, then gets and closes the existing ones as they become available. | [
"Close",
"immediately",
"changes",
"the",
"pool",
"s",
"state",
"so",
"no",
"new",
"connections",
"will",
"be",
"created",
"then",
"gets",
"and",
"closes",
"the",
"existing",
"ones",
"as",
"they",
"become",
"available",
"."
] | 3ea4d25e7cf84fe656d10353672a0eba4b919b6d | https://github.com/jordan-wright/email/blob/3ea4d25e7cf84fe656d10353672a0eba4b919b6d/pool.go#L344-L352 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.