Skip to content

Commit aa267d2

Browse files
delimiters can be byte slices
1 parent 2f3908c commit aa267d2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

modules/git/foreachref/format.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"strings"
1212
)
1313

14-
const (
15-
nullChar = "\x00"
16-
dualNullChar = "\x00\x00"
14+
var (
15+
nullChar = []byte("\x00")
16+
dualNullChar = []byte("\x00\x00")
1717
)
1818

1919
// Format supports specifying and parsing an output format for 'git
@@ -26,12 +26,12 @@ type Format struct {
2626
// fieldDelim is the character sequence that is used to separate fields
2727
// for each reference. fieldDelim and refDelim should be selected to not
2828
// interfere with each other and to not be present in field values.
29-
fieldDelim string
29+
fieldDelim []byte
3030
// refDelim is the character sequence used to separate reference from
3131
// each other in the output. fieldDelim and refDelim should be selected
3232
// to not interfere with each other and to not be present in field
3333
// values.
34-
refDelim string
34+
refDelim []byte
3535
}
3636

3737
// NewFormat creates a forEachRefFormat using the specified fieldNames. See
@@ -70,7 +70,7 @@ func (f Format) Parser(r io.Reader) *Parser {
7070

7171
// hexEscaped produces hex-escpaed characters from a string. For example, "\n\0"
7272
// would turn into "%0a%00".
73-
func (f Format) hexEscaped(delim string) string {
73+
func (f Format) hexEscaped(delim []byte) string {
7474
escaped := ""
7575
for i := 0; i < len(delim); i++ {
7676
escaped += "%" + hex.EncodeToString([]byte{delim[i]})

modules/git/foreachref/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (p *Parser) parseRef(refBlock string) (map[string]string, error) {
9393

9494
fieldValues := make(map[string]string)
9595

96-
fields := strings.Split(refBlock, p.format.fieldDelim)
96+
fields := strings.Split(refBlock, string(p.format.fieldDelim))
9797
if len(fields) != len(p.format.fieldNames) {
9898
return nil, fmt.Errorf("unexpected number of reference fields: wanted %d, was %d",
9999
len(fields), len(p.format.fieldNames))

0 commit comments

Comments
 (0)