private static function parseHgRegions()

in src/shipit/repo/ShipItRepoHG.php [188:208]


  private static function parseHgRegions(string $patch): Iterator<string> {
    $contents = '';
    foreach (Str\split($patch, "\n") as $line) {
      $line = Regex\replace($line, re"/(\r\n|\n)/", "\n");

      if (
        $contents !== '' &&
        Regex\matches(
          Str\trim_right($line),
          re"@^diff --git( ([ab]/(.*?)|/dev/null)){2}@",
        )
      ) {
        yield $contents;
        $contents = '';
      }
      $contents .= $line."\n";
    }
    if ($contents !== '') {
      yield $contents;
    }
  }