Changeset 10473
- Timestamp:
- 01/04/11 03:08:36 (2 years ago)
- Location:
- trunk/RepositoryPlugin
- Files:
-
- 2 edited
-
data/System/RepositoryPlugin.txt (modified) (2 diffs)
-
lib/Foswiki/Plugins/RepositoryPlugin.pm (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/RepositoryPlugin/data/System/RepositoryPlugin.txt
r10469 r10473 31 31 32 32 ---+++ Report for this topic 33 If installed, the REPO macro will expand to the status of this topic file. 34 <verbatim> 35 %REPO{}% 36 </verbatim> 33 If installed, the ==%<nop>REPO{}%== macro will expand to the status of this topic file - =%WEB%/%TOPIC%.txt=. 37 34 38 35 %REPO{}% 39 36 37 ---+++ =git svn info= report for this topic's repository 38 If installed, the ==%<nop>REPO{"svninfo"}%== report will expand to the svn information about the repository that contains this topic. 39 40 %REPO{"svninfo"}% 41 40 42 ---+++ Report for Main.WebHome 41 <verbatim> 42 %REPO{web="Main" topic="WebHome"}% 43 </verbatim> 43 The ==%<nop>REPO{web="Main" topic="WebHome"}%== (or alternate form ==%<nop>REPO{topic="Main.WebHome"}%== ) expands to a report on the specified topic file. 44 44 45 %REPO{ web="Main" topic="WebHome"}%45 %REPO{topic="Main.WebHome"}% 46 46 47 47 ---+++ Report for =Foswiki::Plugins::RepositoryPlugin= 48 <verbatim> 49 %REPO{module="Foswiki::Plugins::RepositoryPlugin"}% 50 </verbatim> 48 The ==%<nop>REPO{module="Foswiki::Plugins::RepositoryPlugin"}%== provides a report on the Plugin module implementing the %REPO macro. Note that an alternative to [[%SYSTEMWEB%.PerlDoc]] - [[%SYSTEMWEB%.RepoPerlDoc]] is provided with this plugin. 51 49 52 50 %REPO{module="Foswiki::Plugins::RepositoryPlugin"}% … … 58 56 ---++ Info 59 57 60 Many thanks to the following sponsors for supporting this work: 61 * Acknowledge any sponsors here 62 63 | Author(s): | | 64 | Copyright: | © | 58 | Author(s): | Foswiki:Main.GeorgeClark, Foswiki Contributors | 59 | Copyright: | © Foswiki Contibutors | 65 60 | License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] | 66 61 | Release: | %$RELEASE% | -
trunk/RepositoryPlugin/lib/Foswiki/Plugins/RepositoryPlugin.pm
r10470 r10473 26 26 require Foswiki::Func; # The plugins API 27 27 require Foswiki::Plugins; # For the API version 28 use Cwd; 29 30 # 28 31 29 32 # $VERSION is referred to by Foswiki, and is the only global variable that … … 42 45 # One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: 43 46 our $SHORTDESCRIPTION = 44 'Repo Plugin - Displays information about the repository if running from a git or svn checkout';47 'Repo Plugin - Displays information about the repository if running from a git or svn checkout'; 45 48 46 49 # You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use … … 53 56 # and topic level. 54 57 our $NO_PREFS_IN_TOPIC = 1; 55 our $REPO_TYPE = '';# Global - can be cached by persistent perl58 our $REPO_TYPE = ''; # Global - can be cached by persistent perl 56 59 57 60 my $svnbin; … … 90 93 || '../'; 91 94 92 93 Foswiki::Func::registerTagHandler( 'REPO', \&_REPO ); 95 Foswiki::Func::registerTagHandler( 'REPO', \&_REPO ); 94 96 95 97 # Plugin correctly initialized … … 116 118 my $module = $params->{module} || ''; 117 119 118 my $web = $params->{web} || $theWeb; 119 my $topic = $params->{topic} || $theTopic; 120 my $web = $params->{web} || $theWeb; 121 my $topic = $params->{topic} || $theTopic; 122 my $default = $params->{_DEFAULT} || ''; 120 123 121 124 if ( Scalar::Util::tainted($web) ) { … … 129 132 } 130 133 131 return '<blockquote class="foswikiAlert"> %X% Error: =module= and =web / topic= parameters cannot be combined. </blockquote>' if ($module && ($params->{web} || $params->{topic}) ); 134 ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $web, $topic ); 135 136 return 137 '<blockquote class="foswikiAlert"> %X% Error: =module= and =web / topic= parameters cannot be combined. </blockquote>' 138 if ( $module && ( $params->{web} || $params->{topic} ) ); 132 139 133 140 my $thisfile; 134 141 135 142 if ($module) { 136 return '<blockquote class="foswikiAlert"> %X% Error: Only Foswiki modules can be queried </blockquote>' unless ($module =~ m/^Foswiki/); 143 return 144 '<blockquote class="foswikiAlert"> %X% Error: Only Foswiki modules can be queried </blockquote>' 145 unless ( $module =~ m/^Foswiki/ ); 137 146 $module =~ s/[^\w:]//g; 138 147 … … 146 155 } 147 156 else { 148 $thisfile = $Foswiki::cfg{DataDir} .'/'.$web.'/'.$topic.'.txt';157 $thisfile = $Foswiki::cfg{DataDir} . '/' . $web . '/' . $topic . '.txt'; 149 158 } 150 159 … … 157 166 } 158 167 159 $absfile ||= $thisfile; 160 my $ texit;161 162 my $repoRoot = _findRepoRoot ( $absfile);168 $absfile ||= $thisfile; 169 my $exit; 170 171 my $repoRoot = _findRepoRoot($absfile); 163 172 return "*Unable to find git root:* =$absfile= " unless ($repoRoot); 164 173 165 174 my $repoLoc = "--git-dir=$repoRoot/.git --work-tree=$repoRoot"; 166 175 167 (my $topicStatus, $texit) = 168 Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc status --porcelain $absfile ", 169 ); 170 171 $topicStatus = substr( $topicStatus, 0, 2); 172 173 return "*File not known to git:* =$absfile= " if ($topicStatus eq '??'); 174 175 my $status = $topicStatus =~ m/\ [MD]/ ? 'Modified, not updated in index' 176 : $topicStatus =~ m/M[\ MD]/ ? 'updated in index' 177 : $topicStatus =~ m/A[\ MD]/ ? 'added to index' 178 : $topicStatus =~ m/D[\ M]/ ? 'deleted from index' 179 : $topicStatus =~ m/R[\ MD]/ ? 'renamed in index' 180 : $topicStatus =~ m/C[\ MD]/ ? 'copied in index' 181 : $topicStatus eq '' ? 'up to date' 182 : 'unknown'; 183 184 (my $topicinfo, $texit) = 185 Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc log -1 $absfile ", 186 ); 187 188 my $report = 189 "*Repo file:* =$absfile= \n\n*Repo root:* $repoRoot\n\n"; 190 176 if ( $default eq 'svninfo' ) { 177 my ($curdir) = getcwd =~ m/^(.*)$/; 178 chdir($repoRoot); 179 ( my $repoInfo, $exit ) = 180 Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc svn info", ); 181 chdir($curdir); 182 my $report .= " " . '<verbatim>' . $repoInfo . '</verbatim>' 183 unless $exit; 184 185 return $report; 186 } 187 188 ( my $topicStatus, $exit ) = Foswiki::Sandbox->sysCommand( 189 "$gitbin $repoLoc status --porcelain $absfile ", 190 ); 191 192 $topicStatus = substr( $topicStatus, 0, 2 ); 193 194 return "*File not known to git:* =$absfile= " if ( $topicStatus eq '??' ); 195 196 my $status = 197 $topicStatus =~ m/\ [MD]/ ? 'Modified, not updated in index' 198 : $topicStatus =~ m/M[\ MD]/ ? 'updated in index' 199 : $topicStatus =~ m/A[\ MD]/ ? 'added to index' 200 : $topicStatus =~ m/D[\ M]/ ? 'deleted from index' 201 : $topicStatus =~ m/R[\ MD]/ ? 'renamed in index' 202 : $topicStatus =~ m/C[\ MD]/ ? 'copied in index' 203 : $topicStatus eq '' ? 'up to date' 204 : 'unknown'; 205 206 ( my $topicinfo, $exit ) = 207 Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc log -1 $absfile ", ); 208 209 my $report = "*Repo file:* =$absfile= \n\n*Repo root:* $repoRoot\n\n"; 210 191 211 $report .= "*File Status:* ($topicStatus) - $status\n\n"; 192 212 193 $report .= "*Last Commit:* \n" 194 . '<verbatim>' 195 . $topicinfo 196 . '</verbatim>' unless $texit; 213 $report .= "*Last Commit:* \n" . '<verbatim>' . $topicinfo . '</verbatim>' 214 unless $exit; 197 215 198 216 return $report; 199 217 200 201 218 my ( $gitinfo, $gexit ) = 202 Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc svn info ", 203 ); 204 205 $repoInfo{type} = 'git' unless ($gexit || $gitinfo =~ m/Not a git repository/);219 Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc svn info ", ); 220 221 $repoInfo{type} = 'git' 222 unless ( $gexit || $gitinfo =~ m/Not a git repository/ ); 206 223 207 224 my ( $svninfo, $sexit ) = 208 Foswiki::Sandbox->sysCommand( "$svnbin $repoLoc info ", 209 ); 210 $repoInfo{type} = 'svn' unless ($sexit || $svninfo =~ m/not a working copy/); 211 212 213 # if ($repoInfo->{type} eq 'svn') { 214 # $svninfo =~ /Path: ( 215 # Path: . 216 # URL: http://svn.twiki.org/svn/twiki/trunk/core 217 # Repository Root: http://svn.twiki.org/svn 218 # Repository UUID: a00a5322-12db-0310-a70b-8735589c885e 219 # Revision: 19150 220 # Node Kind: directory 221 # Schedule: normal 222 # Last Changed Author: PeterThoeny 223 # Last Changed Rev: 19140 224 # Last Changed Date: 2010-06-27 02:42:03 -0400 (Sun, 27 Jun 2010) 225 # 226 # gac@cardinal: /data/gac/SVN/twiki/core $ cd - 227 # /data/gac/SVN/twiki 228 # gac@cardinal: /data/gac/SVN/twiki $ cd /var/www/foswiki/trunk/ 229 # gac@cardinal: /var/www/foswiki/trunk (Item9238-BuildContrib)$ git svn info 230 # Path: . 231 # URL: http://svn.foswiki.org/trunk 232 # Repository Root: http://svn.foswiki.org 233 # Repository UUID: 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 234 # Revision: 8030 235 # Node Kind: directory 236 # Schedule: normal 237 # Last Changed Author: CrawfordCurrie 238 # Last Changed Rev: 8030 239 # Last Changed Date: 2010-07-05 05:21:49 -0400 (Mon, 05 Jul 2010) 240 # 241 242 225 Foswiki::Sandbox->sysCommand( "$svnbin $repoLoc info ", ); 226 $repoInfo{type} = 'svn' 227 unless ( $sexit || $svninfo =~ m/not a working copy/ ); 228 229 # if ($repoInfo->{type} eq 'svn') { 230 # $svninfo =~ /Path: ( 231 # Path: . 232 # URL: http://svn.twiki.org/svn/twiki/trunk/core 233 # Repository Root: http://svn.twiki.org/svn 234 # Repository UUID: a00a5322-12db-0310-a70b-8735589c885e 235 # Revision: 19150 236 # Node Kind: directory 237 # Schedule: normal 238 # Last Changed Author: PeterThoeny 239 # Last Changed Rev: 19140 240 # Last Changed Date: 2010-06-27 02:42:03 -0400 (Sun, 27 Jun 2010) 241 # 242 # gac@cardinal: /data/gac/SVN/twiki/core $ cd - 243 # /data/gac/SVN/twiki 244 # gac@cardinal: /data/gac/SVN/twiki $ cd /var/www/foswiki/trunk/ 245 # gac@cardinal: /var/www/foswiki/trunk (Item9238-BuildContrib)$ git svn info 246 # Path: . 247 # URL: http://svn.foswiki.org/trunk 248 # Repository Root: http://svn.foswiki.org 249 # Repository UUID: 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 250 # Revision: 8030 251 # Node Kind: directory 252 # Schedule: normal 253 # Last Changed Author: CrawfordCurrie 254 # Last Changed Rev: 8030 255 # Last Changed Date: 2010-07-05 05:21:49 -0400 (Mon, 05 Jul 2010) 256 # 243 257 244 258 my $cmd = $params->{_DEFAULT} || ''; … … 246 260 if ( $cmd eq 'date' ) { 247 261 my ( $output, $exit ) = 248 Foswiki::Sandbox->sysCommand( "$gitbin log -1 ", 249 ); 262 Foswiki::Sandbox->sysCommand( "$gitbin log -1 ", ); 250 263 ($output) = $output =~ /^Date:\s+(.*)$/m; 251 264 return "<verbatim>($output)</verbatim>"; … … 253 266 elsif ( $cmd eq 'author' ) { 254 267 my ( $output, $exit ) = 255 Foswiki::Sandbox->sysCommand( "$gitbin log -1 ", 256 ); 268 Foswiki::Sandbox->sysCommand( "$gitbin log -1 ", ); 257 269 ($output) = $output =~ /^Author:\s+(.*)$/m; 258 270 return "<verbatim>($output)</verbatim>"; … … 260 272 elsif ( $cmd eq 'log' ) { 261 273 my ( $output, $exit ) = 262 Foswiki::Sandbox->sysCommand( "$gitbin log -5 ", 263 ); 274 Foswiki::Sandbox->sysCommand( "$gitbin log -5 ", ); 264 275 return "<verbatim>($output)</verbatim>"; 265 276 } 266 elsif ( $cmd eq 'branch' ) {277 elsif ( $cmd eq 'branch' ) { 267 278 my ( $output, $exit ) = 268 Foswiki::Sandbox->sysCommand( "$gitbin branch", 269 ); 279 Foswiki::Sandbox->sysCommand( "$gitbin branch", ); 270 280 ($output) = $output =~ /^\*(.*)$/m; 271 281 return "$output"; 272 }273 else {274 return $repoInfo{type};275 }282 } 283 else { 284 return $repoInfo{type}; 285 } 276 286 277 287 } … … 281 291 my $repoFile = shift; # full path of a file in repo 282 292 283 my ( $vol, $dir, $file) = File::Spec->splitpath( $repoFile);284 my @dirs = File::Spec->splitdir( $dir);293 my ( $vol, $dir, $file ) = File::Spec->splitpath($repoFile); 294 my @dirs = File::Spec->splitdir($dir); 285 295 my $repoRoot; 286 296 287 297 while ( scalar @dirs > 1 ) { 288 $repoRoot = File::Spec->catdir( @dirs ); 289 #print STDERR "Trying $repoRoot \n"; 290 last if (-d "$repoRoot/.git"); 291 pop(@dirs); 292 } 293 294 return $repoRoot if (-d "$repoRoot/.git"); 298 $repoRoot = File::Spec->catdir(@dirs); 299 300 #print STDERR "Trying $repoRoot \n"; 301 last if ( -d "$repoRoot/.git" ); 302 pop(@dirs); 303 } 304 305 return $repoRoot if ( -d "$repoRoot/.git" ); 295 306 296 307 return 0;
Note: See TracChangeset
for help on using the changeset viewer.
