1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | <?php /** * Class to perform a commit log search * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2012 Christopher Han * @package GitPHP * @subpackage Git */ class GitPHP_CommitSearch extends GitPHP_RevList { /** * Commit search type * * @var int */ const CommitType = 1; /** * Author search type * * @var int */ const AuthorType = 2; /** * Committer search type * * @var int */ const CommitterType = 3; /** * Stores the search type * * @var int */ protected $type; /** * Stores the search query * * @var string */ protected $search; /** * Git exe * * @var GitPHP_GitExe */ protected $exe; /** * Load strategy * * @var GitPHP_RevList_Git */ protected $strategy; /** * Constructor * * @param GitPHP_Project $project project * @param int $type search type * @param string $search search string * @param GitPHP_GitExe $exe git exe * @param GitPHP_Commit $head head to walk back from * @param int $limit limit of revisions to walk * @param int $skip number of revisions to skip */ public function __construct($project, $type, $search, $exe, $head = null, $limit = 50, $skip = 0) { parent::__construct($project, $head, $limit, $skip); if (!$type) { throw new Exception('Search type is required'); } if (empty($search)) { throw new Exception('Search string is required'); } $this->type = $type; $this->search = $search; $this->exe = $exe; $this->strategy = new GitPHP_RevList_Git($exe); } /** * Gets the search type * * @return int search type */ public function GetType() { return $this->type; } /** * Sets the search type * * @param int $type search type */ public function SetType($type) { if (!$type) return; if ($type == $this->type) return; if ($this->dataLoaded) $this->Clear(); $this->type = $type; } /** * Gets the search query * * @return string search query */ public function GetSearch() { return $this->search; } /** * Sets the search query * * @param string $search search query */ public function SetSearch($search) { if (empty($search)) return; if ($this->search == $search) return; if ($this->dataLoaded) $this->Clear(); $this->search = $search; } /** * Loads the data for this search */ protected function LoadData() { $this->dataLoaded = true; $args = array(); if ($this->exe->CanIgnoreRegexpCase()) $args[] = '--regexp-ignore-case'; switch ($this->type) { case GitPHP_CommitSearch::CommitType: $args[] = '--grep="' . addslashes($this->search) . '"'; break; case GitPHP_CommitSearch::AuthorType: $args[] = '--author="' . addslashes($this->search) . '"'; break; case GitPHP_CommitSearch::CommitterType: $args[] = '--committer="' . addslashes($this->search) . '"'; break; } $this->hashList = $this->strategy->RevList($this->project, $this->hash, $this->limit, $this->skip, $args); } } |