Skip to content

Commit cbc339b

Browse files
committed
Add Plan 9 support
Not all the tests pass yet but this makes go-git usable on Plan 9. Please merge this after src-d/go-billy#78. Fixes src-d#756 Signed-off-by: Fazlul Shahriar <fshahriar@gmail.com>
1 parent 1a7db85 commit cbc339b

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
1818
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
1919
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
2020
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
21+
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
2122
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
2223
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
2324
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
@@ -77,6 +78,7 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qq
7778
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7879
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
7980
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
81+
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
8082
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
8183
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
8284
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=

repository_plan9_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package git
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
// preReceiveHook returns the bytes of a pre-receive hook script
9+
// that prints m before exiting successfully
10+
func preReceiveHook(m string) []byte {
11+
return []byte(fmt.Sprintf("#!/bin/rc\necho -n %s\n", quote(m)))
12+
}
13+
14+
const quoteChar = '\''
15+
16+
func needsQuote(s string) bool {
17+
for i := 0; i < len(s); i++ {
18+
c := s[i]
19+
if c == quoteChar || c <= ' ' { // quote, blanks, or control characters
20+
return true
21+
}
22+
}
23+
return false
24+
}
25+
26+
// Quote adds single quotes to s in the style of rc(1) if they are needed.
27+
// The behaviour should be identical to Plan 9's quote(3).
28+
func quote(s string) string {
29+
if s == "" {
30+
return "''"
31+
}
32+
if !needsQuote(s) {
33+
return s
34+
}
35+
var b strings.Builder
36+
b.Grow(10 + len(s)) // Enough room for few quotes
37+
b.WriteByte(quoteChar)
38+
for i := 0; i < len(s); i++ {
39+
c := s[i]
40+
if c == quoteChar {
41+
b.WriteByte(quoteChar)
42+
}
43+
b.WriteByte(c)
44+
}
45+
b.WriteByte(quoteChar)
46+
return b.String()
47+
}

worktree_plan9.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package git
2+
3+
import (
4+
"syscall"
5+
"time"
6+
7+
"gopkg.in/src-d/go-git.v4/plumbing/format/index"
8+
)
9+
10+
func init() {
11+
fillSystemInfo = func(e *index.Entry, sys interface{}) {
12+
if os, ok := sys.(*syscall.Dir); ok {
13+
// Plan 9 doesn't have a CreatedAt field.
14+
e.CreatedAt = time.Unix(int64(os.Mtime), 0)
15+
16+
e.Dev = uint32(os.Dev)
17+
18+
// Plan 9 has no Inode.
19+
// ext2srv(4) appears to store Inode in Qid.Path.
20+
e.Inode = uint32(os.Qid.Path)
21+
22+
// Plan 9 has string UID/GID
23+
e.GID = 0
24+
e.UID = 0
25+
}
26+
}
27+
}
28+
29+
func isSymlinkWindowsNonAdmin(err error) bool {
30+
return true
31+
}

0 commit comments

Comments
 (0)