Changeset 10473


Ignore:
Timestamp:
01/04/11 03:08:36 (2 years ago)
Author:
GeorgeClark
Message:

Item9238: Add git svn info support.

  • Support web.topic format
  • Documentation changes
Location:
trunk/RepositoryPlugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/RepositoryPlugin/data/System/RepositoryPlugin.txt

    r10469 r10473  
    3131 
    3232---+++ 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> 
     33If installed, the ==%<nop>REPO{}%== macro will expand to the status of this topic file - =%WEB%/%TOPIC%.txt=. 
    3734 
    3835%REPO{}% 
    3936 
     37---+++ =git svn info= report for this topic's repository 
     38If installed, the ==%<nop>REPO{"svninfo"}%== report will expand to the svn information about the repository that contains this topic. 
     39 
     40%REPO{"svninfo"}% 
     41 
    4042---+++ Report for Main.WebHome 
    41 <verbatim> 
    42 %REPO{web="Main" topic="WebHome"}% 
    43 </verbatim> 
     43The ==%<nop>REPO{web="Main" topic="WebHome"}%== (or alternate form ==%<nop>REPO{topic="Main.WebHome"}%== ) expands to a report on the specified topic file. 
    4444 
    45 %REPO{web="Main" topic="WebHome"}% 
     45%REPO{topic="Main.WebHome"}% 
    4646 
    4747---+++ Report for =Foswiki::Plugins::RepositoryPlugin= 
    48 <verbatim> 
    49 %REPO{module="Foswiki::Plugins::RepositoryPlugin"}% 
    50 </verbatim> 
     48The ==%<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. 
    5149 
    5250%REPO{module="Foswiki::Plugins::RepositoryPlugin"}% 
     
    5856---++ Info 
    5957 
    60 Many thanks to the following sponsors for supporting this work: 
    61    * Acknowledge any sponsors here 
    62  
    63 |  Author(s): | | 
    64 |  Copyright: | &copy; | 
     58|  Author(s): | Foswiki:Main.GeorgeClark,  Foswiki Contributors | 
     59|  Copyright: | &copy; Foswiki Contibutors | 
    6560|  License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] | 
    6661|  Release: | %$RELEASE% | 
  • trunk/RepositoryPlugin/lib/Foswiki/Plugins/RepositoryPlugin.pm

    r10470 r10473  
    2626require Foswiki::Func;       # The plugins API 
    2727require Foswiki::Plugins;    # For the API version 
     28use Cwd; 
     29 
     30# 
    2831 
    2932# $VERSION is referred to by Foswiki, and is the only global variable that 
     
    4245# One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: 
    4346our $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'; 
    4548 
    4649# You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use 
     
    5356# and topic level. 
    5457our $NO_PREFS_IN_TOPIC = 1; 
    55 our $REPO_TYPE = '';            # Global - can be cached by persistent perl 
     58our $REPO_TYPE         = '';    # Global - can be cached by persistent perl 
    5659 
    5760my $svnbin; 
     
    9093      || '../'; 
    9194 
    92  
    93     Foswiki::Func::registerTagHandler( 'REPO',    \&_REPO ); 
     95    Foswiki::Func::registerTagHandler( 'REPO', \&_REPO ); 
    9496 
    9597    # Plugin correctly initialized 
     
    116118    my $module = $params->{module} || ''; 
    117119 
    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} || ''; 
    120123 
    121124    if ( Scalar::Util::tainted($web) ) { 
     
    129132    } 
    130133 
    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} ) ); 
    132139 
    133140    my $thisfile; 
    134141 
    135142    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/ ); 
    137146        $module =~ s/[^\w:]//g; 
    138147 
     
    146155    } 
    147156    else { 
    148         $thisfile = $Foswiki::cfg{DataDir}.'/'.$web.'/'.$topic.'.txt'; 
     157        $thisfile = $Foswiki::cfg{DataDir} . '/' . $web . '/' . $topic . '.txt'; 
    149158    } 
    150159 
     
    157166    } 
    158167 
    159     $absfile ||= $thisfile;  
    160     my $texit; 
    161  
    162     my $repoRoot = _findRepoRoot ( $absfile ); 
     168    $absfile ||= $thisfile; 
     169    my $exit; 
     170 
     171    my $repoRoot = _findRepoRoot($absfile); 
    163172    return "*Unable to find git root:* =$absfile= " unless ($repoRoot); 
    164173 
    165174    my $repoLoc = "--git-dir=$repoRoot/.git --work-tree=$repoRoot"; 
    166175 
    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 
    191211    $report .= "*File Status:* ($topicStatus) - $status\n\n"; 
    192212 
    193     $report .= "*Last Commit:* \n" 
    194         . '<verbatim>' 
    195         . $topicinfo 
    196         . '</verbatim>' unless $texit; 
     213    $report .= "*Last Commit:* \n" . '<verbatim>' . $topicinfo . '</verbatim>' 
     214      unless $exit; 
    197215 
    198216    return $report; 
    199217 
    200  
    201218    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/ ); 
    206223 
    207224    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 # 
    243257 
    244258    my $cmd = $params->{_DEFAULT} || ''; 
     
    246260    if ( $cmd eq 'date' ) { 
    247261        my ( $output, $exit ) = 
    248           Foswiki::Sandbox->sysCommand( "$gitbin log -1 ", 
    249              ); 
     262          Foswiki::Sandbox->sysCommand( "$gitbin log -1 ", ); 
    250263        ($output) = $output =~ /^Date:\s+(.*)$/m; 
    251264        return "<verbatim>($output)</verbatim>"; 
     
    253266    elsif ( $cmd eq 'author' ) { 
    254267        my ( $output, $exit ) = 
    255           Foswiki::Sandbox->sysCommand( "$gitbin log -1 ", 
    256              ); 
     268          Foswiki::Sandbox->sysCommand( "$gitbin log -1 ", ); 
    257269        ($output) = $output =~ /^Author:\s+(.*)$/m; 
    258270        return "<verbatim>($output)</verbatim>"; 
     
    260272    elsif ( $cmd eq 'log' ) { 
    261273        my ( $output, $exit ) = 
    262           Foswiki::Sandbox->sysCommand( "$gitbin log -5 ", 
    263              ); 
     274          Foswiki::Sandbox->sysCommand( "$gitbin log -5 ", ); 
    264275        return "<verbatim>($output)</verbatim>"; 
    265276    } 
    266     elsif ( $cmd eq 'branch') { 
     277    elsif ( $cmd eq 'branch' ) { 
    267278        my ( $output, $exit ) = 
    268           Foswiki::Sandbox->sysCommand( "$gitbin branch", 
    269              ); 
     279          Foswiki::Sandbox->sysCommand( "$gitbin branch", ); 
    270280        ($output) = $output =~ /^\*(.*)$/m; 
    271281        return "$output"; 
    272    } 
    273    else { 
    274        return $repoInfo{type}; 
    275        } 
     282    } 
     283    else { 
     284        return $repoInfo{type}; 
     285    } 
    276286 
    277287} 
     
    281291    my $repoFile = shift;    # full path of a file in repo 
    282292 
    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); 
    285295    my $repoRoot; 
    286296 
    287297    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" ); 
    295306 
    296307    return 0; 
Note: See TracChangeset for help on using the changeset viewer.