/** * Gets all commits in which this object changed * * @param $commitTip The commit from where to start searching * @return array of GitCommit */ public function getHistory(GitCommit $commitTip) { $r = array(); $commits = $commitTip->getHistory(); $path = $commitTip->getPath($this); $last = null; foreach ($commits as $commit) { $sha = (string) $commit[$path]; foreach ($commit->parents as $parent) { if ($sha !== (string) $parent[$path]) { $r[] = $commit; break; } } } return $r; }
/** * openBranch opens and locks the branch for other writing * * @return GitCommit the head commit of the branch or null if empty branch * @author The Young Shepherd **/ public function setTip(GitCommit $commit) { $fBranch = fopen(sprintf('%s/refs/heads/%s', $this->git->getDir(), $this->branchName), 'a+b'); flock($fBranch, LOCK_EX); $commit->write(); ftruncate($fBranch, 0); fwrite($fBranch, $commit->getSha()->hex()); fclose($fBranch); $this->tipCache = $commit; }
$summary = $_POST['summary']; if (strpos($summary, $page->getName()) === FALSE) { $summary = sprintf('%s: %s', $page->getName(), $summary); } $newcommit->summary = $summary; $newcommit->detail = ''; $newcommit->rehash(); $pending[] = $newcommit; if ($fast_merge) { /* create merge commit */ $tree = clone $repo->getObject($tip->tree); $pending = array_merge($pending, $tree->updateNode($page->path, 0100640, $blob->getName())); $tree->rehash(); $pending[] = $tree; $merge_base = $newcommit; $newcommit = new GitCommit($repo); $newcommit->tree = $tree->getName(); $newcommit->parents = array($tip->getName(), $merge_base->getName()); $newcommit->author = $stamp; $newcommit->committer = $stamp; $newcommit->summary = 'Fast merge'; $newcommit->detail = ''; $newcommit->rehash(); $pending[] = $newcommit; } if (!$fast_forward && !$fast_merge) { fclose($f); /* create conflict branch */ $dir = sprintf('%s/refs/heads/%s', $repo->dir, Config::GIT_CONFLICT_BRANCH_DIR); if (!file_exists($dir)) { mkdir($dir, 0755);
/** Batch-reload objects */ function reloadObjects($objects) { $names = array(); $ids = array(); # Demux foreach ($objects as $id => $obj) { $names[] = $obj->name; $ids[] = $id; } # Load commits $commits = GitCommit::find(array('names' => $names, 'mapnamestoc' => true)); $commitsbyname = $commits[2]; # Load blobs $out = git::exec("cat-file --batch", implode("\n", $ids)); $p = 0; $numobjects = count($objects); # Parse object blobs for ($i = 0; $i < $numobjects; $i++) { # <id> SP <type> SP <size> LF # <contents> LF $hend = strpos($out, "\n", $p); $h = explode(' ', substr($out, $p, $hend - $p)); $size = 0; $data = null; $dstart = $hend + 1; if ($h[1] === 'missing') { throw new UnexpectedValueException('missing blob ' . $obj->id . ' ' . var_export($obj->name, 1) . ' in repo stage'); } $obj = $objects[$h[0]]; $size = intval($h[2]); $data = substr($out, $dstart, $size); $obj->reload($data, isset($commitsbyname[$obj->name]) ? $commitsbyname[$obj->name] : array()); $p = $dstart + $size + 1; } }
function findCommits() { if (!$this->name) { throw new UnexpectedValueException('name property is empty'); } $v = GitCommit::find(array('names' => array($this->name))); if ($v) { return $v[0]; } return array(); }
<?php require_once '../_base.php'; gb::authenticate(); $paths = isset($_GET['paths']) ? $_GET['paths'] : null; $id = isset($_GET['id']) ? $_GET['id'] : ''; # Find commit list($commits, $existing, $ntoc) = GitCommit::find(array('treeish' => $id . '^' . '..' . $id, 'names' => $paths)); if (!count($commits)) { header('HTTP/1.1 404 Not Found'); exit('commit "' . h($_GET['id']) . '" not found'); } $commit = $commits[key($commits)]; $patches = $commit->loadPatches($paths); gb::$title[] = 'Commit ' . $commit->id; include '../_header.php'; ?> <style type="text/css" media="screen"> .helpers-view-commit h2 span.id { font-weight:normal; } .helpers-view-commit h2 span.id.tail { color:#ccc; } .git-patch { border:1px solid #ccc; margin-bottom:20px; } .git-patch.a { border-color:#a9eda9; } .git-patch.d { border-color:#f2b4b4; } .git-patch .header { background-color:#ddd; color:#000; padding:5px 0 5px 5px; border-bottom:1px solid #ccc; } .git-patch.d .header { background-color:#fdd; } .git-patch.a .header { background-color:#cfc; } .git-patch.d .header, .git-patch.a .header, .git-patch.r .header, .git-patch.c .header { border:none; } .git-patch .header .action { display:inline-block; margin-right:5px; border-radius:2px; -webkit-border-radius:2px; -moz-border-radius:2px;