Skip to content

Commit ad3cbbc

Browse files
authored
Remove redundant nil check in WalkGitLog (#26773)
From the Go specification: > "1. For a nil slice, the number of iterations is 0." https://go.dev/ref/spec#For_range Therefore, an additional nil check for before the loop is unnecessary. Signed-off-by: Eng Zer Jun <[email protected]>
1 parent db09b35 commit ad3cbbc

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

modules/git/log_name_status.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -374,27 +374,25 @@ heaploop:
374374
break heaploop
375375
}
376376
parentRemaining.Remove(current.CommitID)
377-
if current.Paths != nil {
378-
for i, found := range current.Paths {
379-
if !found {
380-
continue
377+
for i, found := range current.Paths {
378+
if !found {
379+
continue
380+
}
381+
changed[i] = false
382+
if results[i] == "" {
383+
results[i] = current.CommitID
384+
if err := repo.LastCommitCache.Put(headRef, path.Join(treepath, paths[i]), current.CommitID); err != nil {
385+
return nil, err
381386
}
382-
changed[i] = false
383-
if results[i] == "" {
384-
results[i] = current.CommitID
385-
if err := repo.LastCommitCache.Put(headRef, path.Join(treepath, paths[i]), current.CommitID); err != nil {
387+
delete(path2idx, paths[i])
388+
remaining--
389+
if results[0] == "" {
390+
results[0] = current.CommitID
391+
if err := repo.LastCommitCache.Put(headRef, treepath, current.CommitID); err != nil {
386392
return nil, err
387393
}
388-
delete(path2idx, paths[i])
394+
delete(path2idx, "")
389395
remaining--
390-
if results[0] == "" {
391-
results[0] = current.CommitID
392-
if err := repo.LastCommitCache.Put(headRef, treepath, current.CommitID); err != nil {
393-
return nil, err
394-
}
395-
delete(path2idx, "")
396-
remaining--
397-
}
398396
}
399397
}
400398
}

0 commit comments

Comments
 (0)