Permalink
Browse files

argument 'i' is now checked by the checkArgs method and used as cwd f…

…or proc_open, so git will show the log of the specified repository
  • Loading branch information...
1 parent c076878 commit 72f03a61f8a81c22c27d1eef8315797a0d365a5d @aurora committed May 3, 2012
Showing with 20 additions and 17 deletions.
  1. +20 −17 libs/plugins/gitgraph.class.php
@@ -43,6 +43,15 @@ class gitgraph extends plugin
/**/
/**
+ * Work directory to set for git command.
+ *
+ * @octdoc p:gitgraph/$cwd
+ * @var string
+ */
+ protected $cwd;
+ /**/
+
+ /**
* Start date as UNIX timestamp.
*
* @octdoc p:gitgraph/$start
@@ -84,27 +93,16 @@ class gitgraph extends plugin
/**
* Overwrite parent method, because file input is not supported by this plugin, respectively the
- * input file has to specify a git repository.
+ * input file has to specify a git repository and is checked by the checkArgs method.
*
* @octdoc m:gitgraph/loadFile
* @param string $name Name of file to load.
* @return array Status information.
*/
public function loadFile($name)
/**/
- {
- $status = true;
- $msg = '';
- $content = '';
-
- if (!is_dir($name . '/.git')) {
- $status = false;
- $msg = 'input is not a git repository';
- } else {
- $content = $name;
- }
-
- return array($status, $msg, $content);
+ {
+ return array(true, '', '');
}
/**
@@ -142,7 +140,12 @@ public function checkArgs($script, array $opt)
$msg = '';
$usage = '';
- if (!array_key_exists('r', $opt)) {
+ $this->cwd = realpath($opt['i']);
+
+ if (!is_dir($this->cwd . '/.git')) {
+ $status = false;
+ $msg = 'input is not a path to a git repository';
+ } elseif (!array_key_exists('r', $opt)) {
$status = false;
$usage = sprintf("usage: %s -t ... -i ... -o ... -r ... [-c ...] [-s ...]\n", $script);
} elseif (preg_match('/^(\d{4}-\d{2}-\d{2})\.\.(\d{4}-\d{2}-\d{2})$/', $opt['r'], $match)) {
@@ -174,7 +177,7 @@ public function checkArgs($script, array $opt)
* Git log parser.
*
* @octdoc m:gitgraph/parse
- * @param string $content Path to git repository.
+ * @param string $content Unused.
*/
public function parse($content)
/**/
@@ -226,7 +229,7 @@ public function parse($content)
// execute command and process output
fwrite(STDERR, "processing log. please wait ...\n");
- if (!($ph = proc_open($cmd, $descriptors, $pipes))) {
+ if (!($ph = proc_open($cmd, $descriptors, $pipes, $this->cwd))) {
die("unable to execute \"$cmd\"\n");
}

0 comments on commit 72f03a6

Please sign in to comment.