LCOV - code coverage report
Current view: top level - server/git - TagMatcher.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 27 29 93.1 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2011 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.git;
      16             : 
      17             : import com.google.gerrit.server.git.TagSet.Tag;
      18             : import java.io.IOException;
      19             : import java.util.ArrayList;
      20             : import java.util.BitSet;
      21             : import java.util.Collection;
      22             : import java.util.List;
      23             : import org.eclipse.jgit.lib.ObjectId;
      24             : import org.eclipse.jgit.lib.Ref;
      25             : import org.eclipse.jgit.lib.Repository;
      26             : 
      27             : public class TagMatcher {
      28           9 :   final BitSet mask = new BitSet();
      29           9 :   final List<Ref> newRefs = new ArrayList<>();
      30           9 :   final List<LostRef> lostRefs = new ArrayList<>();
      31             :   final TagSetHolder holder;
      32             :   final TagCache cache;
      33             :   final Repository db;
      34             :   final Collection<Ref> include;
      35             :   TagSet tags;
      36             :   final boolean updated;
      37             :   private boolean rebuiltForNewTags;
      38             : 
      39             :   TagMatcher(
      40             :       TagSetHolder holder,
      41             :       TagCache cache,
      42             :       Repository db,
      43             :       Collection<Ref> include,
      44             :       TagSet tags,
      45           9 :       boolean updated) {
      46           9 :     this.holder = holder;
      47           9 :     this.cache = cache;
      48           9 :     this.db = db;
      49           9 :     this.include = include;
      50           9 :     this.tags = tags;
      51           9 :     this.updated = updated;
      52           9 :   }
      53             : 
      54             :   public boolean isReachable(Ref tagRef) throws IOException {
      55           9 :     tagRef = db.getRefDatabase().peel(tagRef);
      56           9 :     ObjectId tagObj = tagRef.getPeeledObjectId();
      57           9 :     if (tagObj == null) {
      58           6 :       tagObj = tagRef.getObjectId();
      59           6 :       if (tagObj == null) {
      60           0 :         return false;
      61             :       }
      62             :     }
      63             : 
      64           9 :     Tag tag = tags.lookupTag(tagObj);
      65           9 :     if (tag == null) {
      66           5 :       if (rebuiltForNewTags) {
      67           0 :         return false;
      68             :       }
      69             : 
      70           5 :       rebuiltForNewTags = true;
      71           5 :       holder.rebuildForNewTags(cache, this);
      72           5 :       return isReachable(tagRef);
      73             :     }
      74             : 
      75           9 :     return tag.has(mask);
      76             :   }
      77             : 
      78             :   static class LostRef {
      79             :     final Tag tag;
      80             :     final int flag;
      81             : 
      82           1 :     LostRef(Tag tag, int flag) {
      83           1 :       this.tag = tag;
      84           1 :       this.flag = flag;
      85           1 :     }
      86             :   }
      87             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750