[Bps-public-commit] r10047 - in SVKUI/trunk: lib lib/SVKUI/Model share/web/templates/__jifty/error share/web/templates/project

clsung at bestpractical.com clsung at bestpractical.com
Sun Dec 23 21:50:06 EST 2007


Author: clsung
Date: Sun Dec 23 21:50:05 2007
New Revision: 10047

Modified:
   SVKUI/trunk/lib/SVKUI.pm
   SVKUI/trunk/lib/SVKUI/Model/Project.pm
   SVKUI/trunk/lib/SVKUI/View.pm
   SVKUI/trunk/share/web/templates/__jifty/error/command_failed
   SVKUI/trunk/share/web/templates/project/index.html

Log:
- lots fixes and preparation for SVKUI-bm

Modified: SVKUI/trunk/lib/SVKUI.pm
==============================================================================
--- SVKUI/trunk/lib/SVKUI.pm	(original)
+++ SVKUI/trunk/lib/SVKUI.pm	Sun Dec 23 21:50:05 2007
@@ -4,8 +4,8 @@
 
 use base 'Class::Data::Inheritable';
 use SVK;
+use SVK::Logger;
 use SVK::XD;
-use SVK::Util;
 __PACKAGE__->mk_classdata('_svk');
 __PACKAGE__->mk_classdata('_peekoutput');
 
@@ -67,6 +67,7 @@
     local $/;
     $output = <$fh>;
     close $fh;
+    $output =~ s,GET request.*\n,,g;
     open $fh, '>', Jifty->config->app('output') or die $!;
     close $fh;
     $class->update_mirror();
@@ -77,9 +78,9 @@
 sub peek {
     my $class = shift;
     my $reset = shift || 0;
-    $class->_peekoutput(undef) if $reset;
+    #$class->_peekoutput(undef) if $reset;
     return $class->_peekoutput if $class->_peekoutput;
-    warn "use new peek";
+    #warn "use new peek";
     use FileHandle;
     my $fh;
     $fh = new FileHandle Jifty->config->app('output'), "r";

Modified: SVKUI/trunk/lib/SVKUI/Model/Project.pm
==============================================================================
--- SVKUI/trunk/lib/SVKUI/Model/Project.pm	(original)
+++ SVKUI/trunk/lib/SVKUI/Model/Project.pm	Sun Dec 23 21:50:05 2007
@@ -99,9 +99,57 @@
     return 0;
 }
 
+sub try_mirror_project {
+    my $self = shift;
+    my $path = shift;
+    my $uri = $self->url;
+    $uri =~ s{(?:/(?=trunk$)|/(?:tags|branche?s?)$)}{};
+    $uri =~ s/\/$//;
+    my $ra = SVN::Ra->new(
+	url => $uri,
+	auth => [ SVN::Client::get_simple_prompt_provider(\&simple_prompt,1)]
+    );
+
+    my $repos_root = $ra->get_repos_root();
+    $ra->reparent($repos_root);
+    my ($uri_path) = $self->url =~ m/^$repos_root(.*)$/;
+    warn $uri_path;
+
+    my %prop = %{ ($ra->get_file('',$ra->get_latest_revnum, undef))[1] };
+
+    # if found projects, then mirror from it
+    # if uri_path exists, we can use it to determine which project it is
+    if (grep { $_ =~ /^svk:project/ } keys %prop) {
+	warn 'Has project';
+	my %projects =
+	    map { $_ => 1 }
+	    grep { $_ =~ s/^svk:project:([^:]+):.*$/$1/ } keys %prop;
+	my @projs = keys %projects;
+	for my $proj (@projs) {
+	    $projects{$proj} = $prop{'svk:project:'.$proj.':path-trunk'};
+	    $projects{$proj} =~ s{/[^/]+$}{};
+	}
+	$path = '//mirror'.$projects{$projs[0]};
+	warn $path . " is changed";
+	$self->_set(column => 'url', value => $repos_root.$projects{$projs[0]});
+    }
+
+    return $path;
+}
+
+sub simple_prompt {
+    my $cred = shift;
+    $cred->username($current_user);
+    $cred->password($current_pass);
+    warn "Setting user/pass to ".$current_user."/".$current_pass;
+}
+
 sub try_mirror {
     my $self = shift;
     my $path = shift;
+    
+    $path = $self->try_mirror_project($path);
+
     return 1 unless defined($self->url);
     #local *SVK::Config::_simple_prompt = sub {
 #	my ($cred, $realm, $default_username, $may_save, $pool) = @_;

Modified: SVKUI/trunk/lib/SVKUI/View.pm
==============================================================================
--- SVKUI/trunk/lib/SVKUI/View.pm	(original)
+++ SVKUI/trunk/lib/SVKUI/View.pm	Sun Dec 23 21:50:05 2007
@@ -113,18 +113,18 @@
 #   XXX: show () will not have the same arguments passing when click
     render_region (name => 'svksync2', 
 	force_path => '/svksync2',
-	force_arguments => { project_name => $project->name, dosync => 0, sid => $sid });
+	arguments => { project_name => $project->name, dosync => 0, sid => $sid });
 };
 
 template 'svksync2' => sub { # TD implementation of share/web/templates/svksync
     my $p_name = get('project_name');
+    my $dosync = get('dosync');
+    my $sid = get('sid');
     my $project = SVKUI::Model::Project->new();
     $project->load_by_cols( name => $p_name );
     unless ($project->id) {
         redirect '/';
     }
-    my $dosync = get('dosync');
-    my $sid = get('sid');
     my $message;
     if ($dosync > 0) {
 	h3 { "Syncing project $p_name ..." };
@@ -135,10 +135,17 @@
     if ($project->synced == 1) {
 	dt { Jifty->web->link( label => "Project synced", url => '/project/'.$p_name ); }
     } elsif ($dosync == 0) {
-	dt { Jifty->web->link( label => "Sync $p_name", onclick => { args => { project_name => $p_name, dosync => 1, sid => $sid } }); }
+	dt {
+	    Jifty->web->link( label => "Sync $p_name",
+		onclick => {
+		    args => { project_name => $p_name, dosync => 1, sid => $sid }
+		}
+	    );
+	}
     };
     }; # dl
     if ($project->id and $dosync) {
+	warn "trying sync...";
 	if ($project->try_sync()) {
 	    $message = 'sync failed';
 	} else {
@@ -146,6 +153,7 @@
 	};
 	warn "Canceling $sid";
 	Jifty->subs->cancel($sid) if $sid;
+	warn "Canceled $sid";
     }
     div { $message };
 };
@@ -156,21 +164,21 @@
     my $cmd = get('command') || '';
     my $args = get ('args') || '';
     my $relpath = get ('path') || '';
-    my $mirror = SVKUI::Model::Project->new();
-    $mirror->load_by_cols( name => $mirror_name );
-    if (!$mirror->id) {  # mirror record not found
+    my $project = SVKUI::Model::Project->new();
+    $project->load_by_cols( name => $mirror_name );
+    if (!$project->id) {  # mirror record not found
         redirect '/';
     }
 
     my $command = SVKUI::Model::Command->new();
     my $ret;
 
-    my $rootpath = Jifty->config->app('checkoutroot')."/".$mirror->name;
+    my $rootpath = Jifty->config->app('checkoutroot')."/".$project->name;
     if ($cmd =~ m/checkout/i) {
-	unless ($mirror->id) {
+	unless ($project->id) {
 	    redirect '/__jifty/error/project/not_found';
 	}
-	$ret = $command->cmd($cmd, $mirror->localrepos, $rootpath);
+	$ret = $command->cmd($cmd, $project->localrepos, $rootpath);
     } elsif ($cmd ne '') {
 	if ($args ne '') {
 	    $ret = $command->cmd($cmd, $rootpath.'/'.$relpath, $args);
@@ -185,12 +193,13 @@
 	$ret = $command->cmd('help', 'commands');
     }
     if ($ret) {
-	set mirror => $mirror;
+	set project => $project;
 	show '/__jifty/error/command_failed';
     } else {
-	dl {
-	    pre { outs($command->output_raw) };
-	};
+	set project => $project;
+	my $message = "Project ".$project->name." execute command ".$cmd;
+	set message => $message;
+	redirect '/projects';
     }
 };
 

Modified: SVKUI/trunk/share/web/templates/__jifty/error/command_failed
==============================================================================
--- SVKUI/trunk/share/web/templates/__jifty/error/command_failed	(original)
+++ SVKUI/trunk/share/web/templates/__jifty/error/command_failed	Sun Dec 23 21:50:05 2007
@@ -1,5 +1,5 @@
 <%args>
-$mirror => undef
+$project => undef
 </%args>
 <%init>
 my $log_info = SVKUI->output;
@@ -10,14 +10,14 @@
 </%init>
 
 <&| /_elements/wrapper, title => _('Error of "command" command') &>
-<h1><%$mirror->name%></h1>
+<h1><%$project->name%></h1>
 <blockquote>
     <%$log_info%>
 </blockquote>
-% if ($mirror->localrepos and $need_checkout) {
-<% $mirror->localrepos %>
+% if ($project->localrepos and $need_checkout) {
+<% $project->localrepos %>
 <h4>Click to do the initial checkout</h4>
-<%Jifty->web->link( url => '/ia2/'.$mirror->name.'/checkout', label => 'Checkout')%>
+<%Jifty->web->link( url => '/ia2/'.$project->name.'/checkout', label => 'Checkout')%>
 % } else {
 <h4>Return to SVKUI</h4>
 <%Jifty->web->link( url => '/', label => 'SVKUI')%>

Modified: SVKUI/trunk/share/web/templates/project/index.html
==============================================================================
--- SVKUI/trunk/share/web/templates/project/index.html	(original)
+++ SVKUI/trunk/share/web/templates/project/index.html	Sun Dec 23 21:50:05 2007
@@ -3,7 +3,7 @@
 $message => undef
 </%args>
 <%init>
-my @outputs = SVKUI->peek->getlines;
+my @outputs = SVKUI->output;
 my $output = join "", @outputs;
 my $edit = Jifty->web->new_action(class =>'UpdateProject', record => $project);
 </%init>



More information about the Bps-public-commit mailing list