From 13ac778ef2f757c7cd636b4336a2bd6c8f403b43 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 15 Dec 2009 15:40:16 -0800 Subject: 1) Change default gofmt default settings for parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 4th set of files. R=rsc CC=golang-dev http://codereview.appspot.com/180049 --- src/pkg/patch/git.go | 78 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'src/pkg/patch/git.go') diff --git a/src/pkg/patch/git.go b/src/pkg/patch/git.go index 7fae216c4..f366a3e05 100644 --- a/src/pkg/patch/git.go +++ b/src/pkg/patch/git.go @@ -5,13 +5,13 @@ package patch import ( - "bytes"; - "compress/zlib"; - "crypto/sha1"; - "encoding/git85"; - "fmt"; - "io"; - "os"; + "bytes" + "compress/zlib" + "crypto/sha1" + "encoding/git85" + "fmt" + "io" + "os" ) func gitSHA1(data []byte) []byte { @@ -19,18 +19,18 @@ func gitSHA1(data []byte) []byte { // special case: 0 length is all zeros sum return make([]byte, 20) } - h := sha1.New(); - fmt.Fprintf(h, "blob %d\x00", len(data)); - h.Write(data); - return h.Sum(); + h := sha1.New() + fmt.Fprintf(h, "blob %d\x00", len(data)) + h.Write(data) + return h.Sum() } // BUG(rsc): The Git binary delta format is not implemented, only Git binary literals. // GitBinaryLiteral represents a Git binary literal diff. type GitBinaryLiteral struct { - OldSHA1 []byte; // if non-empty, the SHA1 hash of the original - New []byte; // the new contents + OldSHA1 []byte // if non-empty, the SHA1 hash of the original + New []byte // the new contents } // Apply implements the Diff interface's Apply method. @@ -38,7 +38,7 @@ func (d *GitBinaryLiteral) Apply(old []byte) ([]byte, os.Error) { if sum := gitSHA1(old); !bytes.HasPrefix(sum, d.OldSHA1) { return nil, ErrPatchFailure } - return d.New, nil; + return d.New, nil } func unhex(c byte) uint8 { @@ -50,60 +50,60 @@ func unhex(c byte) uint8 { case 'A' <= c && c <= 'F': return c - 'A' + 10 } - return 255; + return 255 } func getHex(s []byte) (data []byte, rest []byte) { - n := 0; + n := 0 for n < len(s) && unhex(s[n]) != 255 { n++ } - n &^= 1; // Only take an even number of hex digits. - data = make([]byte, n/2); + 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]) } - rest = s[n:]; - return; + rest = s[n:] + return } // ParseGitBinary parses raw as a Git binary patch. func ParseGitBinary(raw []byte) (Diff, os.Error) { - var oldSHA1, newSHA1 []byte; - var sawBinary bool; + var oldSHA1, newSHA1 []byte + var sawBinary bool for { - var first []byte; - first, raw, _ = getLine(raw, 1); - first = bytes.TrimSpace(first); + var first []byte + first, raw, _ = getLine(raw, 1) + first = bytes.TrimSpace(first) if s, ok := skip(first, "index "); ok { - oldSHA1, s = getHex(s); + oldSHA1, s = getHex(s) if s, ok = skip(s, ".."); !ok { continue } - newSHA1, s = getHex(s); - continue; + newSHA1, s = getHex(s) + continue } if _, ok := skip(first, "GIT binary patch"); ok { - sawBinary = true; - continue; + sawBinary = true + continue } if n, _, ok := atoi(first, "literal ", 10); ok && sawBinary { - data := make([]byte, n); - d := git85.NewDecoder(bytes.NewBuffer(raw)); - z, err := zlib.NewInflater(d); + data := make([]byte, n) + d := git85.NewDecoder(bytes.NewBuffer(raw)) + z, err := zlib.NewInflater(d) if err != nil { return nil, err } - defer z.Close(); + defer z.Close() if _, err = io.ReadFull(z, data); err != nil { if err == os.EOF { err = io.ErrUnexpectedEOF } - return nil, err; + return nil, err } - var buf [1]byte; - m, err := z.Read(&buf); + 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") } @@ -111,11 +111,11 @@ func ParseGitBinary(raw []byte) (Diff, os.Error) { if sum := gitSHA1(data); !bytes.HasPrefix(sum, newSHA1) { return nil, os.NewError("Git binary literal SHA1 mismatch") } - return &GitBinaryLiteral{oldSHA1, data}, nil; + return &GitBinaryLiteral{oldSHA1, data}, nil } if !sawBinary { return nil, os.NewError("unexpected Git patch header: " + string(first)) } } - panic("unreachable"); + panic("unreachable") } -- cgit v1.2.3