<commit_before><?php

/*
 * This file is part of Composer.
 *
 * (c) <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Command;

use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\DependencyResolver\Pool;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Repository\CompositeRepository;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Creates an archive of a package for distribution.
 *
 * @author <NAME> <<EMAIL>>
 */
class ArchiveCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('archive')
            ->setDescription('Create an archive of this composer package')
            ->setDefinition(array(
                new InputArgument('package', InputArgument::OPTIONAL, 'The package to archive instead of the current project'),
                new InputArgument('version', InputArgument::OPTIONAL, 'The package version to archive'),
                new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the resulting archive: tar or zip', 'tar'),
                new InputOption('dir', false, InputOption::VALUE_REQUIRED, 'Write the archive to this directory', '.'),
            ))
            ->setHelp(<<<EOT
The <info>archive</info> command creates an archive of the specified format
containing the files and directories of the Composer project or the specified
package in the specified version and writes it to the specified directory.

<info>php composer.phar archive [--format=zip] [--dir=/foo] [package [version]]</info>

EOT
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        return $this->archive(
            $this->getIO(),
            $input->getArgument('package'),
            $input->getArgument('version'),
            $input->getOption('format'),
            $input->getOption('dir')
        );
    }

    public function archive(IOInterface $io, $packageName = false, $version = false, $format = 'tar', $dest = '.')
    {
        $config = Factory::createConfig();
        $factory = new Factory;
        $archiveManager = $factory->createArchiveManager($config);

        if ($packageName) {
            $package = $this->selectPackage($io, $packageName, $version);

            if (!$package) {
                return 1;
            }
        } else {
            $package = $this->getComposer()->getPackage();

            // also ignore the vendor dir
            $excludes = $package->getArchiveExcludes();
            $excludes[] = '/'.$this->getComposer()->getConfig()->get('vendor-dir');
            $package->setArchiveExcludes($excludes);
        }

        $io->write('<info>Creating the archive.</info>');
        $archiveManager->archive($package, $format, $dest);

        return 0;
    }

    protected function selectPackage(IOInterface $io, $packageName, $version = false)
    {
        $io->write('<info>Searching for the specified package.</info>');

        if ($composer = $this->getComposer(false)) {
            $localRepo = $composer->getRepositoryManager()->getLocalRepository();
            $repos = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories()));
        } else {
            $defaultRepos = Factory::createDefaultRepositories($this->getIO());
            $output->writeln('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos)));
            $repos = new CompositeRepository($defaultRepos);
        }

        $pool = new Pool();
        $pool->addRepository($repos);

        $constraint = ($version) ? new VersionConstraint('>=', $version) : null;
        $packages = $pool->whatProvides($packageName, $constraint);

        if (count($packages) > 1) {
            $package = $packages[0];
            $io->write('<info>Found multiple matches, selected '.$package.'.</info>');
            $io->write('Alternatives were '.implode(', ', $packages).'.');
            $io->write('<comment>Please use a more specific constraint to pick a different package.</comment>');
        } elseif ($packages) {
            $package = $packages[0];
            $io->write('<info>Found an exact match '.$package.'.</info>');
        } else {
            $io->write('<error>Could not find a package matching '.$packageName.'.</error>');
            return false;
        }
<commit_msg>Output packages in archive command using getPrettyString<commit_after><?php

/*
 * This file is part of Composer.
 *
 * (c) <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Command;

use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\DependencyResolver\Pool;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Repository\CompositeRepository;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Creates an archive of a package for distribution.
 *
 * @author <NAME> <<EMAIL>>
 */
class ArchiveCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('archive')
            ->setDescription('Create an archive of this composer package')
            ->setDefinition(array(
                new InputArgument('package', InputArgument::OPTIONAL, 'The package to archive instead of the current project'),
                new InputArgument('version', InputArgument::OPTIONAL, 'The package version to archive'),
                new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the resulting archive: tar or zip', 'tar'),
                new InputOption('dir', false, InputOption::VALUE_REQUIRED, 'Write the archive to this directory', '.'),
            ))
            ->setHelp(<<<EOT
The <info>archive</info> command creates an archive of the specified format
containing the files and directories of the Composer project or the specified
package in the specified version and writes it to the specified directory.

<info>php composer.phar archive [--format=zip] [--dir=/foo] [package [version]]</info>

EOT
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        return $this->archive(
            $this->getIO(),
            $input->getArgument('package'),
            $input->getArgument('version'),
            $input->getOption('format'),
            $input->getOption('dir')
        );
    }

    public function archive(IOInterface $io, $packageName = false, $version = false, $format = 'tar', $dest = '.')
    {
        $config = Factory::createConfig();
        $factory = new Factory;
        $archiveManager = $factory->createArchiveManager($config);

        if ($packageName) {
            $package = $this->selectPackage($io, $packageName, $version);

            if (!$package) {
                return 1;
            }
        } else {
            $package = $this->getComposer()->getPackage();

            // also ignore the vendor dir
            $excludes = $package->getArchiveExcludes();
            $excludes[] = '/'.$this->getComposer()->getConfig()->get('vendor-dir');
            $package->setArchiveExcludes($excludes);
        }

        $io->write('<info>Creating the archive.</info>');
        $archiveManager->archive($package, $format, $dest);

        return 0;
    }

    protected function selectPackage(IOInterface $io, $packageName, $version = false)
    {
        $io->write('<info>Searching for the specified package.</info>');

        if ($composer = $this->getComposer(false)) {
            $localRepo = $composer->getRepositoryManager()->getLocalRepository();
            $repos = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories()));
        } else {
            $defaultRepos = Factory::createDefaultRepositories($this->getIO());
            $output->writeln('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos)));
            $repos = new CompositeRepository($defaultRepos);
        }

        $pool = new Pool();
        $pool->addRepository($repos);

        $constraint = ($version) ? new VersionConstraint('>=', $version) : null;
        $packages = $pool->whatProvides($packageName, $constraint);

        if (count($packages) > 1) {
            $package = $packages[0];
            $io->write('<info>Found multiple matches, selected '.$package->getPrettyString().'.</info>');
            $io->write('Alternatives were '.implode(', ', array_map(function ($p) { return $p->getPrettyString(); }, $packages)).'.');
            $io->write('<comment>Please use a more specific constraint to pick a different package.</comment>');
        } elseif ($packages) {
            $package = $packages[0];
            $io->write('<info>Found an exact match '.$package->getPrettyString().'.</info>');
        } else {
            $io->write('<error>Could not find a package matching '.$packageName.'.</error>');
            return false;
        }

{'fraction_non_alphanumeric': 0.14058106841611998, 'fraction_numerical': 0.0010413412475268145, 'mean_word_length': 2.8202068416865553, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 132, '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': '5987510', 'n_tokens_mistral': 2531, 'n_tokens_neox': 2476, 'n_words': 656}