<commit_before><?php

	loadlib('github_users');
	loadlib('github_api');

	# Aside from the general usefulness of a generic Git library we are using this
	# because the GitHub API is currently busted for WOF-sized repositories. See notes
	# in lib_github_api.php for details (20160502/thisisaaronland)

	########################################################################

	$GLOBALS['git_path'] = '/usr/bin/git';

	########################################################################

	function git_add($path) {

		$args = "add $path";

		$rsp = git_execute($args);
		if (! $rsp['ok']) {
			return array(
				'ok' => 0,
				'error' => "Error from git add: {$rsp['error']}"
			);
		}

		return array(
			'ok' => 1,
			'added' => $path
		);
	}

	########################################################################

	function git_commit($message, $author = null) {

		$esc_message = escapeshellarg($message);
		$args = "commit -m $esc_message";

		if ($author) {
			$esc_author = escapeshellarg($author);
			$args .= " --author=$esc_author";
		}

		$rsp = git_execute($args);
		if (! $rsp['ok']) {
			return array(
				'ok' => 0,
				'error' => "Error from git commit: {$rsp['error']}"
			);
		}

		return $rsp;
	}

	########################################################################

	function git_push($remote = 'origin', $branch = 'master') {

		$args = "push $remote $branch";

		$rsp = git_execute($args);
		if (! $rsp['ok']) {
			return array(
				'ok' => 0,
				'error' => "Error from git push: {$rsp['error']}"
			);
		}

		return $rsp;
	}

	########################################################################

	function git_execute($args) {

		$cmd = "{$GLOBALS['git_path']} $args";
		$cwd = $GLOBALS['cfg']['wof_data_dir'];

		$descriptor = array(
			1 => array('pipe', 'w'), // stdout
			2 => array('pipe', 'w')  // stderr
		);
		$pipes = array();
		$proc = proc_open($cmd, $descriptor, $pipes, $cwd);

		if (! is_resource($proc)) {
			return array(
				'ok' => 0,
				'error' => "Couldn't talk to git. Sad face."
			);
		}

		$error = stream_get_contents($pipes[1]);
		$output = stream_get_contents($pipes[2]);
		fclose($pipes[1]);
		fclose($pipes[2]);
		proc_close($proc);

		return array(
			'ok' => 1,
			'output' => trim($output),
			'error' => trim($error)
		);
	}<commit_msg>Explain the change to git_execute<commit_after><?php

	loadlib('github_users');
	loadlib('github_api');

	# Aside from the general usefulness of a generic Git library we are using this
	# because the GitHub API is currently busted for WOF-sized repositories. See notes
	# in lib_github_api.php for details (20160502/thisisaaronland)

	########################################################################

	$GLOBALS['git_path'] = '/usr/bin/git';

	########################################################################

	function git_add($path) {

		$args = "add $path";

		$rsp = git_execute($args);
		if (! $rsp['ok']) {
			return array(
				'ok' => 0,
				'error' => "Error from git add: {$rsp['error']}"
			);
		}

		return array(
			'ok' => 1,
			'added' => $path
		);
	}

	########################################################################

	function git_commit($message, $author = null) {

		$esc_message = escapeshellarg($message);
		$args = "commit -m $esc_message";

		if ($author) {
			$esc_author = escapeshellarg($author);
			$args .= " --author=$esc_author";
		}

		$rsp = git_execute($args);
		if (! $rsp['ok']) {
			return array(
				'ok' => 0,
				'error' => "Error from git commit: {$rsp['error']}"
			);
		}

		return $rsp;
	}

	########################################################################

	function git_push($remote = 'origin', $branch = 'master') {

		$args = "push $remote $branch";

		$rsp = git_execute($args);
		if (! $rsp['ok']) {
			return array(
				'ok' => 0,
				'error' => "Error from git push: {$rsp['error']}"
			);
		}

		return $rsp;
	}

	########################################################################

	function git_execute($args) {

		$cmd = "{$GLOBALS['git_path']} $args";
		$cwd = $GLOBALS['cfg']['wof_data_dir'];

		$descriptor = array(
			1 => array('pipe', 'w'), // stdout
			2 => array('pipe', 'w')  // stderr
		);
		$pipes = array();
		$proc = proc_open($cmd, $descriptor, $pipes, $cwd);

		if (! is_resource($proc)) {
			return array(
				'ok' => 0,
				'error' => "Couldn't talk to git. Sad face."
			);
		}

		$error = stream_get_contents($pipes[1]);
		$output = stream_get_contents($pipes[2]);
		fclose($pipes[1]);
		fclose($pipes[2]);
		proc_close($proc);

		// Originally this would return 'ok' => 0 if it got back a non-
		// empty STDERR value. Then I noticed that `git hash-object` was
		// using STDERR to return the hash value. Plus, it seems that
		// STDOUT is used to convey info about a failed `git push` or
		// `git pull`, so now I pass both values back and expect the
		// caller to take the right action. (20160502/dphiffer)

		return array(
			'ok' => 1,
			'output' => trim($output),
			'error' => trim($error)
		);
	}
{'fraction_non_alphanumeric': 0.30649970184853903, 'fraction_numerical': 0.009739614390777182, 'mean_word_length': 3.9092682926829267, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '203850', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1622, 'n_words': 408}