added a single file CLOC support
This commit is contained in:
		| @ -107,5 +107,6 @@ LICENSE | ||||
|    jQuery JavaScript Library v1.4.2             See http://jquery.org/license | ||||
|    jQuery UI 1.8                                MIT or GPL | ||||
|    PHPGraphLib                                  MIT | ||||
|    CLOC 1.62                                    GPL | ||||
|    ------------------------------------------------------------------------ | ||||
|  | ||||
|  | ||||
| @ -9,7 +9,7 @@ License: GPL | ||||
| Group: Applications/Utilities | ||||
| Source0: %{name}-%{version}.tar.gz | ||||
|  | ||||
| Requires: httpd php php-ldap php-mysql php-gd subversion subversion-perl mod_dav_svn mod_perl perl-LDAP perl-Config-Simple perl-URI perl-DBI perl-Digest-SHA1 | ||||
| Requires: httpd php php-ldap php-mysql php-gd subversion subversion-perl mod_dav_svn mod_perl perl perl-LDAP perl-Config-Simple perl-URI perl-DBI perl-Digest-SHA1 | ||||
|  | ||||
| #BuildRequires: | ||||
| BuildRoot: %{_tmppath}/%{name}-%{version}-root | ||||
| @ -52,6 +52,7 @@ rm -rf $RPM_BUILD_ROOT | ||||
| /etc/codepot/post-commit | ||||
| /etc/codepot/pre-revprop-change | ||||
| /etc/codepot/post-revprop-change | ||||
| /etc/codepot/cloc.pl | ||||
| /etc/codepot/perl/Codepot/AccessHandler.pm | ||||
| /etc/codepot/perl/Codepot/AuthenHandler.pm | ||||
|  | ||||
|  | ||||
| @ -1,10 +1,10 @@ | ||||
|  | ||||
| cfgdir=$(CFGDIR) | ||||
| cfg_DATA = codepot.ini codepot.mysql codepot.a2ldap codepot.httpd | ||||
| cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change   | ||||
| cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change cloc.pl | ||||
|  | ||||
| perldir=$(CFGDIR)/perl/Codepot | ||||
| perl_SCRIPTS=perl/Codepot/AccessHandler.pm perl/Codepot/AuthenHandler.pm | ||||
|  | ||||
| EXTRA_DIST = $(cfg_DATA)  $(cfg_SCRIPTS) $(perl_SCRIPTS)  | ||||
| EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS) $(perl_SCRIPTS)  | ||||
|  | ||||
|  | ||||
| @ -151,10 +151,10 @@ sysconfdir = @sysconfdir@ | ||||
| target_alias = @target_alias@ | ||||
| wwwdir = @wwwdir@ | ||||
| cfg_DATA = codepot.ini codepot.mysql codepot.a2ldap codepot.httpd | ||||
| cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change   | ||||
| cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change cloc.pl | ||||
| perldir = $(CFGDIR)/perl/Codepot | ||||
| perl_SCRIPTS = perl/Codepot/AccessHandler.pm perl/Codepot/AuthenHandler.pm | ||||
| EXTRA_DIST = $(cfg_DATA)  $(cfg_SCRIPTS) $(perl_SCRIPTS)  | ||||
| EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS) $(perl_SCRIPTS)  | ||||
| all: all-am | ||||
|  | ||||
| .SUFFIXES: | ||||
|  | ||||
							
								
								
									
										9744
									
								
								codepot/etc/cloc.pl
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										9744
									
								
								codepot/etc/cloc.pl
									
									
									
									
									
										Executable file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -219,3 +219,10 @@ svn_min_commit_message_length = "0" | ||||
| ; Leave this empty for the default footer message | ||||
| ;------------------------------------------------------------------------------ | ||||
| footer = "" | ||||
|  | ||||
| ;------------------------------------------------------------------------------ | ||||
| ; CLOC command | ||||
| ;------------------------------------------------------------------------------ | ||||
| ; Full path to the CLOC command | ||||
| ;------------------------------------------------------------------------------ | ||||
| cloc_command_path =  "@CFGDIR@/cloc.pl" | ||||
|  | ||||
| @ -635,7 +635,7 @@ class Code extends Controller | ||||
| 		return $path; | ||||
| 	} | ||||
|  | ||||
| 	function graph ($type = '', $projectid = '', $path = '') | ||||
| 	function graph ($type = '', $projectid = '', $path = '', $rev = SVN_REVISION_HEAD) | ||||
| 	{ | ||||
| 		$this->load->model ('ProjectModel', 'projects'); | ||||
|  | ||||
| @ -659,12 +659,100 @@ class Code extends Controller | ||||
| 		if ($path == '.') $path = ''; /* treat a period specially */ | ||||
| 		$path = $this->_normalize_path ($path); | ||||
|  | ||||
| 		$file = $this->subversion->getHistory ($projectid, $path, SVN_REVISION_HEAD); | ||||
| 		$history = $file['history']; | ||||
| 		$history_count = count($history); | ||||
|  | ||||
| 		if ($type == 'commit-share-by-users') | ||||
| 		if ($type == 'cloc-file') | ||||
| 		{ | ||||
| 			// number of lines in a single file | ||||
|  | ||||
| 			$file = $this->subversion->getFile ($projectid, $path, $rev); | ||||
| 			if ($file === FALSE) | ||||
| 			{ | ||||
| 				header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');  | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			if ($file['type'] != 'file') | ||||
| 			{ | ||||
| 				header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');  | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			$tfname = @tempnam(__FILE__, 'xxx');  | ||||
| 			if ($tfname === FALSE) | ||||
| 			{ | ||||
| 				header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');  | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			$tfname = $tfname . '.' . pathinfo ($file['name'], PATHINFO_EXTENSION); | ||||
| 			@file_put_contents ($tfname, $file['content']); | ||||
|  | ||||
| 			$cloc_cmd = sprintf ('%s --quiet --csv --csv-delimiter=":" %s', CODEPOT_CLOC_COMMAND_PATH, $tfname); | ||||
| 			$cloc = @popen ($cloc_cmd, 'r'); | ||||
| 			if ($cloc === FALSE) | ||||
| 			{ | ||||
| 				@unlink ($tfname); | ||||
| 				header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');  | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			$line_count = 0; | ||||
| 			$counter = FALSE; | ||||
| 			while (!feof($cloc)) | ||||
| 			{ | ||||
| 				$line = @fgets ($cloc); | ||||
| 				if ($line_count == 2) | ||||
| 				{ | ||||
| 					$counter = explode (':', $line); | ||||
| 				} | ||||
| 				$line_count++; | ||||
| 			}  | ||||
|  | ||||
| 			@pclose ($cloc); | ||||
| 			@unlink ($tfname); | ||||
|  | ||||
| 			if ($counter === FALSE) | ||||
| 			{ | ||||
| 				$stats = array ( | ||||
| 					'no-data' => 0 | ||||
| 				); | ||||
| 				$title = $file['name']; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				$stats = array ( | ||||
| 					'blank' => (integer)$counter[2], | ||||
| 					'comment' => (integer)$counter[3], | ||||
| 					'code' => (integer)$counter[4], | ||||
| 					'total' => (integer)$counter[2] + (integer)$counter[3] + (integer)$counter[4] | ||||
| 				); | ||||
|  | ||||
| 				$title = $file['name'] . ' (' . $counter[1] . ')'; | ||||
| 			} | ||||
|  | ||||
| 			$this->load->library ('PHPGraphLib', array ('width' => 280, 'height' => 200), 'graph'); | ||||
| 			$this->graph->addData($stats); | ||||
| 			$this->graph->setTitle($title); | ||||
| 			$this->graph->setDataPoints(TRUE); | ||||
| 			$this->graph->setDataValues(TRUE); | ||||
| 			$this->graph->setBars(TRUE); | ||||
| 			$this->graph->setXValuesHorizontal(TRUE); | ||||
| 			$this->graph->setYValues (FALSE); | ||||
| 			$this->graph->createGraph(); | ||||
| 		} | ||||
| 		else if ($type == 'commit-share-by-users') | ||||
| 		{ | ||||
| 			// revision is ignored | ||||
| 			$file = $this->subversion->getHistory ($projectid, $path, SVN_REVISION_HEAD); | ||||
| 			if ($file === FALSE) | ||||
| 			{ | ||||
| 				header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');  | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			$history = $file['history']; | ||||
| 			$history_count = count($history); | ||||
|  | ||||
| 			$stats = array(); | ||||
| 			for ($i = 0; $i < $history_count; $i++) | ||||
| 			{ | ||||
| @ -679,13 +767,24 @@ class Code extends Controller | ||||
|  | ||||
| 			$this->load->library ('PHPGraphLibPie', array ('width' => 400, 'height' => 300), 'graph'); | ||||
| 			$this->graph->addData($stats); | ||||
| 			$this->graph->setTitle("Commit share by users"); | ||||
| 			$this->graph->setTitle('Commit share by users'); | ||||
| 			$this->graph->setLabelTextColor('50,50,50'); | ||||
| 			$this->graph->setLegendTextColor('50,50,50'); | ||||
| 			$this->graph->createGraph(); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			// revision is ignored | ||||
| 			$file = $this->subversion->getHistory ($projectid, $path, SVN_REVISION_HEAD); | ||||
| 			if ($file === FALSE) | ||||
| 			{ | ||||
| 				header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');  | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			$history = $file['history']; | ||||
| 			$history_count = count($history); | ||||
|  | ||||
| 			$stats = array(); | ||||
| 			for ($i = 0; $i < $history_count; $i++) | ||||
| 			{ | ||||
| @ -700,7 +799,7 @@ class Code extends Controller | ||||
|  | ||||
| 			$this->load->library ('PHPGraphLib', array ('width' => 400, 'height' => 300), 'graph'); | ||||
| 			$this->graph->addData($stats); | ||||
| 			$this->graph->setTitle("Commits by users"); | ||||
| 			$this->graph->setTitle('Commits by users'); | ||||
| 			$this->graph->setDataPoints(TRUE); | ||||
| 			$this->graph->setDataValues(TRUE); | ||||
| 			//$this->graph->setLine(TRUE); | ||||
|  | ||||
| @ -261,6 +261,14 @@ if (array_key_exists('properties', $file) && count($file['properties']) > 0) | ||||
| } | ||||
| ?> | ||||
| </pre> | ||||
|  | ||||
| <div class="title">CLOC</div> | ||||
| <?php | ||||
| 	/* TODO: show this if it's enabled in the user settings  */ | ||||
|         $graph_url = codepot_merge_path (site_url(), "/code/graph/cloc-file/{$project->id}/{$xpar}{$revreq}"); | ||||
|         print "<img src='{$graph_url}' />"; | ||||
| ?> | ||||
|  | ||||
| </div> <!-- code_file_mainarea_result_info --> | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -80,7 +80,8 @@ function load_ini ($file) | ||||
| 		array ('signin_for_code_search',       'boolean',     TRUE), | ||||
| 		array ('svn_for_members_only',         'boolean',     FALSE), | ||||
|  | ||||
| 		array ('footer',                       'string',      '') | ||||
| 		array ('footer',                       'string',      ''), | ||||
| 		array ('cloc_command_path',            'string',      CODEPOT_CFG_DIR.'/cloc.pl') | ||||
| 	); | ||||
|  | ||||
| 	foreach ($xcfgs as $x) | ||||
|  | ||||
| @ -10,8 +10,13 @@ | ||||
| 	white-space: nowrap; | ||||
| } | ||||
|  | ||||
| /*----------------------------------------------- | ||||
|  * file show view | ||||
|  *-----------------------------------------------*/ | ||||
|  | ||||
| #file_show_mainarea_result { | ||||
| 	position: relative; | ||||
| 	min-height: 13em; | ||||
| } | ||||
|  | ||||
| #file_show_mainarea_result_info { | ||||
|  | ||||
| @ -1,5 +1,10 @@ | ||||
| /*--------------------------------------------- | ||||
|  * wiki show | ||||
|  *---------------------------------------------*/ | ||||
|  | ||||
| #wiki_show_mainarea_result { | ||||
| 	position: relative; | ||||
| 	min-height: 13em; | ||||
| } | ||||
|  | ||||
| #wiki_show_mainarea_result_info { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user