From a6202cacd12aa5ee20c54aff799b0e91330526c5 Mon Sep 17 00:00:00 2001 From: Jeremy Stribling Date: Fri, 3 Nov 2017 10:47:46 -0700 Subject: dotgit: use bufio for PackRefs Suggested by taruti. Issue: #13 --- storage/filesystem/internal/dotgit/dotgit.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'storage/filesystem/internal') 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 -- cgit