break;
} while(true);
}
+ if($patch_id == 1) {
+ if(count($commit['parent']) > 1)
+ $html[] = new ContentProvider('commitdiff', 'patch_nopatch_merge');
+ else
+ $html[] = new ContentProvider('commitdiff', 'patch_nopatch_simple');
+ }
return $html;
}
$header = array();
if(!$this->diff) {
$header[] = "diff --cc ";
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'path' => ''));
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'file_hash' => $this->tree['to_id'], 'path' => ''));
} else if($this->tree['parents'] > 1) {
preg_match('!^(diff (.*?) )"?.*$!', $this->diff[0], $match);
$header[] = $match[1];
if(preg_match('/^[0]{40}$/', $this->tree['to_id']))
$header[] = $this->tree['to_file'];
else
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'path' => ''));
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'file_hash' => $this->tree['to_id'], 'path' => ''));
} else {
preg_match('!^(diff (.*?) )"?a/.*$!', $this->diff[0], $match);
$header[] = $match[1];
if(preg_match('/^[0]{40}$/', $this->tree['from_id']))
$header[] = 'a/'.$this->tree['file'];
else
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['parent'][0], 'file' => $this->tree['from_file'], 'path' => 'a/'));
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['parent'][0], 'file' => $this->tree['from_file'], 'file_hash' => $this->tree['from_id'], 'path' => 'a/'));
$header[] = ' ';
if(preg_match('/^[0]{40}$/', $this->tree['to_id']))
$header[] = 'b/'.$this->tree['file'];
else
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'path' => 'b/'));
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'file_hash' => $this->tree['to_id'], 'path' => 'b/'));
}
return $header;
}
$this->data['copy']++;
else
$this->data['copy'] = 0;
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['parent'][$this->data['copy']], 'file' => $this->tree['from_file'], 'path' => ''));
+ if(is_array($this->tree['from_id']))
+ $from_id = $this->tree['from_id'][$this->data['copy']];
+ else
+ $from_id = $this->tree['from_id'];
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['parent'][$this->data['copy']], 'file' => $this->tree['from_file'], 'file_hash' => $from_id, 'path' => ''));
} else if(preg_match('/^((copy|rename) to ).*$/', $line, $matches)) {
$header[] = $matches[1];
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'path' => ''));
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'file_hash' => $this->tree['to_id'], 'path' => ''));
} else if(preg_match('/^(index )[0-9a-fA-F]{40},[0-9a-fA-F]{40}/', $line, $matches)) { //combined diff
$header[] = $matches[1];
$parent_id = 0;
if(preg_match('/^[0]{40}$/', $from_id))
$header[] = '0000000';
else
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob_id', array('hash' => $this->commit['parent'][$parent_id], 'file' => $this->tree['from_file'], 'id' => substr($from_id, 0, 7)));
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob_id', array('hash' => $this->commit['parent'][$parent_id], 'file' => $this->tree['from_file'], 'file_hash' => $from_id, 'id' => substr($from_id, 0, 7)));
$parent_id++;
}
} else if(preg_match('/^(index )([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/', $line, $matches)) {
if(preg_match('/^[0]{40}$/', $matches[2]))
$header[] = '0000000';
else
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob_id', array('hash' => $this->commit['parent'][0], 'file' => $this->tree['from_file'], 'id' => substr($matches[2], 0, 7)));
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob_id', array('hash' => $this->commit['parent'][0], 'file' => $this->tree['from_file'], 'file_hash' => $this->tree['from_id'], 'id' => substr($matches[2], 0, 7)));
$header[] = '..';
if(preg_match('/^[0]{40}$/', $matches[3]))
$header[] = '0000000';
else
- $header[] = new ContentProvider('commitdiff', 'patch_link_blob_id', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'id' => substr($matches[3], 0, 7)));
+ $header[] = new ContentProvider('commitdiff', 'patch_link_blob_id', array('hash' => $this->commit['id'], 'file' => $this->tree['to_file'], 'file_hash' => $this->tree['to_id'], 'id' => substr($matches[3], 0, 7)));
} else
$header[] = $line;
if(preg_match('/([0-7]{6})$/', $line, $matches)) {
return $header;
}
+ private function format_line($line) {
+ $lineobj = new ContentProvider('commitdiff', 'patch_diffline');
+ $class = "";
+ if($this->tree['parents'] > 1) {
+ $prefix = substr($line, 0, $this->tree['parents']);
+ if(preg_match('/@/', $prefix))
+ $class = " chunk_header";
+ else if(preg_match('/\\/', $prefix))
+ $class = " incomplete";
+ else if(preg_match('/+/', $prefix))
+ $class = " add";
+ else if(preg_match('/-/', $prefix))
+ $class = " rem";
+ } else {
+ $prefix = substr($line, 0, 1);
+ if($prefix == '@')
+ $class = " chunk_header";
+ else if($prefix == '\\')
+ $class = " incomplete";
+ else if($prefix == '+')
+ $class = " add";
+ else if($prefix == '-')
+ $class = " rem";
+ }
+ $lineobj->set('class', $class);
+ $line = Tools::replaceTabs($line);
+ $lineobj->set('line', htmlentities($line));
+
+ return $lineobj;
+ }
+
private function gen_contentprovider($patch_id) {
if(!$this->diff)
$pageclass = 'patch_nodiff';
$pageclass = 'patch_normal';
$page = new ContentProvider('commitdiff', $pageclass);
$page->set('diffcmd', $this->gen_diffcmd_header());
+ $page->set('patch_id', $patch_id);
if(!$this->diff)
return $page;
$is_header = true;
continue;
}
}
- $lineobj = new ContentProvider('commitdiff', 'patch_diffline');
- //if(preg_match('', $line))
+ $page->append('patch', $this->format_line($line));
+
}
if($is_header)
$page->set('patch', '');