<commit_before><?php

/*
 * Copyright 2011 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Covers your professional reputation by blaming changes to locate reviewers.
 *
 * @group workflow
 */
class ArcanistCoverWorkflow extends ArcanistBaseWorkflow {

  public function getCommandHelp() {
    return phutil_console_format(<<<EOTEXT
      **cover**
          Supports: svn, git
          Cover your... professional reputation. Show blame for the lines you
          changed in your working copy. This will take a minute because blame
          takes a minute, especially under SVN.
EOTEXT
      );
  }

  public function requiresWorkingCopy() {
    return true;
  }

  public function requiresConduit() {
    return false;
  }

  public function requiresAuthentication() {
    return false;
  }

  public function requiresRepositoryAPI() {
    return true;
  }

  public function run() {

    $repository_api = $this->getRepositoryAPI();

    $paths = $repository_api->getWorkingCopyStatus();

    foreach ($paths as $path => $status) {
      if (is_dir($path)) {
        unset($paths[$path]);
      }
      if ($status & ArcanistRepositoryAPI::FLAG_UNTRACKED) {
        unset($paths[$path]);
      }
      if ($status & ArcanistRepositoryAPI::FLAG_ADDED) {
        unset($paths[$path]);
      }
    }

    $paths = array_keys($paths);

    if (!$paths) {
      throw new ArcanistNoEffectException(
        "You're covered, you didn't change anything.");
    }

    $changed = array();
    foreach ($paths as $path) {
      $changed[$path] = $this->getChangedLines($path, 'cover');
    }

    $covers = array();
    foreach ($paths as $path) {
      $blame = $repository_api->getBlame($path);
      $lines = $changed[$path];
      foreach ($lines as $line) {
        list($author, $revision) = idx($blame, $line, array(null, null));
        if (!$author) {
          continue;
        }
        if (!isset($covers[$author])) {
          $covers[$author] = array();
        }
        if (!isset($covers[$author][$path])) {
          $covers[$author][$path] = array(
            'lines'     => array(),
            'revisions' => array(),
          );
        }
        $covers[$author][$path]['lines'][] = $line;
        $covers[$author][$path]['revisions'][] = $revision;
      }
    }

    if (count($covers)) {
      foreach ($covers as $author => $files) {<commit_msg>Ignore non-plaintext changes in cover<commit_after><?php

/*
 * Copyright 2012 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Covers your professional reputation by blaming changes to locate reviewers.
 *
 * @group workflow
 */
class ArcanistCoverWorkflow extends ArcanistBaseWorkflow {

  public function getCommandHelp() {
    return phutil_console_format(<<<EOTEXT
      **cover**
          Supports: svn, git
          Cover your... professional reputation. Show blame for the lines you
          changed in your working copy. This will take a minute because blame
          takes a minute, especially under SVN.
EOTEXT
      );
  }

  public function requiresWorkingCopy() {
    return true;
  }

  public function requiresConduit() {
    return false;
  }

  public function requiresAuthentication() {
    return false;
  }

  public function requiresRepositoryAPI() {
    return true;
  }

  public function run() {

    $repository_api = $this->getRepositoryAPI();

    $paths = $repository_api->getWorkingCopyStatus();

    foreach ($paths as $path => $status) {
      if (is_dir($path)) {
        unset($paths[$path]);
      }
      if ($status & ArcanistRepositoryAPI::FLAG_UNTRACKED) {
        unset($paths[$path]);
      }
      if ($status & ArcanistRepositoryAPI::FLAG_ADDED) {
        unset($paths[$path]);
      }
    }

    $paths = array_keys($paths);

    if (!$paths) {
      throw new ArcanistNoEffectException(
        "You're covered, you didn't change anything.");
    }

    $covers = array();
    foreach ($paths as $path) {
      $lines = $this->getChangedLines($path, 'cover');
      if (!$lines) {
        continue;
      }
      $blame = $repository_api->getBlame($path);
      foreach ($lines as $line) {
        list($author, $revision) = idx($blame, $line, array(null, null));
        if (!$author) {
          continue;
        }
        if (!isset($covers[$author])) {
          $covers[$author] = array();
        }
        if (!isset($covers[$author][$path])) {
          $covers[$author][$path] = array(
            'lines'     => array(),
            'revisions' => array(),
          );
        }
        $covers[$author][$path]['lines'][] = $line;
        $covers[$author][$path]['revisions'][] = $revision;
      }
    }

    if (count($covers)) {
      foreach ($covers as $author => $files) {
{'fraction_non_alphanumeric': 0.1296071984772452, 'fraction_numerical': 0.0027686450943069734, 'mean_word_length': 2.6628643852978455, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5516964', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1625, 'n_words': 495}