Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add paths arguments from Git rev-list #11

Merged
merged 1 commit into from

4 participants

@chEbba

This patch adds the ability to specify paths for rev-list (last arguments).
Example:

<?php
$git = new VersionControl_Git('/path/to/repository');
$result = $git->getRevListFetcher()
    ->target('master')
    ->paths(array('/path/to/repository/and/some/file/or/dir')) // optional an array of paths
    ->setOption('max-count', 10)
    ->setOption('grep', 'initial')
    ->setOption('date', '3 hours ago')
    ->fetch();
// Result will contain only commits which had affect for specified paths 
@co3k
Owner

Good. I'll merge it within a week. Thanks for your contribute!

BTW, do you have unit test for it?

@chEbba

Sorry for the late answer, i was on vacation :)
I was going to write a test, but there was no testcase for VersionControl_Git_Util_RevListFetcher at all. But i can create a full unit test for this class. Will try to do it on the weekend.

@cweiske
Owner

any update?

@co3k co3k was assigned
@CloCkWeRX CloCkWeRX merged commit 3ad2b5b into pear:master
@CloCkWeRX
Owner

Added because "Good. I'll merge it within a week" was unfortunately a year ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2011
  1. @chEbba
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 4 deletions.
  1. +34 −4 VersionControl/Git/Util/RevListFetcher.php
View
38 VersionControl/Git/Util/RevListFetcher.php
@@ -30,6 +30,7 @@
* @category VersionControl
* @package VersionControl_Git
* @author Kousuke Ebihara <ebihara@php.net>
+ * @author Kirill chEbba Chebunin <iam@chebba.org>
* @copyright 2010 Kousuke Ebihara
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
*/
@@ -50,6 +51,13 @@ class VersionControl_Git_Util_RevListFetcher extends VersionControl_Git_Util_Com
protected $target = self::DEFAULT_TARGET;
/**
+ * Commits will be filtered by modifications for this paths only
+ *
+ * @var type
+ */
+ protected $paths = array();
+
+ /**
* Set the target
*
* @param string $target The target for the commits that you want to get
@@ -64,6 +72,20 @@ public function target($target)
}
/**
+ * Set paths
+ *
+ * @param array $paths The array of paths which commits you want
+ *
+ * @return VersionControl_Git_Util_RevListFetcher The "$this" object
+ */
+ public function paths(array $paths)
+ {
+ $this->paths = $paths;
+
+ return $this;
+ }
+
+ /**
* Reset properties
*
* @return VersionControl_Git_Util_RevListFetcher The "$this" object
@@ -74,6 +96,8 @@ public function reset()
$this->target = self::DEFAULT_TARGET;
+ $this->paths = array();
+
return $this;
}
@@ -84,10 +108,16 @@ public function reset()
*/
public function fetch()
{
- $string = $this->setSubCommand('rev-list')
- ->setOption('pretty', 'raw')
- ->setArguments(array($this->target))
- ->execute();
+ $this->setSubCommand('rev-list')
+ ->setOption('pretty', 'raw')
+ ->setArguments(array($this->target));
+
+ // Add paths to arguments
+ foreach ($this->paths as $path) {
+ $this->addArgument($path);
+ }
+
+ $string = $this->execute();
$lines = explode("\n", $string);
Something went wrong with that request. Please try again.