@@ -11,7 +11,9 @@ import (
11
11
"fmt"
12
12
"io"
13
13
"log"
14
+ "regexp"
14
15
"sort"
16
+ "strconv"
15
17
"strings"
16
18
"sync"
17
19
"time"
@@ -244,6 +246,10 @@ type nonChangeRefLister interface {
244
246
ForeachNonChangeRef (fn func (ref string , hash maintner.GitHash ) error ) error
245
247
}
246
248
249
+ // releaseBranchRx matches things of the form "release-branch.go1.5" or "release-branch.go2",
250
+ // but not things like "release-branch.go1.10-security".
251
+ var releaseBranchRx = regexp .MustCompile (`^release-branch\.go(\d{1,2})(?:\.(\d{1,3}))?$` )
252
+
247
253
// supportedGoReleases returns the latest patches of releases
248
254
// that are considered supported per policy.
249
255
func supportedGoReleases (goProj nonChangeRefLister ) ([]* apipb.GoRelease , error ) {
@@ -289,14 +295,16 @@ func supportedGoReleases(goProj nonChangeRefLister) ([]*apipb.GoRelease, error)
289
295
case strings .HasPrefix (ref , "refs/heads/release-branch.go" ):
290
296
// Release branch.
291
297
branchName := ref [len ("refs/heads/" ):]
292
- var major , minor int32
293
- _ , err := fmt .Sscanf (branchName , "release-branch.go%d.%d" , & major , & minor )
294
- if err == io .ErrUnexpectedEOF {
295
- // Do nothing.
296
- } else if err != nil {
298
+ m := releaseBranchRx .FindStringSubmatch (branchName )
299
+ if m == nil {
297
300
return nil
298
301
}
299
- branches [majorMinor {major , minor }] = branch {
302
+ var major , minor int
303
+ major , _ = strconv .Atoi (m [1 ])
304
+ if len (m ) > 2 {
305
+ minor , _ = strconv .Atoi (m [2 ])
306
+ }
307
+ branches [majorMinor {int32 (major ), int32 (minor )}] = branch {
300
308
Name : branchName ,
301
309
Commit : hash ,
302
310
}
0 commit comments