private boolean isDirty()

in src/main/java/com/ericsson/gerrit/plugins/gcconductor/EvaluationTask.java [111:147]


  private boolean isDirty() {
    try (FileRepository repository =
        (FileRepository)
            RepositoryCache.open(FileKey.exact(new File(repositoryPath), FS.DETECTED))) {
      RepoStatistics statistics = new GC(repository).getStatistics();
      if (statistics.numberOfPackFiles >= cfg.getPackedThreshold()) {
        log.debug(
            "The number of packs ({}) exceeds the configured limit of {}",
            statistics.numberOfPackFiles,
            cfg.getPackedThreshold());
        return true;
      }
      long looseObjects = statistics.numberOfLooseObjects;
      int looseThreshold = cfg.getLooseThreshold();
      if (looseObjects >= looseThreshold) {
        long referencedLooseObjects = 0;
        long unreferencedLooseObjects = 0;
        long duration = 0;
        long start = System.currentTimeMillis();
        unreferencedLooseObjects = getUnreferencedLooseObjectsCount(repository);
        duration = System.currentTimeMillis() - start;
        referencedLooseObjects = looseObjects - unreferencedLooseObjects;
        log.debug(
            "{} of {} loose objects in repository {} were unreferenced. Evaluating unreferenced objects took {}ms.",
            unreferencedLooseObjects,
            looseObjects,
            repositoryPath,
            duration);
        return referencedLooseObjects >= looseThreshold;
      }
    } catch (RepositoryNotFoundException rnfe) {
      log.debug("Repository no longer exist, aborting evaluation.");
    } catch (IOException e) {
      log.error("Error gathering '{}' statistics.", repositoryPath, e);
    }
    return false;
  }