find() static public method

Returns array($commits, $existing, $ntoc)
static public find ( $kwargs = null )
Example #1
0
 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();
 }
Example #2
0
 /** 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;
     }
 }
Example #3
0
<?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;