Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit acb3e0f

Browse files
committed
Use defer
1 parent 2706f5e commit acb3e0f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

commit_info.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ type getCommitsInfoState struct {
4747

4848
func (state *getCommitsInfoState) numRemainingEntries() int {
4949
state.lock.Lock()
50-
numRemaining := len(state.entries) - len(state.commits)
51-
state.lock.Unlock()
52-
return numRemaining
50+
defer state.lock.Unlock()
51+
return len(state.entries) - len(state.commits)
5352
}
5453

5554
// getTargetEntryPath Returns the next path for a targeted-searching thread to
5655
// search for, or returns the empty string if nothing left to search for
5756
func (state *getCommitsInfoState) getTargetedEntryPath() string {
5857
var targetedEntryPath string
5958
state.lock.Lock()
59+
defer state.lock.Unlock()
6060
for _, entry := range state.entries {
6161
entryPath := path.Join(state.treePath, entry.Name())
6262
if _, ok := state.commits[entryPath]; ok {
@@ -68,7 +68,6 @@ func (state *getCommitsInfoState) getTargetedEntryPath() string {
6868
state.targetedPaths[entryPath] = struct{}{}
6969
break
7070
}
71-
state.lock.Unlock()
7271
return targetedEntryPath
7372
}
7473

@@ -179,11 +178,11 @@ func (state *getCommitsInfoState) update(entryPath string, commit *Commit) bool
179178

180179
var updated bool
181180
state.lock.Lock()
181+
defer state.lock.Unlock()
182182
if _, ok := state.commits[entryPath]; !ok {
183183
state.commits[entryPath] = commit
184184
updated = true
185185
}
186-
state.lock.Unlock()
187186
return updated
188187
}
189188

0 commit comments

Comments
 (0)