public static function rewritePaths()

in src/shipit/filter/ShipItPathFilters.php [98:130]


  public static function rewritePaths(
    ShipItChangeset $changeset,
    (function(string): string) $path_rewrite_callback,
  ): ShipItChangeset {
    $diffs = vec[];
    foreach ($changeset->getDiffs() as $diff) {
      $old_path = $diff['path'];
      $new_path = $path_rewrite_callback($old_path);
      if ($old_path === $new_path) {
        $diffs[] = $diff;
        continue;
      }

      $old_path = PHP\preg_quote($old_path, '@');

      $body = $diff['body'];
      $body = PHP\preg_replace(
        '@^--- (a/'.$old_path.'|"a/.*?"$)@m',
        '--- a/'.$new_path,
        $body,
      ) as string;
      $body = PHP\preg_replace(
        '@^\+\+\+ (b/'.$old_path.'|"b/.*?"$)@m',
        '+++ b/'.$new_path,
        $body,
      ) as string;
      $diffs[] = shape(
        'path' => $new_path,
        'body' => $body,
      );
    }
    return $changeset->withDiffs($diffs);
  }