/[drupal]/contributions/modules/versioncontrol_git/versioncontrol_git.module
ViewVC logotype

Contents of /contributions/modules/versioncontrol_git/versioncontrol_git.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.34 - (show annotations) (download) (as text)
Mon Oct 19 15:25:34 2009 UTC (5 weeks, 2 days ago) by marvil07
Branch: MAIN
CVS Tags: HEAD
Changes since 1.33: +2 -33 lines
File MIME type: text/x-php
update to the new commits at vc api

mainly operation loader and item with one abstract method
1 <?php
2 // $Id: versioncontrol_git.module,v 1.33 2009/10/19 15:23:19 marvil07 Exp $
3 /**
4 * @file
5 * Git backend for Version Control API - Provides Git commit information and
6 * account management as a pluggable backend.
7 *
8 * Copyright 2008 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
9 * Copyright 2009 by Cornelius Riemenschneider ("CorniI", http://drupal.org/user/136353)
10 */
11
12 // Update methods.
13 define('VERSIONCONTROL_GIT_UPDATE_CRON', 0);
14 define('VERSIONCONTROL_GIT_UPDATE_XGIT', 1);
15
16 require_once drupal_get_path('module', 'versioncontrol_git') . '/includes/classes.inc';
17 // The admin and user edit pages.
18 include_once(drupal_get_path('module', 'versioncontrol_git') .'/versioncontrol_git.admin.inc');
19 include_once(drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolRepository.php');
20
21 /**
22 * Implementation of hook_help().
23 */
24 function versioncontrol_git_help($section, $arg) {
25 $output = '';
26 if ($section == 'admin/help/versioncontrol_git' || $section == 'admin/help#versioncontrol_git') {
27 $output = '<p>The Git Backend can be used to retrieve and view commit information. The commit
28 information can either be retreived automatically through the use of the <i>xgit</i> scripts
29 or using the <i>fetch now</i> link on the project administration repository page. The logs
30 are then defaultly avaliable through the <i>commitlog</i> page.</p>
31 <p>Information reguarding the setup of <i>xgit</i> scripts is aviable in the <i>README.txt</i>
32 located in the <i>xgit</i> directory.</p>
33 <p>If you have any questions, comments, or feature requests please visit the
34 <a href="http://drupal.org/project/versioncontrol_git">module page</a> and
35 post your concerns in the issue quene.</p>';
36 }
37
38 return $output;
39 }
40
41 /**
42 * Implementation of hook_versioncontrol_backends().
43 */
44 function versioncontrol_git_versioncontrol_backends() {
45 return array(
46 'git' => new VersioncontrolGitBackend()
47 );
48 }
49
50 /**
51 * Implementation of hook_menu().
52 */
53 function versioncontrol_git_menu() {
54 $items = array();
55 $items['admin/project/versioncontrol-repositories/clearlock/git'] = array(
56 'title' => 'Clear lock',
57 'page callback' => 'versioncontrol_git_clearlock_repository_callback',
58 'access arguments' => array('administer version control systems'),
59 'type' => MENU_CALLBACK,
60 );
61 $items['admin/project/versioncontrol-repositories/update/git'] = array(
62 'title' => 'Fetch log',
63 'page callback' => 'versioncontrol_git_update_repository_callback',
64 'access arguments' => array('administer version control systems'),
65 'type' => MENU_CALLBACK,
66 );
67 return $items;
68 }
69
70 /**
71 * Implementation of hook_cron()
72 */
73 function versioncontrol_git_cron() {
74 $constraints = array( 'vcs' => array('git') );
75 $git_repositories = VersioncontrolRepositoryCache::getInstance()->getRepositories($constraints);
76
77 // Set timeout limit to 3600 seconds as it can take a long time to process
78 // the log initially. (And hook_cron() might be called by poormanscron.)
79 if (!ini_get('safe_mode')) {
80 set_time_limit(3600);
81 }
82 foreach ($git_repositories as $repository) {
83 if ($repository->data['versioncontrol_git']['update_method'] != VERSIONCONTROL_GIT_UPDATE_CRON) {
84 // get repositories that have log fetching enabled
85 continue;
86 }
87 _versioncontrol_git_update_repository($repository);
88 }
89 }
90
91 function _versioncontrol_git_get_branch_intersect($repository, $item1, $item2) {
92 $constraints = array(
93 'revisions' => array($item1->revision, $item2->revision),
94 'vcs' => array('git'),
95 'repo_ids' => array($repository->repo_id),
96 'types' => array(VERSIONCONTROL_OPERATION_COMMIT)
97 );
98 $commit_ops = VersioncontrolOperationCache::getInstance()->getOperations($constraints);
99 $branches1 = array();
100 $branches2 = array();
101 foreach ($commit_ops as $vc_op_id => $op) {
102 foreach ($op['labels'] as $label) {
103 if ($label['type'] === VERSIONCONTROL_OPERATION_BRANCH) {
104 if ($op['revision'] == $item1['revision']) {
105 $branches1[]=$label;
106 }
107 else if ($op['revision'] == $item2['revision']) {
108 $branches2[]=$label;
109 }
110 }
111 }
112 }
113 foreach ($branches1 as $key => $value) {
114 if (!in_array($value, $branches2)) {
115 unset($branches1[$key]);
116 }
117 }
118 return array_pop($branches1); // We don't know any keys in $branches, so we use array_pop here. Also it'll return NULL if needed
119 }
120
121 /**
122 * Menu callback for 'admin/project/versioncontrol-repositories/clearlock/git'
123 * (expecting a $repo_id as one more path argument):
124 * Clears the update lock for the specified repository
125 */
126 function versioncontrol_git_clearlock_repository_callback($repo_id) {
127 if (is_numeric($repo_id)) {
128 $repository = VersioncontrolRepositoryCache::getInstance()->getRepository($repo_id);
129 $repository->data['versioncontrol_git']['locked'] = 0;
130 $repository->update();
131 drupal_set_message(t('Cleared the lock for the repository.'));
132 }
133 drupal_goto('admin/project/versioncontrol-repositories');
134 }
135
136 /**
137 * Menu callback for 'admin/project/versioncontrol-repositories/update/git'
138 * (expecting a $repo_id as one more path argument):
139 * Retrieve/validate the specified repository, fetch new commits, tags
140 * and branches by invoking the git executable, output messages and
141 * redirect back to the repository page.
142 */
143 function versioncontrol_git_update_repository_callback($repo_id) {
144 if (is_numeric($repo_id)) {
145 $repository = VersioncontrolRepositoryCache::getInstance()->getRepository($repo_id);
146
147 if (isset($repository)) {
148 $update_method = $repository->data['versioncontrol_git']['update_method'];
149 }
150 }
151 if (isset($update_method) && $update_method == VERSIONCONTROL_GIT_UPDATE_CRON) {
152 // Set timeout limit to 3600 seconds as it can take a long time
153 // to process the log initially.
154 if (!ini_get('safe_mode')) {
155 set_time_limit(3600);
156 }
157 if (_versioncontrol_git_update_repository($repository)) {
158 drupal_set_message(t('Fetched new log entries.'));
159 }
160 else {
161 drupal_set_message(t('Error while fetching new log entries.'), 'error');
162 }
163 }
164 else { // $repo_id is not a number or doesn't correlate to any repository.
165 drupal_set_message(t('No such repository, did not fetch anything.'));
166 }
167 drupal_goto('admin/project/versioncontrol-repositories');
168 }
169
170 /**
171 * Actually update the repository by fetching commits and other stuff
172 * directly from the repository, invoking the git executable.
173 *
174 * @return
175 * TRUE if the logs were updated, or FALSE if fetching and updating the logs
176 * failed for whatever reason.
177 */
178 function _versioncontrol_git_update_repository(&$repository) {
179 include_once(drupal_get_path('module', 'versioncontrol_git') .'/versioncontrol_git.log.inc');
180 return _versioncontrol_git_log_update_repository($repository);
181 }

  ViewVC Help
Powered by ViewVC 1.1.2