From 21929645ceaedc4ece1a2c2932ad26c593ff6279 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 7 Aug 2014 20:34:30 +0100 Subject: [PATCH] Make free functions static members for autoloading. --- site-tools/boost_super_project.php | 53 ++++++++++++++++-------------- site-tools/update-doc-list.php | 6 ++-- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/site-tools/boost_super_project.php b/site-tools/boost_super_project.php index 28e230f4..5f21359e 100644 --- a/site-tools/boost_super_project.php +++ b/site-tools/boost_super_project.php @@ -14,7 +14,7 @@ class BoostSuperProject { public function parse_config_file($path) { if ($this->git_branch) { - if (git_version() >= array(1,8,4,0)) { + if (self::git_version() >= array(1,8,4,0)) { $blob = $this->run_git("ls-tree {$this->git_branch} \"{$path}\""); $blob = preg_split("@[\t ]@", $blob[0])[2]; return $this->run_git("config -l --blob {$blob}"); @@ -52,32 +52,35 @@ class BoostSuperProject { } public function run_git($command) { - return run_process("git -C \"{$this->location}\" {$command}"); - } -} - -function git_version() { - $output = run_process("git --version"); - $match = null; - - if (count($output) == 1 - && preg_match('@^git version ([0-9.]+)$@', $output[0], $match)) - { - return array_pad(explode('.', $match[1]), 4, 0); - } - else { - return array(0,0,0,0); - } -} - -function run_process($command) { - exec($command, $output, $return_var); - - if ($return_var != 0) { - throw new ProcessError($return_var); + return self::run_process("git -C \"{$this->location}\" {$command}"); } - return $output; + // A couple of utility functions that don't really fit, so might move + // later. + + static function git_version() { + $output = self::run_process("git --version"); + $match = null; + + if (count($output) == 1 + && preg_match('@^git version ([0-9.]+)$@', $output[0], $match)) + { + return array_pad(explode('.', $match[1]), 4, 0); + } + else { + return array(0,0,0,0); + } + } + + static function run_process($command) { + exec($command, $output, $return_var); + + if ($return_var != 0) { + throw new ProcessError($return_var); + } + + return $output; + } } class ProcessError extends RuntimeException { diff --git a/site-tools/update-doc-list.php b/site-tools/update-doc-list.php index e7159313..e7ef831d 100644 --- a/site-tools/update-doc-list.php +++ b/site-tools/update-doc-list.php @@ -35,7 +35,7 @@ function main() { $location = $real_location; - if (get_bool_from_array(run_process( + if (get_bool_from_array(BoostSuperProject::run_process( "cd '${location}' && git rev-parse --is-bare-repository"))) { if ($version) { @@ -108,7 +108,7 @@ function update_from_git($libs, $location, $version) { $module_location = "{$location}/{$module['url']}"; $module_command = "cd '{$module_location}' && git"; - foreach(run_process("{$module_command} ls-tree {$module['hash']} " + foreach(BoostSuperProject::run_process("{$module_command} ls-tree {$module['hash']} " ."meta/libraries.xml meta/libraries.json") as $entry) { try { @@ -116,7 +116,7 @@ function update_from_git($libs, $location, $version) { if (preg_match("@^100644 blob ([a-zA-Z0-9]+)\t(.*)$@", $entry, $matches)) { $hash = $matches[1]; $filename = $matches[2]; - $text = implode("\n", (run_process("{$module_command} show {$hash}"))); + $text = implode("\n", (BoostSuperProject::run_process("{$module_command} show {$hash}"))); $libs->update(load_from_text($text, $filename, $branch), $name, $module['path']); } }