/** * Constructor * * @param Horde_Vcs $rep A Horde_Vcs repository object. * @param string $file The filename to create patchsets for. */ public function __construct($rep, $opts = array()) { // TODO: Allow access via 'range' $fileOb = $rep->getFile($opts['file']); foreach ($fileOb->getLog() as $rev => $log) { $this->_patchsets[$rev] = array_merge($log->toHash(), array('members' => array())); foreach ($log->getFiles() as $file => $info) { $to = $rev; $status = Horde_Vcs_Patchset::MODIFIED; if ($info['status'] == 'A') { $from = null; $status = Horde_Vcs_Patchset::ADDED; } elseif ($info['status'] == 'D') { $from = $to; $to = null; $status = Horde_Vcs_Patchset::DELETED; } else { // This technically isn't the previous revision, // but it works for diffing purposes. $from = $to - 1; } $this->_patchsets[$rev]['members'][] = array('file' => $file, 'from' => $from, 'to' => $to, 'status' => $status); } } }
/** * Constructor * * @param Horde_Vcs $rep A Horde_Vcs repository object. * @param array $opts Additional options. * <pre> * 'file' - (string) The filename to produce patchsets for. * 'range' - (array) The patchsets to process. * DEFAULT: None (all patchsets are processed). * </pre> */ public function __construct($rep, $opts = array()) { $revs = array(); if (isset($opts['file'])) { $ob = $rep->getFile($opts['file']); $revs = $ob->getLog(); } elseif (!empty($opts['range'])) { foreach ($opts['range'] as $val) { /* Grab a filename in the patchset to get log info. */ list($resource, $stream) = $rep->runCommand('diff-tree --name-only -r ' . escapeshellarg($val)); /* The first line is the SHA1 hash. */ $ob = $rep->getFile(fgets($stream)); fclose($stream); proc_close($resource); $revs[$val] = $ob->getLog($val); } } reset($revs); while (list($rev, $log) = each($revs)) { if (empty($log)) { continue; } $this->_patchsets[$rev] = array_merge($log->toHash(), array('members' => array())); foreach ($log->getFiles() as $file) { $from = $log->getParent(); $to = $rev; switch ($file['status']) { case 'A': $status = Horde_Vcs_Patchset::ADDED; break; case 'D': $status = Horde_Vcs_Patchset::DELETED; break; default: $status = Horde_Vcs_Patchset::MODIFIED; } $statinfo = isset($file['added']) ? array('added' => $file['added'], 'deleted' => $file['deleted']) : array(); $this->_patchsets[$rev]['members'][] = array_merge(array('file' => $file['srcPath'], 'from' => $from, 'status' => $status, 'to' => $to), $statinfo); } } }