diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-03 10:47:46 -0700 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-29 10:38:37 -0800 |
commit | a6202cacd12aa5ee20c54aff799b0e91330526c5 (patch) | |
tree | 13053067662ea7041df01ed79512c1d354b5d5f9 /storage/filesystem/internal/dotgit | |
parent | d50161181583f7767038de58eff8ee204de7646d (diff) | |
download | go-git-a6202cacd12aa5ee20c54aff799b0e91330526c5.tar.gz |
dotgit: use bufio for PackRefs
Suggested by taruti.
Issue: #13
Diffstat (limited to 'storage/filesystem/internal/dotgit')
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit.go | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go index 8b1df3d..9d49945 100644 --- a/storage/filesystem/internal/dotgit/dotgit.go +++ b/storage/filesystem/internal/dotgit/dotgit.go @@ -615,16 +615,9 @@ func (d *DotGit) CountLooseRefs() (int, error) { // packed, plus all tags. func (d *DotGit) PackRefs() (err error) { // Lock packed-refs, and create it if it doesn't exist yet. - f, err := d.fs.Open(packedRefsPath) + f, err := d.fs.OpenFile(packedRefsPath, os.O_RDWR|os.O_CREATE, 0600) if err != nil { - if os.IsNotExist(err) { - f, err = d.fs.Create(packedRefsPath) - if err != nil { - return err - } - } else { - return err - } + return err } defer ioutil.CheckClose(f, &err) @@ -659,12 +652,17 @@ func (d *DotGit) PackRefs() (err error) { ioutil.CheckClose(tmp, &err) } }() + w := bufio.NewWriter(tmp) for _, ref := range refs { - _, err := tmp.Write([]byte(ref.String() + "\n")) + _, err := w.WriteString(ref.String() + "\n") if err != nil { return err } } + err = w.Flush() + if err != nil { + return err + } // Rename the temp packed-refs file. doCloseTmp = false |