<commit_before>package io.shiftleft.semanticcpg

import io.shiftleft.codepropertygraph.Cpg
import io.shiftleft.codepropertygraph.generated.Properties
import io.shiftleft.semanticcpg.language._

object Overlays {

  def appendOverlayName(cpg: Cpg, name: String): Unit = {
    cpg.metaData.headOption match {
      case Some(metaData) =>
        val newValue = metaData.overlays :+ name
        metaData.setProperty(Properties.OVERLAYS, newValue)
      case None =>
        System.err.println("Missing metaData block")
    }
  }

  def removeLastOverlayName(cpg: Cpg): Unit = {
    cpg.metaData.headOption match {
      case Some(metaData) =>
        val newValue = metaData.overlays.dropRight(1)
        metaData.setProperty(Properties.OVERLAYS, newValue)
      case None =>
        System.err.println("Missing metaData block")
    }
  }

  def appliedOverlays(cpg: Cpg): Seq[String] = {
    cpg.metaData.headOption match {
      case Some(metaData) => Option(metaData.overlays).getOrElse(Nil)
      case None =>
        System.err.println("Missing metaData block")
        List()
    }
  }
<commit_msg>Use diff graph interface instead of deprecated direct CPG write. (#1935)<commit_after>package io.shiftleft.semanticcpg

import io.shiftleft.codepropertygraph.Cpg
import io.shiftleft.codepropertygraph.generated.Properties
import io.shiftleft.passes.SimpleCpgPass
import io.shiftleft.semanticcpg.language._
import overflowdb.BatchedUpdate

object Overlays {

  def appendOverlayName(cpg: Cpg, overlayName: String): Unit = {
    new SimpleCpgPass(cpg) {
      override def run(diffGraph: BatchedUpdate.DiffGraphBuilder): Unit = {
        cpg.metaData.headOption match {
          case Some(metaData) =>
            val newValue = metaData.overlays :+ overlayName
            diffGraph.setNodeProperty(metaData, Properties.OVERLAYS.name, newValue)
          case None =>
            System.err.println("Missing metaData block")
        }
      }
    }.createAndApply()
  }

  def removeLastOverlayName(cpg: Cpg): Unit = {
    new SimpleCpgPass(cpg) {
      override def run(diffGraph: BatchedUpdate.DiffGraphBuilder): Unit = {
        cpg.metaData.headOption match {
          case Some(metaData) =>
            val newValue = metaData.overlays.dropRight(1)
            diffGraph.setNodeProperty(metaData, Properties.OVERLAYS.name, newValue)
          case None =>
            System.err.println("Missing metaData block")
        }
      }
    }.createAndApply()
  }

  def appliedOverlays(cpg: Cpg): Seq[String] = {
    cpg.metaData.headOption match {
      case Some(metaData) => Option(metaData.overlays).getOrElse(Nil)
      case None =>
        System.err.println("Missing metaData block")
        List()
    }
  }

{'fraction_non_alphanumeric': 0.10154525386313466, 'fraction_numerical': 0.002207505518763797, 'mean_word_length': 3.022189349112426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6079098', 'n_tokens_mistral': 850, 'n_tokens_neox': 839, 'n_words': 160}