aboutsummaryrefslogtreecommitdiffstats
path: root/repository_plan9_test.go
diff options
context:
space:
mode:
authorFazlul Shahriar <fshahriar@gmail.com>2019-12-25 17:01:42 -0500
committerFazlul Shahriar <fshahriar@gmail.com>2019-12-25 17:01:42 -0500
commitcbc339b60d5b25ad2b2685de4303f78d0efa51fe (patch)
tree830a4f550c1f1e9cc87dcfda88d3a0b627fc624d /repository_plan9_test.go
parent1a7db85bca7027d90afdb5ce711622aaac9feaed (diff)
downloadgo-git-cbc339b60d5b25ad2b2685de4303f78d0efa51fe.tar.gz
Add Plan 9 support
Not all the tests pass yet but this makes go-git usable on Plan 9. Please merge this after https://github.com/src-d/go-billy/pull/78. Fixes #756 Signed-off-by: Fazlul Shahriar <fshahriar@gmail.com>
Diffstat (limited to 'repository_plan9_test.go')
-rw-r--r--repository_plan9_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/repository_plan9_test.go b/repository_plan9_test.go
new file mode 100644
index 0000000..00ebeed
--- /dev/null
+++ b/repository_plan9_test.go
@@ -0,0 +1,47 @@
+package git
+
+import (
+ "fmt"
+ "strings"
+)
+
+// preReceiveHook returns the bytes of a pre-receive hook script
+// that prints m before exiting successfully
+func preReceiveHook(m string) []byte {
+ return []byte(fmt.Sprintf("#!/bin/rc\necho -n %s\n", quote(m)))
+}
+
+const quoteChar = '\''
+
+func needsQuote(s string) bool {
+ for i := 0; i < len(s); i++ {
+ c := s[i]
+ if c == quoteChar || c <= ' ' { // quote, blanks, or control characters
+ return true
+ }
+ }
+ return false
+}
+
+// Quote adds single quotes to s in the style of rc(1) if they are needed.
+// The behaviour should be identical to Plan 9's quote(3).
+func quote(s string) string {
+ if s == "" {
+ return "''"
+ }
+ if !needsQuote(s) {
+ return s
+ }
+ var b strings.Builder
+ b.Grow(10 + len(s)) // Enough room for few quotes
+ b.WriteByte(quoteChar)
+ for i := 0; i < len(s); i++ {
+ c := s[i]
+ if c == quoteChar {
+ b.WriteByte(quoteChar)
+ }
+ b.WriteByte(c)
+ }
+ b.WriteByte(quoteChar)
+ return b.String()
+}