aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem
diff options
context:
space:
mode:
authorJeremy Stribling <strib@alum.mit.edu>2017-11-03 10:47:46 -0700
committerJeremy Stribling <strib@alum.mit.edu>2017-11-29 10:38:37 -0800
commita6202cacd12aa5ee20c54aff799b0e91330526c5 (patch)
tree13053067662ea7041df01ed79512c1d354b5d5f9 /storage/filesystem
parentd50161181583f7767038de58eff8ee204de7646d (diff)
downloadgo-git-a6202cacd12aa5ee20c54aff799b0e91330526c5.tar.gz
dotgit: use bufio for PackRefs
Suggested by taruti. Issue: #13
Diffstat (limited to 'storage/filesystem')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go18
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