<commit_before><?php

abstract class DiffusionController extends PhabricatorController {

  private $diffusionRequest;

  protected function getDiffusionRequest() {
    if (!$this->diffusionRequest) {
      throw new PhutilInvalidStateException('loadDiffusionContext');
    }
    return $this->diffusionRequest;
  }

  protected function hasDiffusionRequest() {
    return (bool)$this->diffusionRequest;
  }

  public function willBeginExecution() {
    $request = $this->getRequest();

    // Check if this is a VCS request, e.g. from "git clone", "hg clone", or
    // "svn checkout". If it is, we jump off into repository serving code to
    // process the request.

    $serve_controller = new DiffusionServeController();
    if ($serve_controller->isVCSRequest($request)) {
      return $this->delegateToController($serve_controller);
    }

    return parent::willBeginExecution();
  }

  protected function loadDiffusionContextForEdit() {
    return $this->loadContext(
      array(
        'edit' => true,
      ));
  }

  protected function loadDiffusionContext() {
    return $this->loadContext(array());
  }

  private function loadContext(array $options) {
    $request = $this->getRequest();
    $viewer = $this->getViewer();

    $identifier = $this->getRepositoryIdentifierFromRequest($request);

    $params = $options + array(
      'repository' => $identifier,
      'user' => $viewer,
      'blob' => $this->getDiffusionBlobFromRequest($request),
      'commit' => $request->getURIData('commit'),
      'path' => $request->getURIData('path'),
      'line' => $request->getURIData('line'),
      'branch' => $request->getURIData('branch'),
      'lint' => $request->getStr('lint'),
    );

    $drequest = DiffusionRequest::newFromDictionary($params);

    if (!$drequest) {
      return new Aphront404Response();
    }

    $this->diffusionRequest = $drequest;

    return null;
  }

  protected function getDiffusionBlobFromRequest(AphrontRequest $request) {
    return $request->getURIData('dblob');
  }

  protected function getRepositoryIdentifierFromRequest(
    AphrontRequest $request) {

    $identifier = $request->getURIData('repositoryCallsign');
    if (strlen($identifier)) {
      return $identifier;
    }

    $id = $request->getURIData('repositoryID');
    if (strlen($id)) {
      return (int)$id;
    }

    return null;
  }

  public function buildCrumbs(array $spec = array()) {
    $crumbs = $this->buildApplicationCrumbs();
    $crumb_list = $this->buildCrumbList($spec);
    foreach ($crumb_list as $crumb) {
      $crumbs->addCrumb($crumb);
    }
    return $crumbs;
  }

  private function buildCrumbList(array $spec = array()) {

    $spec = $spec + array(
      'commit'  => null,
      'tags'    => null,
      'branches'    => null,
      'view'    => null,
    );

    $crumb_list = array();

    // On the home page, we don't have a DiffusionRequest.
    if ($this->hasDiffusionRequest()) {
      $drequest = $this->getDiffusionRequest();
      $repository = $drequest->getRepository();
    } else {
      $drequest = null;
      $repository = null;
    }

    if (!$repository) {
      return $crumb_list;
    }

    $repository_name = $repository->getName();

    if (!$spec['commit'] && !$spec['tags'] && !$spec['branches']) {
      $branch_name = $drequest->getBranch();
      if ($branch_name) {
        $repository_name .= ' ('.$branch_name.')';
      }
    }

    $crumb = id(new PHUICrumbView())
      ->setName($repository_name);
    if (!$spec['view'] && !$spec['commit'] &&
        !$spec['tags'] && !$spec['branches']) {
      $crumb_list[] = $crumb;
      return $crumb_list;
    }
    $crumb->setHref(
      $drequest->generateURI(
        array(
          'action' => 'branch',
          'path' => '/',
        )));
    $crumb_list[] = $crumb;

    $stable_commit = $drequest->getStableCommit();
    $commit_name = $repository->formatCommitName($stable_commit);
    $commit_uri = $repository->getCommitURI($stable_commit);

    if ($spec['tags']) {
      $crumb = new PHUICrumbView();
      if ($spec['commit']) {
        $crumb->setName(pht('Tags for %s', $commit_name));
        $crumb->setHref($commit_uri);
      } else {
        $crumb->setName(pht('Tags'));
      }
      $crumb_list[] = $crumb;
      return $crumb_list;
    }

    if ($spec['branches']) {
      $crumb = id(new PHUICrumbView())
        ->setName(pht('Branches'));
      $crumb_list[] = $crumb;
      return $crumb_list;
    }

    if ($spec['commit']) {
      $crumb = id(new PHUICrumbView())
        ->setName($commit_name)
        ->setHref($commit_uri);
      $crumb_list[] = $crumb;
      return $crumb_list;
    }

    $crumb = new PHUICrumbView();
    $view = $spec['view'];

    switch ($view) {
      case 'history':
        $view_name = pht('History');
        break;
      case 'browse':
        $view_name = pht('Browse');
        break;
      case 'lint':
        $view_name = pht('Lint');<commit_msg>Don't link commit uri in Crumbs<commit_after><?php

abstract class DiffusionController extends PhabricatorController {

  private $diffusionRequest;

  protected function getDiffusionRequest() {
    if (!$this->diffusionRequest) {
      throw new PhutilInvalidStateException('loadDiffusionContext');
    }
    return $this->diffusionRequest;
  }

  protected function hasDiffusionRequest() {
    return (bool)$this->diffusionRequest;
  }

  public function willBeginExecution() {
    $request = $this->getRequest();

    // Check if this is a VCS request, e.g. from "git clone", "hg clone", or
    // "svn checkout". If it is, we jump off into repository serving code to
    // process the request.

    $serve_controller = new DiffusionServeController();
    if ($serve_controller->isVCSRequest($request)) {
      return $this->delegateToController($serve_controller);
    }

    return parent::willBeginExecution();
  }

  protected function loadDiffusionContextForEdit() {
    return $this->loadContext(
      array(
        'edit' => true,
      ));
  }

  protected function loadDiffusionContext() {
    return $this->loadContext(array());
  }

  private function loadContext(array $options) {
    $request = $this->getRequest();
    $viewer = $this->getViewer();

    $identifier = $this->getRepositoryIdentifierFromRequest($request);

    $params = $options + array(
      'repository' => $identifier,
      'user' => $viewer,
      'blob' => $this->getDiffusionBlobFromRequest($request),
      'commit' => $request->getURIData('commit'),
      'path' => $request->getURIData('path'),
      'line' => $request->getURIData('line'),
      'branch' => $request->getURIData('branch'),
      'lint' => $request->getStr('lint'),
    );

    $drequest = DiffusionRequest::newFromDictionary($params);

    if (!$drequest) {
      return new Aphront404Response();
    }

    $this->diffusionRequest = $drequest;

    return null;
  }

  protected function getDiffusionBlobFromRequest(AphrontRequest $request) {
    return $request->getURIData('dblob');
  }

  protected function getRepositoryIdentifierFromRequest(
    AphrontRequest $request) {

    $identifier = $request->getURIData('repositoryCallsign');
    if (strlen($identifier)) {
      return $identifier;
    }

    $id = $request->getURIData('repositoryID');
    if (strlen($id)) {
      return (int)$id;
    }

    return null;
  }

  public function buildCrumbs(array $spec = array()) {
    $crumbs = $this->buildApplicationCrumbs();
    $crumb_list = $this->buildCrumbList($spec);
    foreach ($crumb_list as $crumb) {
      $crumbs->addCrumb($crumb);
    }
    return $crumbs;
  }

  private function buildCrumbList(array $spec = array()) {

    $spec = $spec + array(
      'commit'  => null,
      'tags'    => null,
      'branches'    => null,
      'view'    => null,
    );

    $crumb_list = array();

    // On the home page, we don't have a DiffusionRequest.
    if ($this->hasDiffusionRequest()) {
      $drequest = $this->getDiffusionRequest();
      $repository = $drequest->getRepository();
    } else {
      $drequest = null;
      $repository = null;
    }

    if (!$repository) {
      return $crumb_list;
    }

    $repository_name = $repository->getName();

    if (!$spec['commit'] && !$spec['tags'] && !$spec['branches']) {
      $branch_name = $drequest->getBranch();
      if ($branch_name) {
        $repository_name .= ' ('.$branch_name.')';
      }
    }

    $crumb = id(new PHUICrumbView())
      ->setName($repository_name);
    if (!$spec['view'] && !$spec['commit'] &&
        !$spec['tags'] && !$spec['branches']) {
      $crumb_list[] = $crumb;
      return $crumb_list;
    }
    $crumb->setHref(
      $drequest->generateURI(
        array(
          'action' => 'branch',
          'path' => '/',
        )));
    $crumb_list[] = $crumb;

    $stable_commit = $drequest->getStableCommit();
    $commit_name = $repository->formatCommitName($stable_commit, $local = true);
    $commit_uri = $repository->getCommitURI($stable_commit);

    if ($spec['tags']) {
      $crumb = new PHUICrumbView();
      if ($spec['commit']) {
        $crumb->setName(pht('Tags for %s', $commit_name));
        $crumb->setHref($commit_uri);
      } else {
        $crumb->setName(pht('Tags'));
      }
      $crumb_list[] = $crumb;
      return $crumb_list;
    }

    if ($spec['branches']) {
      $crumb = id(new PHUICrumbView())
        ->setName(pht('Branches'));
      $crumb_list[] = $crumb;
      return $crumb_list;
    }

    if ($spec['commit']) {
      $crumb = id(new PHUICrumbView())
        ->setName($commit_name);
      $crumb_list[] = $crumb;
      return $crumb_list;
    }

    $crumb = new PHUICrumbView();
    $view = $spec['view'];

    switch ($view) {
      case 'history':
        $view_name = pht('History');
        break;
      case 'browse':
        $view_name = pht('Browse');
        break;
      case 'lint':
        $view_name = pht('Lint');
{'fraction_non_alphanumeric': 0.1627648839556004, 'fraction_numerical': 0.0006054490413723512, 'mean_word_length': 2.9004329004329006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 114, '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': '1461584', 'n_tokens_mistral': 3207, 'n_tokens_neox': 3140, 'n_words': 609}