Skip to content

Commit 1fac4a3

Browse files
committed
Include our own copy of golang.org/x/tools/go/[email protected]
Closes: #1043070
1 parent 2164163 commit 1fac4a3

File tree

8 files changed

+1296
-9
lines changed

8 files changed

+1296
-9
lines changed

debian/copyright

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
22
Source: https://github.com/Debian/dh-make-golang
33
Upstream-Name: dh-make-golang
44

5-
Files:
6-
*
7-
Copyright:
8-
2015-2019 Michael Stapelberg, Google Inc. and contributors
5+
Files: *
6+
Copyright: 2015-2019 Michael Stapelberg, Google Inc. and contributors
97
License: BSD-3-clause
108

11-
Files:
12-
debian/*
13-
Copyright:
14-
2015-2017 Michael Stapelberg <[email protected]>
15-
2016-2019 Dr. Tobias Quathamer <[email protected]>
9+
Files: debian/*
10+
Copyright: 2015-2017 Michael Stapelberg <[email protected]>
11+
2016-2019 Dr. Tobias Quathamer <[email protected]>
1612
License: BSD-3-clause
1713
Comment: Debian packaging is licensed under the same terms as upstream
1814

15+
Files: debian/go/src/golang.org/x/tools/go/vcs/*
16+
Copyright: 2009 The Go Authors
17+
License: BSD-3-clause
18+
1919
License: BSD-3-clause
2020
Copyright © 2015, Michael Stapelberg, Google Inc. and contributors
2121
All rights reserved.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2012 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package vcs
6+
7+
import (
8+
"encoding/xml"
9+
"fmt"
10+
"io"
11+
"strings"
12+
)
13+
14+
// charsetReader returns a reader for the given charset. Currently
15+
// it only supports UTF-8 and ASCII. Otherwise, it returns a meaningful
16+
// error which is printed by go get, so the user can find why the package
17+
// wasn't downloaded if the encoding is not supported. Note that, in
18+
// order to reduce potential errors, ASCII is treated as UTF-8 (i.e. characters
19+
// greater than 0x7f are not rejected).
20+
func charsetReader(charset string, input io.Reader) (io.Reader, error) {
21+
switch strings.ToLower(charset) {
22+
case "ascii":
23+
return input, nil
24+
default:
25+
return nil, fmt.Errorf("can't decode XML document using charset %q", charset)
26+
}
27+
}
28+
29+
// parseMetaGoImports returns meta imports from the HTML in r.
30+
// Parsing ends at the end of the <head> section or the beginning of the <body>.
31+
//
32+
// This copy of cmd/go/internal/vcs.parseMetaGoImports always operates
33+
// in IgnoreMod ModuleMode.
34+
func parseMetaGoImports(r io.Reader) (imports []metaImport, err error) {
35+
d := xml.NewDecoder(r)
36+
d.CharsetReader = charsetReader
37+
d.Strict = false
38+
var t xml.Token
39+
for {
40+
t, err = d.RawToken()
41+
if err != nil {
42+
if err == io.EOF || len(imports) > 0 {
43+
err = nil
44+
}
45+
return
46+
}
47+
if e, ok := t.(xml.StartElement); ok && strings.EqualFold(e.Name.Local, "body") {
48+
return
49+
}
50+
if e, ok := t.(xml.EndElement); ok && strings.EqualFold(e.Name.Local, "head") {
51+
return
52+
}
53+
e, ok := t.(xml.StartElement)
54+
if !ok || !strings.EqualFold(e.Name.Local, "meta") {
55+
continue
56+
}
57+
if attrValue(e.Attr, "name") != "go-import" {
58+
continue
59+
}
60+
if f := strings.Fields(attrValue(e.Attr, "content")); len(f) == 3 {
61+
// Ignore VCS type "mod", which is applicable only in module mode.
62+
if f[1] == "mod" {
63+
continue
64+
}
65+
imports = append(imports, metaImport{
66+
Prefix: f[0],
67+
VCS: f[1],
68+
RepoRoot: f[2],
69+
})
70+
}
71+
}
72+
}
73+
74+
// attrValue returns the attribute value for the case-insensitive key
75+
// `name', or the empty string if nothing is found.
76+
func attrValue(attrs []xml.Attr, name string) string {
77+
for _, a := range attrs {
78+
if strings.EqualFold(a.Name.Local, name) {
79+
return a.Value
80+
}
81+
}
82+
return ""
83+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2013 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package vcs
6+
7+
import (
8+
"os"
9+
"strings"
10+
)
11+
12+
// envForDir returns a copy of the environment
13+
// suitable for running in the given directory.
14+
// The environment is the current process's environment
15+
// but with an updated $PWD, so that an os.Getwd in the
16+
// child will be faster.
17+
func envForDir(dir string) []string {
18+
env := os.Environ()
19+
// Internally we only use rooted paths, so dir is rooted.
20+
// Even if dir is not rooted, no harm done.
21+
return mergeEnvLists([]string{"PWD=" + dir}, env)
22+
}
23+
24+
// mergeEnvLists merges the two environment lists such that
25+
// variables with the same name in "in" replace those in "out".
26+
func mergeEnvLists(in, out []string) []string {
27+
NextVar:
28+
for _, inkv := range in {
29+
k := strings.SplitAfterN(inkv, "=", 2)[0]
30+
for i, outkv := range out {
31+
if strings.HasPrefix(outkv, k) {
32+
out[i] = inkv
33+
continue NextVar
34+
}
35+
}
36+
out = append(out, inkv)
37+
}
38+
return out
39+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Deprecated: This module contains one deprecated package.
2+
// See the package deprecation notice for more information.
3+
module golang.org/x/tools/go/vcs
4+
5+
go 1.19
6+
7+
require golang.org/x/sys v0.9.0
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2012 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package vcs
6+
7+
import (
8+
"fmt"
9+
"io"
10+
"io/ioutil"
11+
"log"
12+
"net/http"
13+
"net/url"
14+
)
15+
16+
// httpClient is the default HTTP client, but a variable so it can be
17+
// changed by tests, without modifying http.DefaultClient.
18+
var httpClient = http.DefaultClient
19+
20+
// httpGET returns the data from an HTTP GET request for the given URL.
21+
func httpGET(url string) ([]byte, error) {
22+
resp, err := httpClient.Get(url)
23+
if err != nil {
24+
return nil, err
25+
}
26+
defer resp.Body.Close()
27+
if resp.StatusCode != 200 {
28+
return nil, fmt.Errorf("%s: %s", url, resp.Status)
29+
}
30+
b, err := ioutil.ReadAll(resp.Body)
31+
if err != nil {
32+
return nil, fmt.Errorf("%s: %v", url, err)
33+
}
34+
return b, nil
35+
}
36+
37+
// httpsOrHTTP returns the body of either the importPath's
38+
// https resource or, if unavailable, the http resource.
39+
func httpsOrHTTP(importPath string) (urlStr string, body io.ReadCloser, err error) {
40+
fetch := func(scheme string) (urlStr string, res *http.Response, err error) {
41+
u, err := url.Parse(scheme + "://" + importPath)
42+
if err != nil {
43+
return "", nil, err
44+
}
45+
u.RawQuery = "go-get=1"
46+
urlStr = u.String()
47+
if Verbose {
48+
log.Printf("Fetching %s", urlStr)
49+
}
50+
res, err = httpClient.Get(urlStr)
51+
return
52+
}
53+
closeBody := func(res *http.Response) {
54+
if res != nil {
55+
res.Body.Close()
56+
}
57+
}
58+
urlStr, res, err := fetch("https")
59+
if err != nil || res.StatusCode != 200 {
60+
if Verbose {
61+
if err != nil {
62+
log.Printf("https fetch failed.")
63+
} else {
64+
log.Printf("ignoring https fetch with status code %d", res.StatusCode)
65+
}
66+
}
67+
closeBody(res)
68+
urlStr, res, err = fetch("http")
69+
}
70+
if err != nil {
71+
closeBody(res)
72+
return "", nil, err
73+
}
74+
// Note: accepting a non-200 OK here, so people can serve a
75+
// meta import in their http 404 page.
76+
if Verbose {
77+
log.Printf("Parsing meta tags from %s (status code %d)", urlStr, res.StatusCode)
78+
}
79+
return urlStr, res.Body, nil
80+
}

0 commit comments

Comments
 (0)