<commit_before>package sbt.dynver

import java.io.File
import collection.JavaConverters._
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.{IndexDiff, Constants}
import org.eclipse.jgit.revwalk.RevWalk
import org.eclipse.jgit.treewalk.FileTreeIterator

object Main {
  def main(args: Array[String]) {
    val repoDir = new File("target/test-repo")
    println("version = " + getVersion(Git.open(repoDir)))
  }

  def getVersion(git: Git, tagPred: (String => Boolean) = SemVer.validate): Version = {
    val repo = git.getRepository
    val headId = repo.resolve(Constants.HEAD)

    val revWalk = new RevWalk(repo)
    val headCommit = revWalk.parseCommit(headId)
    revWalk.markStart(headCommit)

    val tags = repo.getTags.asScala.toMap
    val headTags = for {
      (shortTagName, tag) <- tags
      tagId = tag.getObjectId
      revObj = revWalk.parseAny(tagId)
      peeledRevObj = revWalk.peel(revObj)
      if peeledRevObj == headId
      if tagPred(shortTagName)
    } yield shortTagName

    val isDirty = new IndexDiff(repo, Constants.HEAD, new FileTreeIterator(repo)).diff()

    if (headTags.isEmpty) {
      val commitHash = headId.name.slice(0, 12)
      val tagsMap = for {(shortTagName, tag) <- tags} yield (revWalk.parseCommit(tag.getObjectId), shortTagName)
      val commitSeq = revWalk.asScala.toSeq<commit_msg>Change getVersion to take a Repository instead of a Git.<commit_after>package sbt.dynver

import java.io.File
import collection.JavaConverters._
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.{Repository, IndexDiff, Constants}
import org.eclipse.jgit.revwalk.RevWalk
import org.eclipse.jgit.treewalk.FileTreeIterator

object Main {
  def main(args: Array[String]) {
    val repoDir = new File("target/test-repo")
    val git = Git.open(repoDir)
    val repo = git.getRepository
    val version = getVersion(repo)
    println("version = " + version)
  }

  def getVersion(repo: Repository, tagPred: (String => Boolean) = SemVer.validate): Version = {
    val headId = repo.resolve(Constants.HEAD)

    val revWalk = new RevWalk(repo)
    val headCommit = revWalk.parseCommit(headId)
    revWalk.markStart(headCommit)

    val tags = repo.getTags.asScala.toMap
    val headTags = for {
      (shortTagName, tag) <- tags
      tagId = tag.getObjectId
      revObj = revWalk.parseAny(tagId)
      peeledRevObj = revWalk.peel(revObj)
      if peeledRevObj == headId
      if tagPred(shortTagName)
    } yield shortTagName

    val isDirty = new IndexDiff(repo, Constants.HEAD, new FileTreeIterator(repo)).diff()

    if (headTags.isEmpty) {
      val commitHash = headId.name.slice(0, 12)
      val tagsMap = for {(shortTagName, tag) <- tags} yield (revWalk.parseCommit(tag.getObjectId), shortTagName)
      val commitSeq = revWalk.asScala.toSeq
{'fraction_non_alphanumeric': 0.10793423874195854, 'fraction_numerical': 0.002144388849177984, 'mean_word_length': 3.665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2999058', 'n_tokens_mistral': 928, 'n_tokens_neox': 908, 'n_words': 205}