<commit_before><?php
/*
 * Copyright (c) 2012, <NAME>, http://www.xrstf.de/
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

/**
 * Repository wrapper
 *
 * This class wraps a single repository, given by the working directory's
 * path.
 */
class libhg_Repository implements libhg_Repository_Interface {
	protected $path;   ///< string
	protected $client; ///< libhg_Client_Interface

	/**
	 * Constructor
	 *
	 * @param string $path  full path to a working directory (without the '/.hg')
	 */
	public function __construct($path, libhg_Client $client = null) {
		$repo = is_string($path) && !empty($path) ? realpath($path) : false;

		if ($repo === false || !is_dir($repo)) {
			throw new libhg_Exception('Invalid repository path "'.$path.'" given.');
		}

		if (basename($repo) === '.hg') {
			$repo = dirname($repo);
		}
		elseif (!is_dir($repo.DIRECTORY_SEPARATOR.'.hg')) {
			throw new libhg_Exception('Invalid repository path "'.$path.'" given.');
		}

		$this->path   = rtrim($repo, DIRECTORY_SEPARATOR);
		$this->client = $client;
	}

	/**
	 * get directory
	 *
	 * @return string  path without trailing directory separator
	 */
	public function getDirectory() {
		return $this->path;
	}

	/**
	 * set client to use
	 *
	 * @param  libhg_Client_Interface $client
	 * @return libhg_Repository                self
	 */
	public function setClient(libhg_Client_Interface $client) {
		$this->client = $client;
		return $this;
	}

	/**
	 * get client
	 *
	 * @return libhg_Client_Interface
	 */
	public function getClient() {
		if ($this->client === null) {
			$options = new libhg_Options_Container();
			$this->client = new libhg_Client($options, $this);
		}

		return $this->client;
	}

	/**
	 * get hgrc wrapper
	 *
	 * @return libhg_Hgrc  wrapper (does not mean that the file actually exists)
	 */
	public function getHgrc() {
		$file = $this->path.DIRECTORY_SEPARATOR.'.hg'.DIRECTORY_SEPARATOR.'hgrc';
		$hgrc = new libhg_Hgrc($file);

		return $hgrc;
	}

	/**
	 * Run a command
	 *
	 * @param  libhg_Command_Interface $command  the command to run
	 * @return mixed                             the command's return value
	 */
	public function run(libhg_Command_Interface $command) {
		return $this->getClient()->run($command, $this);
	}

	/**
	 * instantiate a new command instance
	 *
	 * Class names must be named like 'libhg_Command_[$command]_Cmd'.
	 *
	 * @return string $commandName      like 'status' or 'push'
	 * @return libhg_Command_Interface
	 */<commit_msg>fixed docs<commit_after><?php
/*
 * Copyright (c) 2012, <NAME>, http://www.xrstf.de/
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

/**
 * Repository wrapper
 *
 * This class wraps a single repository, given by the working directory's
 * path.
 */
class libhg_Repository implements libhg_Repository_Interface {
	protected $path;   ///< string
	protected $client; ///< libhg_Client_Interface

	/**
	 * Constructor
	 *
	 * @param string $path  full path to a working directory (without the '/.hg')
	 */
	public function __construct($path, libhg_Client $client = null) {
		$repo = is_string($path) && !empty($path) ? realpath($path) : false;

		if ($repo === false || !is_dir($repo)) {
			throw new libhg_Exception('Invalid repository path "'.$path.'" given.');
		}

		if (basename($repo) === '.hg') {
			$repo = dirname($repo);
		}
		elseif (!is_dir($repo.DIRECTORY_SEPARATOR.'.hg')) {
			throw new libhg_Exception('Invalid repository path "'.$path.'" given.');
		}

		$this->path   = rtrim($repo, DIRECTORY_SEPARATOR);
		$this->client = $client;
	}

	/**
	 * get directory
	 *
	 * @return string  path without trailing directory separator
	 */
	public function getDirectory() {
		return $this->path;
	}

	/**
	 * set client to use
	 *
	 * @param  libhg_Client_Interface $client
	 * @return libhg_Repository                self
	 */
	public function setClient(libhg_Client_Interface $client) {
		$this->client = $client;
		return $this;
	}

	/**
	 * get client
	 *
	 * @return libhg_Client_Interface
	 */
	public function getClient() {
		if ($this->client === null) {
			$options = new libhg_Options_Container();
			$this->client = new libhg_Client($options, $this);
		}

		return $this->client;
	}

	/**
	 * get hgrc wrapper
	 *
	 * @return libhg_Hgrc  wrapper (does not mean that the file actually exists)
	 */
	public function getHgrc() {
		$file = $this->path.DIRECTORY_SEPARATOR.'.hg'.DIRECTORY_SEPARATOR.'hgrc';
		$hgrc = new libhg_Hgrc($file);

		return $hgrc;
	}

	/**
	 * Run a command
	 *
	 * @param  libhg_Command_Interface $command  the command to run
	 * @return mixed                             the command's return value
	 */
	public function run(libhg_Command_Interface $command) {
		return $this->getClient()->run($command, $this);
	}

	/**
	 * instantiate a new command instance
	 *
	 * Class names must be named like 'libhg_Command_[$command]_Cmd'.
	 *
	 * @param  string $commandName      like 'status' or 'push'
	 * @return libhg_Command_Interface
	 */
{'fraction_non_alphanumeric': 0.1399505609431451, 'fraction_numerical': 0.0015212017493820118, 'mean_word_length': 3.286878565607172, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3352835', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1642, 'n_words': 459}