| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Log(C) = [C, A, B, base, common...] | 131 // Log(C) = [C, A, B, base, common...] |
| 132 // | 132 // |
| 133 func (c *Client) Log(ctx context.Context, repoURL, treeish string, limit int) ([
]Commit, error) { | 133 func (c *Client) Log(ctx context.Context, repoURL, treeish string, limit int) ([
]Commit, error) { |
| 134 repoURL, err := NormalizeRepoURL(repoURL) | 134 repoURL, err := NormalizeRepoURL(repoURL) |
| 135 if err != nil { | 135 if err != nil { |
| 136 return nil, err | 136 return nil, err |
| 137 } | 137 } |
| 138 if limit < 1 { | 138 if limit < 1 { |
| 139 return nil, fmt.Errorf("limit must be at least 1, but %d provide
d", limit) | 139 return nil, fmt.Errorf("limit must be at least 1, but %d provide
d", limit) |
| 140 } | 140 } |
| 141 » subPath := fmt.Sprintf("+log/%s?format=JSON", url.PathEscape(treeish)) | 141 » // TODO(tandrii): s/QueryEscape/PathEscape once AE deployments are Go1.8
+. |
| 142 » subPath := fmt.Sprintf("+log/%s?format=JSON", url.QueryEscape(treeish)) |
| 142 resp := &logResponse{} | 143 resp := &logResponse{} |
| 143 if err := c.get(ctx, repoURL, subPath, resp); err != nil { | 144 if err := c.get(ctx, repoURL, subPath, resp); err != nil { |
| 144 return nil, err | 145 return nil, err |
| 145 } | 146 } |
| 146 result := resp.Log | 147 result := resp.Log |
| 147 for { | 148 for { |
| 148 if resp.Next == "" || len(result) >= limit { | 149 if resp.Next == "" || len(result) >= limit { |
| 149 if len(result) > limit { | 150 if len(result) > limit { |
| 150 result = result[:limit] | 151 result = result[:limit] |
| 151 } | 152 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 func (c *Client) Refs(ctx context.Context, repoURL, refsPath string) (map[string
]string, error) { | 185 func (c *Client) Refs(ctx context.Context, repoURL, refsPath string) (map[string
]string, error) { |
| 185 repoURL, err := NormalizeRepoURL(repoURL) | 186 repoURL, err := NormalizeRepoURL(repoURL) |
| 186 if err != nil { | 187 if err != nil { |
| 187 return nil, err | 188 return nil, err |
| 188 } | 189 } |
| 189 if refsPath != "refs" && !strings.HasPrefix(refsPath, "refs/") { | 190 if refsPath != "refs" && !strings.HasPrefix(refsPath, "refs/") { |
| 190 return nil, fmt.Errorf("refsPath must start with \"refs\": %q",
refsPath) | 191 return nil, fmt.Errorf("refsPath must start with \"refs\": %q",
refsPath) |
| 191 } | 192 } |
| 192 refsPath = strings.TrimRight(refsPath, "/") | 193 refsPath = strings.TrimRight(refsPath, "/") |
| 193 | 194 |
| 194 » subPath := fmt.Sprintf("+%s?format=json", url.PathEscape(refsPath)) | 195 » // TODO(tandrii): s/QueryEscape/PathEscape once AE deployments are Go1.8
+. |
| 196 » subPath := fmt.Sprintf("+%s?format=json", url.QueryEscape(refsPath)) |
| 195 resp := refsResponse{} | 197 resp := refsResponse{} |
| 196 if err := c.get(ctx, repoURL, subPath, &resp); err != nil { | 198 if err := c.get(ctx, repoURL, subPath, &resp); err != nil { |
| 197 return nil, err | 199 return nil, err |
| 198 } | 200 } |
| 199 r := make(map[string]string, len(resp)) | 201 r := make(map[string]string, len(resp)) |
| 200 for ref, v := range resp { | 202 for ref, v := range resp { |
| 201 switch { | 203 switch { |
| 202 case v.Value == "": | 204 case v.Value == "": |
| 203 // Weird case of what looks like hash with a target in a
t least Chromium | 205 // Weird case of what looks like hash with a target in a
t least Chromium |
| 204 // repo. | 206 // repo. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 return errors.Annotate(err, "unexpected response from Gitiles").
Err() | 259 return errors.Annotate(err, "unexpected response from Gitiles").
Err() |
| 258 } | 260 } |
| 259 if cnt != 4 || ")]}'" != string(trash) { | 261 if cnt != 4 || ")]}'" != string(trash) { |
| 260 return errors.New("unexpected response from Gitiles") | 262 return errors.New("unexpected response from Gitiles") |
| 261 } | 263 } |
| 262 if err = json.NewDecoder(r.Body).Decode(result); err != nil { | 264 if err = json.NewDecoder(r.Body).Decode(result); err != nil { |
| 263 return errors.Annotate(err, "failed to decode Gitiles response i
nto %T", result).Err() | 265 return errors.Annotate(err, "failed to decode Gitiles response i
nto %T", result).Err() |
| 264 } | 266 } |
| 265 return nil | 267 return nil |
| 266 } | 268 } |
| OLD | NEW |