@@ -44,11 +44,32 @@ class Log implements \Countable, \IteratorAggregate
4444 */
4545 protected $ limit ;
4646
47- public function __construct (Repository $ repository , $ revisions , $ paths = null , $ offset = 0 , $ limit = null )
47+ /**
48+ * Instanciates a git log object.
49+ *
50+ * @param Repository $repository the repository where log occurs
51+ * @param RevisionList $revisions a list of revisions or null if you want all history
52+ * @param array $paths paths to filter on
53+ * @param int|null $offset start list from a given position
54+ * @param int|null $limit limit number of fetched elements
55+ */
56+ public function __construct (Repository $ repository , $ revisions = null , $ paths = null , $ offset = null , $ limit = null )
4857 {
58+ if (null !== $ revisions && !$ revisions instanceof RevisionList) {
59+ $ revisions = new RevisionList ($ repository , $ revisions );
60+ }
61+
62+ if (null === $ paths ) {
63+ $ paths = array ();
64+ } elseif (is_string ($ paths )) {
65+ $ paths = array ($ paths );
66+ } elseif (!is_array ($ paths )) {
67+ throw new \InvalidArgumentException (sprintf ('Expected a string or an array, got a "%s". ' , is_object ($ paths ) ? get_class ($ paths ) : gettype ($ paths )));
68+ }
69+
4970 $ this ->repository = $ repository ;
50- $ this ->revisions = ( array ) $ revisions ;
51- $ this ->paths = ( array ) $ paths ;
71+ $ this ->revisions = $ revisions ;
72+ $ this ->paths = $ paths ;
5273 $ this ->offset = $ offset ;
5374 $ this ->limit = $ limit ;
5475 }
@@ -62,7 +83,7 @@ public function getDiff()
6283 }
6384
6485 /**
65- * @return array
86+ * @return RevisionList
6687 */
6788 public function getRevisions ()
6889 {
@@ -118,10 +139,6 @@ public function setLimit($limit)
118139 */
119140 public function getCommits ()
120141 {
121- $ offset = null !== $ this ->offset ? '--skip= ' .((int ) $ this ->offset ) : '' ;
122- $ limit = null !== $ this ->limit ? '-n ' .((int ) $ this ->limit ) : '' ;
123- $ revisions = null !== $ this ->revisions ? $ this ->revisions : '--all ' ;
124-
125142 $ args = array ('--encoding= ' .StringHelper::getEncoding (), '--format=format:%H ' );
126143
127144 if (null !== $ this ->offset ) {
@@ -133,8 +150,8 @@ public function getCommits()
133150 $ args [] = (int ) $ this ->limit ;
134151 }
135152
136- if (count ( $ this ->revisions ) ) {
137- $ args = array_merge ($ args , $ this ->revisions );
153+ if (null !== $ this ->revisions ) {
154+ $ args = array_merge ($ args , $ this ->revisions -> getAsTextArray () );
138155 } else {
139156 $ args [] = '--all ' ;
140157 }
@@ -180,7 +197,7 @@ public function getIterator()
180197 public function countCommits ()
181198 {
182199 if (count ($ this ->revisions )) {
183- $ output = $ this ->repository ->run ('rev-list ' , array_merge ($ this ->revisions , array ('-- ' ), $ this ->paths ));
200+ $ output = $ this ->repository ->run ('rev-list ' , array_merge ($ this ->revisions -> getAsTextArray () , array ('-- ' ), $ this ->paths ));
184201 } else {
185202 $ output = $ this ->repository ->run ('rev-list ' , array_merge (array ('--all ' , '-- ' ), $ this ->paths ));
186203 }
0 commit comments