summaryrefslogtreecommitdiff
path: root/src/pkg/patch
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-11-09 12:07:39 -0800
committerRobert Griesemer <gri@golang.org>2009-11-09 12:07:39 -0800
commite940edc7a026293153ba09ece40e8092a2fc2463 (patch)
treec94a425c84b7a48f91a5d76a222effad70c9a88c /src/pkg/patch
parente067f862f1774ab89a2096a88571a94e3b9cd353 (diff)
downloadgolang-e940edc7a026293153ba09ece40e8092a2fc2463.tar.gz
remove semis after statements in one-statement statement lists
R=rsc, r http://go/go-review/1025029
Diffstat (limited to 'src/pkg/patch')
-rw-r--r--src/pkg/patch/apply.go4
-rw-r--r--src/pkg/patch/git.go26
-rw-r--r--src/pkg/patch/patch.go34
-rw-r--r--src/pkg/patch/patch_test.go2
-rw-r--r--src/pkg/patch/textdiff.go48
5 files changed, 57 insertions, 57 deletions
diff --git a/src/pkg/patch/apply.go b/src/pkg/patch/apply.go
index 154133028..fc82f93cc 100644
--- a/src/pkg/patch/apply.go
+++ b/src/pkg/patch/apply.go
@@ -40,12 +40,12 @@ func (set *Set) Apply(readFile func(string) ([]byte, os.Error)) ([]Op, os.Error)
if f.Src != "" {
old, err = readFile(f.Src);
if err != nil {
- return nil, &os.PathError{string(f.Verb), f.Src, err};
+ return nil, &os.PathError{string(f.Verb), f.Src, err}
}
}
o.Data, err = f.Diff.Apply(old);
if err != nil {
- return nil, &os.PathError{string(f.Verb), f.Src, err};
+ return nil, &os.PathError{string(f.Verb), f.Src, err}
}
}
}
diff --git a/src/pkg/patch/git.go b/src/pkg/patch/git.go
index fd03f4a92..f9335cc45 100644
--- a/src/pkg/patch/git.go
+++ b/src/pkg/patch/git.go
@@ -17,7 +17,7 @@ import (
func gitSHA1(data []byte) []byte {
if len(data) == 0 {
// special case: 0 length is all zeros sum
- return make([]byte, 20);
+ return make([]byte, 20)
}
h := sha1.New();
fmt.Fprintf(h, "blob %d\x00", len(data));
@@ -36,7 +36,7 @@ type GITBinaryLiteral struct {
// Apply implements the Diff interface's Apply method.
func (d *GITBinaryLiteral) Apply(old []byte) ([]byte, os.Error) {
if sum := gitSHA1(old); !bytes.HasPrefix(sum, d.OldSHA1) {
- return nil, ErrPatchFailure;
+ return nil, ErrPatchFailure
}
return d.New, nil;
}
@@ -44,11 +44,11 @@ func (d *GITBinaryLiteral) Apply(old []byte) ([]byte, os.Error) {
func unhex(c byte) uint8 {
switch {
case '0' <= c && c <= '9':
- return c-'0';
+ return c-'0'
case 'a' <= c && c <= 'f':
- return c-'a'+10;
+ return c-'a'+10
case 'A' <= c && c <= 'F':
- return c-'A'+10;
+ return c-'A'+10
}
return 255;
}
@@ -56,12 +56,12 @@ func unhex(c byte) uint8 {
func getHex(s []byte) (data []byte, rest []byte) {
n := 0;
for n < len(s) && unhex(s[n]) != 255 {
- n++;
+ n++
}
n &^= 1; // Only take an even number of hex digits.
data = make([]byte, n/2);
for i := range data {
- data[i] = unhex(s[2*i])<<4 | unhex(s[2*i + 1]);
+ data[i] = unhex(s[2*i])<<4 | unhex(s[2*i + 1])
}
rest = s[n:len(s)];
return;
@@ -79,7 +79,7 @@ func ParseGITBinary(raw []byte) (Diff, os.Error) {
if s, ok := skip(first, "index "); ok {
oldSHA1, s = getHex(s);
if s, ok = skip(s, ".."); !ok {
- continue;
+ continue
}
newSHA1, s = getHex(s);
continue;
@@ -93,28 +93,28 @@ func ParseGITBinary(raw []byte) (Diff, os.Error) {
d := git85.NewDecoder(bytes.NewBuffer(raw));
z, err := zlib.NewInflater(d);
if err != nil {
- return nil, err;
+ return nil, err
}
defer z.Close();
if _, err = io.ReadFull(z, data); err != nil {
if err == os.EOF {
- err = io.ErrUnexpectedEOF;
+ err = io.ErrUnexpectedEOF
}
return nil, err;
}
var buf [1]byte;
m, err := z.Read(&buf);
if m != 0 || err != os.EOF {
- return nil, os.NewError("GIT binary literal longer than expected");
+ return nil, os.NewError("GIT binary literal longer than expected")
}
if sum := gitSHA1(data); !bytes.HasPrefix(sum, newSHA1) {
- return nil, os.NewError("GIT binary literal SHA1 mismatch");
+ return nil, os.NewError("GIT binary literal SHA1 mismatch")
}
return &GITBinaryLiteral{oldSHA1, data}, nil;
}
if !sawBinary {
- return nil, os.NewError("unexpected GIT patch header: " + string(first));
+ return nil, os.NewError("unexpected GIT patch header: " + string(first))
}
}
panic("unreachable");
diff --git a/src/pkg/patch/patch.go b/src/pkg/patch/patch.go
index e8ed627f7..25f03fe61 100644
--- a/src/pkg/patch/patch.go
+++ b/src/pkg/patch/patch.go
@@ -57,7 +57,7 @@ var NoDiff Diff = noDiffType(0)
type noDiffType int
func (noDiffType) Apply(old []byte) ([]byte, os.Error) {
- return old, nil;
+ return old, nil
}
// A SyntaxError represents a syntax error encountered while parsing a patch.
@@ -84,7 +84,7 @@ func Parse(text []byte) (*Set, os.Error) {
// First look for Index: lines. If none, fall back on diff lines.
text, files := sections(text, "Index: ");
if len(files) == 0 {
- text, files = sections(text, "diff ");
+ text, files = sections(text, "diff ")
}
set := &Set{string(text), make([]*File, len(files))};
@@ -114,7 +114,7 @@ func Parse(text []byte) (*Set, os.Error) {
HaveName:
p.Dst = path.Clean(p.Dst);
if strings.HasPrefix(p.Dst, "../") || strings.HasPrefix(p.Dst, "/") {
- return nil, SyntaxError("invalid path: " + p.Dst);
+ return nil, SyntaxError("invalid path: " + p.Dst)
}
// Parse header lines giving file information:
@@ -180,29 +180,29 @@ func Parse(text []byte) (*Set, os.Error) {
// Hg prints
// Binary file foo has changed
// when deleting a binary file.
- continue;
+ continue
}
if s, ok := skip(l, "RCS file: "); ok && len(s) > 0 {
// CVS prints
// RCS file: /cvs/plan9/bin/yesterday,v
// retrieving revision 1.1
// for each file.
- continue;
+ continue
}
if s, ok := skip(l, "retrieving revision "); ok && len(s) > 0 {
// CVS prints
// RCS file: /cvs/plan9/bin/yesterday,v
// retrieving revision 1.1
// for each file.
- continue;
+ continue
}
if hasPrefix(l, "===") || hasPrefix(l, "---") || hasPrefix(l, "+++") || hasPrefix(l, "diff ") {
- continue;
+ continue
}
if hasPrefix(l, "@@ -") {
diff, err := ParseTextDiff(oldraw);
if err != nil {
- return nil, err;
+ return nil, err
}
p.Diff = diff;
break;
@@ -210,7 +210,7 @@ func Parse(text []byte) (*Set, os.Error) {
if hasPrefix(l, "index ") || hasPrefix(l, "GIT binary patch") {
diff, err := ParseGITBinary(oldraw);
if err != nil {
- return nil, err;
+ return nil, err
}
p.Diff = diff;
break;
@@ -218,10 +218,10 @@ func Parse(text []byte) (*Set, os.Error) {
return nil, SyntaxError("unexpected patch header line: " + string(l));
}
if p.Diff == nil {
- p.Diff = NoDiff;
+ p.Diff = NoDiff
}
if p.Verb == Edit {
- p.Src = p.Dst;
+ p.Src = p.Dst
}
}
@@ -254,11 +254,11 @@ func sections(text []byte, prefix string) ([]byte, [][]byte) {
n := 0;
for b := text; ; {
if hasPrefix(b, prefix) {
- n++;
+ n++
}
nl := bytes.Index(b, newline);
if nl < 0 {
- break;
+ break
}
b = b[nl+1 : len(b)];
}
@@ -285,7 +285,7 @@ func sections(text []byte, prefix string) ([]byte, [][]byte) {
// s with that prefix removed and ok == true.
func skip(s []byte, t string) (ss []byte, ok bool) {
if len(s) < len(t) || string(s[0:len(t)]) != t {
- return nil, false;
+ return nil, false
}
return s[len(t):len(s)], true;
}
@@ -296,14 +296,14 @@ func skip(s []byte, t string) (ss []byte, ok bool) {
// prefix and the digits removed.
func atoi(s []byte, t string, base int) (n int, ss []byte, ok bool) {
if s, ok = skip(s, t); !ok {
- return;
+ return
}
var i int;
for i = 0; i < len(s) && '0' <= s[i] && s[i] <= byte('0'+base-1); i++ {
- n = n*base + int(s[i]-'0');
+ n = n*base + int(s[i]-'0')
}
if i == 0 {
- return;
+ return
}
return n, s[i:len(s)], true;
}
diff --git a/src/pkg/patch/patch_test.go b/src/pkg/patch/patch_test.go
index b4c64b31b..dd610eed6 100644
--- a/src/pkg/patch/patch_test.go
+++ b/src/pkg/patch/patch_test.go
@@ -34,7 +34,7 @@ func TestFileApply(t *testing.T) {
continue;
}
if s := string(new); s != test.out {
- t.Errorf("#%d:\n--- have\n%s--- want\n%s", i, s, test.out);
+ t.Errorf("#%d:\n--- have\n%s--- want\n%s", i, s, test.out)
}
}
}
diff --git a/src/pkg/patch/textdiff.go b/src/pkg/patch/textdiff.go
index db8527682..ddf3b2606 100644
--- a/src/pkg/patch/textdiff.go
+++ b/src/pkg/patch/textdiff.go
@@ -32,32 +32,32 @@ func ParseTextDiff(raw []byte) (TextDiff, os.Error) {
s := chunkHeader;
if oldLine, s, ok = atoi(s, "@@ -", 10); !ok {
ErrChunkHdr:
- return nil, SyntaxError("unexpected chunk header line: " + string(chunkHeader));
+ return nil, SyntaxError("unexpected chunk header line: " + string(chunkHeader))
}
if len(s) == 0 || s[0] != ',' {
- oldCount = 1;
+ oldCount = 1
} else if oldCount, s, ok = atoi(s, ",", 10); !ok {
- goto ErrChunkHdr;
+ goto ErrChunkHdr
}
if newLine, s, ok = atoi(s, " +", 10); !ok {
- goto ErrChunkHdr;
+ goto ErrChunkHdr
}
if len(s) == 0 || s[0] != ',' {
- newCount = 1;
+ newCount = 1
} else if newCount, s, ok = atoi(s, ",", 10); !ok {
- goto ErrChunkHdr;
+ goto ErrChunkHdr
}
if !hasPrefix(s, " @@") {
- goto ErrChunkHdr;
+ goto ErrChunkHdr
}
// Special case: for created or deleted files, the empty half
// is given as starting at line 0. Translate to line 1.
if oldCount == 0 && oldLine == 0 {
- oldLine = 1;
+ oldLine = 1
}
if newCount == 0 && newLine == 0 {
- newLine = 1;
+ newLine = 1
}
// Count lines in text
@@ -68,18 +68,18 @@ func ParseTextDiff(raw []byte) (TextDiff, os.Error) {
for _, l := range chunk {
if nold == oldCount && nnew == newCount && (len(l) == 0 || l[0] != '\\') {
if len(bytes.TrimSpace(l)) != 0 {
- return nil, SyntaxError("too many chunk lines");
+ return nil, SyntaxError("too many chunk lines")
}
continue;
}
if len(l) == 0 {
- return nil, SyntaxError("empty chunk line");
+ return nil, SyntaxError("empty chunk line")
}
switch l[0] {
case '+':
- nnew++;
+ nnew++
case '-':
- nold++;
+ nold++
case ' ':
nnew++;
nold++;
@@ -87,30 +87,30 @@ func ParseTextDiff(raw []byte) (TextDiff, os.Error) {
if _, ok := skip(l, "\\ No newline at end of file"); ok {
switch lastch {
case '-':
- dropOldNL = true;
+ dropOldNL = true
case '+':
- dropNewNL = true;
+ dropNewNL = true
case ' ':
dropOldNL = true;
dropNewNL = true;
default:
- return nil, SyntaxError("message `\\ No newline at end of file' out of context");
+ return nil, SyntaxError("message `\\ No newline at end of file' out of context")
}
break;
}
fallthrough;
default:
- return nil, SyntaxError("unexpected chunk line: " + string(l));
+ return nil, SyntaxError("unexpected chunk line: " + string(l))
}
lastch = l[0];
}
// Does it match the header?
if nold != oldCount || nnew != newCount {
- return nil, SyntaxError("chunk header does not match line count: " + string(chunkHeader));
+ return nil, SyntaxError("chunk header does not match line count: " + string(chunkHeader))
}
if oldLine+delta != newLine {
- return nil, SyntaxError("chunk delta is out of sync with previous chunks");
+ return nil, SyntaxError("chunk delta is out of sync with previous chunks")
}
delta += nnew-nold;
c.Line = oldLine;
@@ -120,11 +120,11 @@ func ParseTextDiff(raw []byte) (TextDiff, os.Error) {
nnew = 0;
for _, l := range chunk {
if nold == oldCount && nnew == newCount {
- break;
+ break
}
ch, l := l[0], l[1:len(l)];
if ch == '\\' {
- continue;
+ continue
}
if ch != '+' {
old.Write(l);
@@ -138,10 +138,10 @@ func ParseTextDiff(raw []byte) (TextDiff, os.Error) {
c.Old = old.Bytes();
c.New = new.Bytes();
if dropOldNL {
- c.Old = c.Old[0 : len(c.Old)-1];
+ c.Old = c.Old[0 : len(c.Old)-1]
}
if dropNewNL {
- c.New = c.New[0 : len(c.New)-1];
+ c.New = c.New[0 : len(c.New)-1]
}
}
return diff, nil;
@@ -159,7 +159,7 @@ func (d TextDiff) Apply(data []byte) ([]byte, os.Error) {
var prefix []byte;
prefix, data, ok = getLine(data, c.Line - line);
if !ok || !bytes.HasPrefix(data, c.Old) {
- return nil, ErrPatchFailure;
+ return nil, ErrPatchFailure
}
buf.Write(prefix);
data = data[len(c.Old):len(data)];