Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
git-bug
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
MichaelMure
git-bug
Commits
b168d71f
Unverified
Commit
b168d71f
authored
6 years ago
by
Michael Muré
Browse files
Options
Downloads
Patches
Plain Diff
cache: attempt to future-proof the cache file
parent
f8b0b4f5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cache/multi_repo_cache.go
+0
-1
0 additions, 1 deletion
cache/multi_repo_cache.go
cache/repo_cache.go
+36
-22
36 additions, 22 deletions
cache/repo_cache.go
with
36 additions
and
23 deletions
cache/multi_repo_cache.go
+
0
−
1
View file @
b168d71f
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
)
)
const
lockfile
=
"lock"
const
lockfile
=
"lock"
const
excerptsFile
=
"excerpts"
type
MultiRepoCache
struct
{
type
MultiRepoCache
struct
{
repos
map
[
string
]
*
RepoCache
repos
map
[
string
]
*
RepoCache
...
...
This diff is collapsed.
Click to expand it.
cache/repo_cache.go
+
36
−
22
View file @
b168d71f
...
@@ -19,6 +19,9 @@ import (
...
@@ -19,6 +19,9 @@ import (
"github.com/MichaelMure/git-bug/util/process"
"github.com/MichaelMure/git-bug/util/process"
)
)
const
cacheFile
=
"cache"
const
formatVersion
=
1
type
RepoCache
struct
{
type
RepoCache
struct
{
// the underlying repo
// the underlying repo
repo
repository
.
Repo
repo
repository
.
Repo
...
@@ -39,14 +42,14 @@ func NewRepoCache(r repository.Repo) (*RepoCache, error) {
...
@@ -39,14 +42,14 @@ func NewRepoCache(r repository.Repo) (*RepoCache, error) {
return
&
RepoCache
{},
err
return
&
RepoCache
{},
err
}
}
err
=
c
.
load
Excerpts
()
err
=
c
.
load
()
if
err
==
nil
{
if
err
==
nil
{
return
c
,
nil
return
c
,
nil
}
}
c
.
build
AllExcerpt
()
c
.
build
Cache
()
return
c
,
c
.
write
Excerpts
()
return
c
,
c
.
write
()
}
}
// Repository return the underlying repository.
// Repository return the underlying repository.
...
@@ -92,45 +95,56 @@ func (c *RepoCache) bugUpdated(id string) error {
...
@@ -92,45 +95,56 @@ func (c *RepoCache) bugUpdated(id string) error {
c
.
excerpts
[
id
]
=
NewBugExcerpt
(
b
.
bug
,
b
.
Snapshot
())
c
.
excerpts
[
id
]
=
NewBugExcerpt
(
b
.
bug
,
b
.
Snapshot
())
return
c
.
write
Excerpts
()
return
c
.
write
()
}
}
// loadExcerpts will try to read from the disk the bug excerpt file
// load will try to read from the disk the bug cache file
func
(
c
*
RepoCache
)
loadExcerpts
()
error
{
func
(
c
*
RepoCache
)
load
()
error
{
excerptsPath
:=
repoExcerptsFilePath
(
c
.
repo
)
f
,
err
:=
os
.
Open
(
cacheFilePath
(
c
.
repo
))
f
,
err
:=
os
.
Open
(
excerptsPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
decoder
:=
gob
.
NewDecoder
(
f
)
decoder
:=
gob
.
NewDecoder
(
f
)
var
excerpts
map
[
string
]
*
BugExcerpt
aux
:=
struct
{
Version
uint
Excerpts
map
[
string
]
*
BugExcerpt
}{}
err
=
decoder
.
Decode
(
&
excerpts
)
err
=
decoder
.
Decode
(
&
aux
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
c
.
excerpts
=
excerpts
if
aux
.
Version
!=
1
{
return
fmt
.
Errorf
(
"unknown cache format version %v"
,
aux
.
Version
)
}
c
.
excerpts
=
aux
.
Excerpts
return
nil
return
nil
}
}
// write
Excerpts
will serialize on disk the
B
ug
Excerpt array
// write will serialize on disk the
b
ug
cache file
func
(
c
*
RepoCache
)
write
Excerpts
()
error
{
func
(
c
*
RepoCache
)
write
()
error
{
var
data
bytes
.
Buffer
var
data
bytes
.
Buffer
aux
:=
struct
{
Version
uint
Excerpts
map
[
string
]
*
BugExcerpt
}{
Version
:
formatVersion
,
Excerpts
:
c
.
excerpts
,
}
encoder
:=
gob
.
NewEncoder
(
&
data
)
encoder
:=
gob
.
NewEncoder
(
&
data
)
err
:=
encoder
.
Encode
(
c
.
excerpts
)
err
:=
encoder
.
Encode
(
aux
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
excerptsPath
:=
repoExcerptsFilePath
(
c
.
repo
)
f
,
err
:=
os
.
Create
(
cacheFilePath
(
c
.
repo
))
f
,
err
:=
os
.
Create
(
excerptsPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -143,11 +157,11 @@ func (c *RepoCache) writeExcerpts() error {
...
@@ -143,11 +157,11 @@ func (c *RepoCache) writeExcerpts() error {
return
f
.
Close
()
return
f
.
Close
()
}
}
func
repoExcerpts
FilePath
(
repo
repository
.
Repo
)
string
{
func
cache
FilePath
(
repo
repository
.
Repo
)
string
{
return
path
.
Join
(
repo
.
GetPath
(),
".git"
,
"git-bug"
,
excerpts
File
)
return
path
.
Join
(
repo
.
GetPath
(),
".git"
,
"git-bug"
,
cache
File
)
}
}
func
(
c
*
RepoCache
)
build
AllExcerpt
()
{
func
(
c
*
RepoCache
)
build
Cache
()
{
fmt
.
Printf
(
"Building bug cache... "
)
fmt
.
Printf
(
"Building bug cache... "
)
c
.
excerpts
=
make
(
map
[
string
]
*
BugExcerpt
)
c
.
excerpts
=
make
(
map
[
string
]
*
BugExcerpt
)
...
@@ -324,7 +338,7 @@ func (c *RepoCache) MergeAll(remote string) <-chan bug.MergeResult {
...
@@ -324,7 +338,7 @@ func (c *RepoCache) MergeAll(remote string) <-chan bug.MergeResult {
out
<-
result
out
<-
result
}
}
err
:=
c
.
write
Excerpts
()
err
:=
c
.
write
()
// No easy way out here ..
// No easy way out here ..
if
err
!=
nil
{
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment