Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 79262fc

Browse files
committed
Merge remote-tracking branch 'origin/master' into commitgraph-obj
2 parents 5f53b23 + e17ee11 commit 79262fc

File tree

5 files changed

+96
-53
lines changed

5 files changed

+96
-53
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module gopkg.in/src-d/go-git.v4
33
require (
44
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 // indirect
55
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 // indirect
6+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
67
github.com/davecgh/go-spew v1.1.1 // indirect
78
github.com/emirpasic/gods v1.12.0
89
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
@@ -19,7 +20,7 @@ require (
1920
github.com/stretchr/testify v1.3.0 // indirect
2021
github.com/xanzy/ssh-agent v0.2.1
2122
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd
22-
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6 // indirect
23+
golang.org/x/net v0.0.0-20190502183928-7f726cade0ab
2324
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
2425
golang.org/x/text v0.3.0
2526
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBb
22
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
33
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
44
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
5+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
6+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
57
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
68
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
79
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -48,6 +50,8 @@ golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd/go.mod h1:yigFU9vqHzYiE8U
4850
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
4951
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6 h1:HdqqaWmYAUI7/dmByKKEw+yxDksGSo+9GjkUc9Zp34E=
5052
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
53+
golang.org/x/net v0.0.0-20190502183928-7f726cade0ab h1:9RfW3ktsOZxgo9YNbBAjq1FWzc/igwEcUzZz8IXgSbk=
54+
golang.org/x/net v0.0.0-20190502183928-7f726cade0ab/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
5155
golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9 h1:lkiLiLBHGoH3XnqSLUIaBsilGMUjI+Uy2Xu2JLUtTas=
5256
golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5357
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

plumbing/format/idxfile/idxfile.go

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import (
55
"io"
66
"sort"
77

8+
encbin "encoding/binary"
9+
810
"gopkg.in/src-d/go-git.v4/plumbing"
9-
"gopkg.in/src-d/go-git.v4/utils/binary"
1011
)
1112

1213
const (
@@ -122,41 +123,32 @@ func (idx *MemoryIndex) FindOffset(h plumbing.Hash) (int64, error) {
122123
return 0, plumbing.ErrObjectNotFound
123124
}
124125

125-
offset, err := idx.getOffset(k, i)
126+
offset := idx.getOffset(k, i)
126127

127128
if !idx.offsetHashIsFull {
128129
// Save the offset for reverse lookup
129130
if idx.offsetHash == nil {
130131
idx.offsetHash = make(map[int64]plumbing.Hash)
131132
}
132-
idx.offsetHash[offset] = h
133+
idx.offsetHash[int64(offset)] = h
133134
}
134135

135-
return offset, err
136+
return int64(offset), nil
136137
}
137138

138139
const isO64Mask = uint64(1) << 31
139140

140-
func (idx *MemoryIndex) getOffset(firstLevel, secondLevel int) (int64, error) {
141+
func (idx *MemoryIndex) getOffset(firstLevel, secondLevel int) uint64 {
141142
offset := secondLevel << 2
142-
buf := bytes.NewBuffer(idx.Offset32[firstLevel][offset : offset+4])
143-
ofs, err := binary.ReadUint32(buf)
144-
if err != nil {
145-
return -1, err
146-
}
143+
ofs := encbin.BigEndian.Uint32(idx.Offset32[firstLevel][offset : offset+4])
147144

148145
if (uint64(ofs) & isO64Mask) != 0 {
149146
offset := 8 * (uint64(ofs) & ^isO64Mask)
150-
buf := bytes.NewBuffer(idx.Offset64[offset : offset+8])
151-
n, err := binary.ReadUint64(buf)
152-
if err != nil {
153-
return -1, err
154-
}
155-
156-
return int64(n), nil
147+
n := encbin.BigEndian.Uint64(idx.Offset64[offset : offset+8])
148+
return n
157149
}
158150

159-
return int64(ofs), nil
151+
return uint64(ofs)
160152
}
161153

162154
// FindCRC32 implements the Index interface.
@@ -167,13 +159,12 @@ func (idx *MemoryIndex) FindCRC32(h plumbing.Hash) (uint32, error) {
167159
return 0, plumbing.ErrObjectNotFound
168160
}
169161

170-
return idx.getCRC32(k, i)
162+
return idx.getCRC32(k, i), nil
171163
}
172164

173-
func (idx *MemoryIndex) getCRC32(firstLevel, secondLevel int) (uint32, error) {
165+
func (idx *MemoryIndex) getCRC32(firstLevel, secondLevel int) uint32 {
174166
offset := secondLevel << 2
175-
buf := bytes.NewBuffer(idx.CRC32[firstLevel][offset : offset+4])
176-
return binary.ReadUint32(buf)
167+
return encbin.BigEndian.Uint32(idx.CRC32[firstLevel][offset : offset+4])
177168
}
178169

179170
// FindHash implements the Index interface.
@@ -213,22 +204,19 @@ func (idx *MemoryIndex) genOffsetHash() error {
213204
idx.offsetHash = make(map[int64]plumbing.Hash, count)
214205
idx.offsetHashIsFull = true
215206

216-
iter, err := idx.Entries()
217-
if err != nil {
218-
return err
219-
}
220-
221-
for {
222-
entry, err := iter.Next()
223-
if err != nil {
224-
if err == io.EOF {
225-
return nil
226-
}
227-
return err
207+
var hash plumbing.Hash
208+
i := uint32(0)
209+
for firstLevel, fanoutValue := range idx.Fanout {
210+
mappedFirstLevel := idx.FanoutMapping[firstLevel]
211+
for secondLevel := uint32(0); i < fanoutValue; i++ {
212+
copy(hash[:], idx.Names[mappedFirstLevel][secondLevel*objectIDLength:])
213+
offset := int64(idx.getOffset(mappedFirstLevel, int(secondLevel)))
214+
idx.offsetHash[offset] = hash
215+
secondLevel++
228216
}
229-
230-
idx.offsetHash[int64(entry.Offset)] = entry.Hash
231217
}
218+
219+
return nil
232220
}
233221

234222
// Count implements the Index interface.
@@ -297,22 +285,11 @@ func (i *idxfileEntryIter) Next() (*Entry, error) {
297285
continue
298286
}
299287

288+
mappedFirstLevel := i.idx.FanoutMapping[i.firstLevel]
300289
entry := new(Entry)
301-
ofs := i.secondLevel * objectIDLength
302-
copy(entry.Hash[:], i.idx.Names[i.idx.FanoutMapping[i.firstLevel]][ofs:])
303-
304-
pos := i.idx.FanoutMapping[entry.Hash[0]]
305-
306-
offset, err := i.idx.getOffset(pos, i.secondLevel)
307-
if err != nil {
308-
return nil, err
309-
}
310-
entry.Offset = uint64(offset)
311-
312-
entry.CRC32, err = i.idx.getCRC32(pos, i.secondLevel)
313-
if err != nil {
314-
return nil, err
315-
}
290+
copy(entry.Hash[:], i.idx.Names[mappedFirstLevel][i.secondLevel*objectIDLength:])
291+
entry.Offset = i.idx.getOffset(mappedFirstLevel, i.secondLevel)
292+
entry.CRC32 = i.idx.getCRC32(mappedFirstLevel, i.secondLevel)
316293

317294
i.secondLevel++
318295
i.total++

plumbing/transport/ssh/common.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package ssh
33

44
import (
5+
"context"
56
"fmt"
67
"reflect"
78
"strconv"
@@ -11,6 +12,7 @@ import (
1112

1213
"github.com/kevinburke/ssh_config"
1314
"golang.org/x/crypto/ssh"
15+
"golang.org/x/net/proxy"
1416
)
1517

1618
// DefaultClient is the default SSH client.
@@ -115,7 +117,7 @@ func (c *command) connect() error {
115117

116118
overrideConfig(c.config, config)
117119

118-
c.client, err = ssh.Dial("tcp", c.getHostWithPort(), config)
120+
c.client, err = dial("tcp", c.getHostWithPort(), config)
119121
if err != nil {
120122
return err
121123
}
@@ -130,6 +132,29 @@ func (c *command) connect() error {
130132
return nil
131133
}
132134

135+
func dial(network, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
136+
var (
137+
ctx = context.Background()
138+
cancel context.CancelFunc
139+
)
140+
if config.Timeout > 0 {
141+
ctx, cancel = context.WithTimeout(ctx, config.Timeout)
142+
} else {
143+
ctx, cancel = context.WithCancel(ctx)
144+
}
145+
defer cancel()
146+
147+
conn, err := proxy.Dial(ctx, network, addr)
148+
if err != nil {
149+
return nil, err
150+
}
151+
c, chans, reqs, err := ssh.NewClientConn(conn, addr, config)
152+
if err != nil {
153+
return nil, err
154+
}
155+
return ssh.NewClient(c, chans, reqs), nil
156+
}
157+
133158
func (c *command) getHostWithPort() string {
134159
if addr, found := c.doGetHostWithPortFromSSHConfig(); found {
135160
return addr
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ssh
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net"
7+
"os"
8+
9+
"github.com/armon/go-socks5"
10+
. "gopkg.in/check.v1"
11+
)
12+
13+
type ProxySuite struct {
14+
UploadPackSuite
15+
}
16+
17+
var _ = Suite(&ProxySuite{})
18+
19+
func (s *ProxySuite) SetUpSuite(c *C) {
20+
s.UploadPackSuite.SetUpSuite(c)
21+
22+
l, err := net.Listen("tcp", "localhost:0")
23+
c.Assert(err, IsNil)
24+
25+
server, err := socks5.New(&socks5.Config{})
26+
c.Assert(err, IsNil)
27+
28+
port := l.Addr().(*net.TCPAddr).Port
29+
30+
err = os.Setenv("ALL_PROXY", fmt.Sprintf("socks5://localhost:%d", port))
31+
c.Assert(err, IsNil)
32+
33+
go func() {
34+
log.Fatal(server.Serve(l))
35+
}()
36+
}

0 commit comments

Comments
 (0)