@@ -47,9 +47,6 @@ func (s *Server) listBranches(w http.ResponseWriter, r *http.Request) {
4747
4848 branchDetails := make ([]models.BranchView , 0 , len (branches ))
4949
50- // branchRegistry is used to display the "main" branch with only the most recent snapshot.
51- branchRegistry := make (map [string ]int , 0 )
52-
5350 for _ , branchEntity := range branches {
5451 snapshotDetails , ok := repo .Snapshots [branchEntity .SnapshotID ]
5552 if ! ok {
@@ -60,22 +57,14 @@ func (s *Server) listBranches(w http.ResponseWriter, r *http.Request) {
6057
6158 branchView := models.BranchView {
6259 Name : branchEntity .Name ,
60+ BaseDataset : branchEntity .Dataset ,
6361 Parent : parentSnapshot ,
6462 DataStateAt : snapshotDetails .DataStateAt ,
6563 SnapshotID : snapshotDetails .ID ,
6664 Dataset : snapshotDetails .Dataset ,
6765 NumSnapshots : numSnapshots ,
6866 }
6967
70- if position , ok := branchRegistry [branchEntity .Name ]; ok {
71- if branchView .DataStateAt > branchDetails [position ].DataStateAt {
72- branchDetails [position ] = branchView
73- }
74-
75- continue
76- }
77-
78- branchRegistry [branchView .Name ] = len (branchDetails )
7968 branchDetails = append (branchDetails , branchView )
8069 }
8170
@@ -136,15 +125,36 @@ func containsString(slice []string, s string) bool {
136125}
137126
138127func (s * Server ) getFSManagerForBranch (branchName string ) (pool.FSManager , error ) {
128+ return s .getFSManagerForBranchAndDataset (branchName , "" )
129+ }
130+
131+ func (s * Server ) getFSManagerForBranchAndDataset (branchName , dataset string ) (pool.FSManager , error ) {
139132 allBranches , err := s .getAllAvailableBranches (s .pm .First ())
140133 if err != nil {
141134 return nil , fmt .Errorf ("failed to get branch list: %w" , err )
142135 }
143136
144137 for _ , branchEntity := range allBranches {
145- if branchEntity .Name == branchName { // TODO: filter by pool name as well because branch name is ambiguous.
138+ if branchEntity .Name != branchName {
139+ continue
140+ }
141+
142+ if dataset == "" {
146143 return s .getFSManagerForSnapshot (branchEntity .SnapshotID )
147144 }
145+
146+ fsm , err := s .getFSManagerForSnapshot (branchEntity .SnapshotID )
147+ if err != nil {
148+ continue
149+ }
150+
151+ if fsm .Pool ().Name == dataset {
152+ return fsm , nil
153+ }
154+ }
155+
156+ if dataset != "" {
157+ return nil , fmt .Errorf ("failed to find dataset %s of the branch: %s" , dataset , branchName )
148158 }
149159
150160 return nil , fmt .Errorf ("failed to found dataset of the branch: %s" , branchName )
@@ -469,6 +479,18 @@ func filterSnapshotsByBranch(pool *resources.Pool, branch string, snapshots []mo
469479 return filtered
470480}
471481
482+ func filterSnapshotsByDataset (dataset string , snapshots []models.Snapshot ) []models.Snapshot {
483+ filtered := make ([]models.Snapshot , 0 )
484+
485+ for _ , sn := range snapshots {
486+ if sn .Pool == dataset {
487+ filtered = append (filtered , sn )
488+ }
489+ }
490+
491+ return filtered
492+ }
493+
472494func (s * Server ) log (w http.ResponseWriter , r * http.Request ) {
473495 branchName := mux .Vars (r )["branchName" ]
474496
0 commit comments