forked from src-d/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package git | ||
|
||
import ( | ||
"syscall" | ||
"time" | ||
|
||
"gopkg.in/src-d/go-git.v4/plumbing/format/index" | ||
) | ||
|
||
func init() { | ||
fillSystemInfo = func(e *index.Entry, sys interface{}) { | ||
if os, ok := sys.(*syscall.Dir); ok { | ||
// Plan 9 doesn't have a CreatedAt field. | ||
e.CreatedAt = time.Unix(int64(os.Mtime), 0) | ||
|
||
e.Dev = uint32(os.Dev) | ||
|
||
// Plan 9 has no Inode. | ||
// ext2srv(4) appears to store Inode in Qid.Path. | ||
e.Inode = uint32(os.Qid.Path) | ||
|
||
// Plan 9 has string UID/GID | ||
e.GID = 0 | ||
e.UID = 0 | ||
} | ||
} | ||
} | ||
|
||
func isSymlinkWindowsNonAdmin(err error) bool { | ||
return true | ||
} |