| 1 |
<?php |
<?php |
| 2 |
// $Id: gb.module,v 1.20 2009/07/17 05:51:14 gordon Exp $ |
// $Id: gb.module,v 1.21 2009/07/23 02:02:40 gordon Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Provide a git browsing API which allows other modules to add the ability |
* Provide a git browsing API which allows other modules to add the ability |
| 153 |
return $links; |
return $links; |
| 154 |
} |
} |
| 155 |
|
|
|
/** |
|
|
* Build menu links |
|
|
*/ |
|
|
function gb_build_git_menus($params = array()) { |
|
|
module_load_include('inc', 'gb', 'gb'); |
|
|
$default = array( |
|
|
'title' => 'Git Repository', |
|
|
'repos' => './.git', |
|
|
); |
|
|
$params+= $default; |
|
|
$path = $params['path']; |
|
|
$path_count = count(explode('/', $path)); |
|
|
|
|
|
$items = array(); |
|
| 156 |
|
|
|
$items[$path] = array( |
|
|
'title' => $params['title'], |
|
|
'page callback' => 'gb_summary', |
|
|
'page arguments' => array($path, $params['repos']), |
|
|
'access arguments' => array('access repository'), |
|
|
'file' => 'gb.inc', |
|
|
); |
|
|
|
|
|
$hash_arg = count(explode('/', $path))+1; |
|
|
|
|
|
$items[$path .'/commit/%'] = array( |
|
|
'title' => 'Commit Info', |
|
|
'page callback' => 'gb_commit_page', |
|
|
'page arguments' => array($path, $params['repos'], $hash_arg), |
|
|
'access arguments' => array('access commit log'), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
$items[$path .'/commit/%/details'] = array( |
|
|
'title' => 'Details', |
|
|
'access arguments' => array('access commit'), |
|
|
'page callback' => 'gb_commit_page', |
|
|
'page arguments' => array($path, $params['repos'], $hash_arg), |
|
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
|
'file' => 'gb.inc', |
|
|
'weight' => -9, |
|
|
); |
|
|
$items[$path .'/commit/%/diff'] = array( |
|
|
'title' => 'Commit Diff', |
|
|
'access arguments' => array('access commit diff'), |
|
|
'page callback' => 'gb_commit_diff', |
|
|
'page arguments' => array($path, $params['repos'], $hash_arg), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
); |
|
|
for ($i = 0; $i < 5; $i++) { |
|
|
$items[$path .'/commit/%/diff/'. $i] = array( |
|
|
'title callback' => '_gb_parent_hash_title', |
|
|
'title arguments' => array($params['repos'], $hash_arg, (string)$i), |
|
|
'access callback' => '_gb_access_parent', |
|
|
'access arguments' => array($params['repos'], $hash_arg, (string)$i, 'access commit diff'), |
|
|
'page callback' => 'gb_commit_diff', |
|
|
'page arguments' => array($path, $params['repos'], $hash_arg, (string)$i), |
|
|
'file' => 'gb.inc', |
|
|
'type' => $i ? MENU_LOCAL_TASK : MENU_DEFAULT_LOCAL_TASK, |
|
|
); |
|
|
} |
|
|
|
|
|
$items[$path .'/commit/%/tag'] = array( |
|
|
'title' => 'Tag', |
|
|
'access arguments' => array('access create commit tag'), |
|
|
'page callback' => 'drupal_get_form', |
|
|
'page arguments' => array('gb_create_tag', $path, $params['repos'], $hash_arg), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
); |
|
|
$items[$path .'/download/%'] = array( |
|
|
'title' => 'Download', |
|
|
'access arguments' => array('download archive'), |
|
|
'page callback' => 'gb_download', |
|
|
'page arguments' => array($params['repos'], $hash_arg, $hash_arg+1), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
$items[$path .'/fetch/%'] = array( |
|
|
'title' => 'Download', |
|
|
'access arguments' => array('fetch commits'), |
|
|
'page callback' => 'gb_fetch', |
|
|
'page arguments' => array($params['repos'], $hash_arg), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
|
|
|
$items[$path .'/checkout/%'] = array( |
|
|
'title' => 'Checkout', |
|
|
'access arguments' => array('checkout tag'), |
|
|
'page callback' => 'drupal_get_form', |
|
|
'page arguments' => array('gb_checkout', $params['repos'], $hash_arg), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
|
|
|
$items[$path .'/tag/%'] = array( |
|
|
'title' => 'Tag Info', |
|
|
'page callback' => 'gb_tag_page', |
|
|
'page arguments' => array($path, $params['repos'], $hash_arg), |
|
|
'access arguments' => array('access tag details'), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
|
|
|
$items+= gb_build_git_tabs($path, $params['repos'], $path, 'HEAD'); |
|
|
|
|
|
$info = gb_get_commit_info($params['repos'], 'HEAD'); |
|
|
foreach (gb_show_ref($params['repos']) as $head) { |
|
|
if ($head['hash'] != $info['hash']) { |
|
|
$items[$path .'/'. $head['path']] = array( |
|
|
'title' => $head['name'], |
|
|
'page callback' => 'gb_summary', |
|
|
'page arguments' => array($path, $params['repos'], $head['fullname']), |
|
|
'access arguments' => array('access repository'), |
|
|
'file' => 'gb.inc', |
|
|
'type' => ($head['type'] == 'heads' ? MENU_NORMAL_ITEM : MENU_CALLBACK), |
|
|
); |
|
|
|
|
|
$items+= gb_build_git_tabs($path, $params['repos'], $path .'/'. $head['path'], $head['fullname']); |
|
|
} |
|
|
} |
|
|
|
|
|
foreach ($items as $path => $item) { |
|
|
if (isset($params['menu options'])) { |
|
|
$items[$path]+= $params['menu options']; |
|
|
} |
|
|
} |
|
|
return $items; |
|
|
} |
|
|
|
|
|
function gb_build_git_tabs($menu_path, $repos, $path, $head = 'HEAD') { |
|
|
$items = array(); |
|
|
|
|
|
$items[$path .'/summary'] = array( |
|
|
'title' => 'Summary', |
|
|
'page callback' => 'gb_summary', |
|
|
'page arguments' => array($menu_path, $repos, $head), |
|
|
'access arguments' => array('access repository'), |
|
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
|
'weight' => -1, |
|
|
'file' => 'gb.inc', |
|
|
); |
|
|
$items[$path .'/shortlog'] = array( |
|
|
'title' => 'Short log', |
|
|
'page callback' => 'gb_shortlog', |
|
|
'page arguments' => array($menu_path, $repos, $head), |
|
|
'access arguments' => array('access commit log'), |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
'file' => 'gb.inc', |
|
|
); |
|
|
$items[$path .'/tag'] = array( |
|
|
'title' => 'Tag', |
|
|
'access arguments' => array('access create head tag'), |
|
|
'page callback' => 'drupal_get_form', |
|
|
'page arguments' => array('gb_create_tag', $path, $repos, $head), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
); |
|
|
$items[$path .'/tools'] = array( |
|
|
'title' => 'Tools', |
|
|
'access arguments' => array('access git tools'), |
|
|
'page callback' => 'gb_tools', |
|
|
'page arguments' => array($path, $repos, $head), |
|
|
'file' => 'gb.inc', |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
); |
|
|
|
|
|
return $items; |
|
|
} |
|
| 157 |
|
|
| 158 |
/** |
/** |
| 159 |
* Run the Git command |
* Run the Git command |