From: Rob H. <for...@us...> - 2002-06-04 18:13:58
|
Update of /cvsroot/sandweb/sandweb/bin In directory usw-pr-cvs1:/tmp/cvs-serv31988 Modified Files: sandweb.cgi Log Message: checking in branching stuff.. Index: sandweb.cgi =================================================================== RCS file: /cvsroot/sandweb/sandweb/bin/sandweb.cgi,v retrieving revision 1.294 retrieving revision 1.295 diff -U2 -r1.294 -r1.295 --- sandweb.cgi 2 Jun 2002 18:40:59 -0000 1.294 +++ sandweb.cgi 4 Jun 2002 18:13:55 -0000 1.295 @@ -262,4 +262,37 @@ } + if ( $vcs_command eq "branch" ) { + my $branch_sync = CGI::param('branch_sync') || ''; + my $branch_switch = CGI::param('branch_switch') || ''; + my $trunk_sync = CGI::param('trunk_sync') || ''; + my $trunk_switch = CGI::param('trunk_switch') || ''; + my $create_branch = CGI::param('create_branch') || ''; + my $remove_branch = CGI::param('remove_branch') || ''; + if ($submit) { + branch_commit( + ck_auth => $ck_auth, + branch_sync => $branch_sync, + branch_switch => $branch_switch, + trunk_sync => $trunk_sync, + trunk_switch => $trunk_switch, + create_branch => $create_branch, + remove_branch => $remove_branch, + module_name => $module_name, + repo_name => $repo_name, + filename => \@filename, + location => $location, + ); + } else { + branch_menu( + ck_auth => $ck_auth, + module_name => $module_name, + repo_name => $repo_name, + filename => \@filename, + location => $location, + ); + } + exit; + } + vcs_commit( ck_auth => $ck_auth, @@ -1485,4 +1518,51 @@ ############################################################################### +# branch menu +# +# allows user to perform branch operations on file or files +# +# args: +# ck_auth - the sessions cookie +# filename - filename(s) to branch (NOTE: this is an array) +# repo_name - name of the current repository. +# module_name - name of the current module. +# users_dir - location of user sandbox directories. +############################################################################### + +sub branch_menu { + my %args = @_; + + my $ck_auth = $args{'ck_auth'}; + my $module_name = $args{'module_name'}; + my $repo_name = $args{'repo_name'}; + + my @filename = (); + my $count = 0; + while ( $args{'filename'}->[$count] ) { + push (@filename, $args{'filename'}->[$count]); + $count++; + } + my $filename = "@filename"; + + my $content = $ui->get_menu( + MENU => 'branch', + FILENAME => $filename, + PROGNAME => $progname, + MODULE_NAME => $module_name, + REPO_NAME => $repo_name, + ); + print CGI::header( -cookie => $ck_auth ); + $ui->print_popup( + TITLE=> 'SandWeb : branch menu', + MENU_TITLE => 'SandWeb', + SUBMENU_TITLE => 'branch menu', + FOOTER => '', + CONTENT => $content, + MESSAGE => $message, + ); +} + + +############################################################################### ############################################################################### ## Commit Menu Data @@ -2600,4 +2680,182 @@ +############################################################################### +# branch commit +# +# processes calls from branch menu to sync with/switch to trunk or branchname +# +# A Repository object is created and used. +# +# args: +# ck_auth - the sessions cookie +# filename - name of the file(s) that the vcs_command should +# be used with. NOTE: this is an array +# location - system path to the file(s) specified by filename +# repo_name - name of the current repository. +# module_name - name of the current module. +# users_dir - location of user sandbox directories. +# message - message to the VCS system. +############################################################################### + +sub branch_commit { + my %args = @_; + + my $ck_auth = $args{'ck_auth'}; + if (! load_config()) { + # no existing user config, forward to prefs menu + preferences_menu( ck_auth => $ck_auth ); + } + + my @filename = (); + my $count = 0; + while ( $args{'filename'}->[$count] ) { + push (@filename, $args{'filename'}->[$count]); + $count++; + } + my $module_name = $args{'module_name'}; + my $location = $args{'location'}; + my $message = CGI::param('message'); + my $username = $auth->get_username(); + my $users_dir = $config->{'paths'}->{'users_dir'}; + my $repo_name = $args{'repo_name'}; + my $prev_url = "$ENV{'HTTP_REFERER'}"; + $log->debug("prev_url $prev_url"); + my %return; + + my $branch_sync = $args{'branch_sync'} || ''; + my $branch_switch = $args{'branch_switch'} || ''; + my $trunk_sync = $args{'trunk_sync'} || ''; + my $trunk_switch = $args{'trunk_switch'} || ''; + my $create_branch = $args{'create_branch'} || ''; + my $remove_branch = $args{'remove_branch'} || ''; + + $log->debug("module_name: $module_name"); + $log->debug("username: $username"); + $log->debug("location: $location"); + + my $repo_server = $user->get_repo_server(repo => $repo_name); + my $repo_username = $user->get_repo_username(repo => $repo_name); + my $repo_password = $user->get_repo_password(repo => $repo_name); + my $repo_type = $user->get_repo_type(repo => $repo_name); + my $repo_connection = $user->get_repo_connection(repo => $repo_name); + my $repo_root = $user->get_repo_root(repo => $repo_name); + my $ssh_bin = $config->{'system'}->{'ssh_bin'}; + my $cvs_bin = $config->{'system'}->{'cvs_bin'}; + my $bindir = $config->{'system'}->{'bindir'}; + + my $sandbox = $user->{'paths'}->{'users_dir'} || ''; + + my @vcs_output = (); + my @vcs_error = (); + + my $repository = SandWeb::Repository->new( + root => $repo_root, + connection => $repo_connection, + 'vcs_username' => $repo_username, + 'vcs_password' => $repo_password, + 'unix_auth' => $unix_auth, + 'system_username' => $system_username, + 'system_password' => $system_password, + server => $repo_server, + repo_type => $repo_type, + sandbox => "$users_dir/$username/$repo_name/$module_name/$location", + 'ssh_bin' => $ssh_bin, + 'cvs_bin' => $cvs_bin, + 'bindir' => $bindir, + ); + + $log->debug("Repo name: $repo_name"); + $log->debug("Repo root: $repo_root"); + $log->debug("VCS sandbox: $users_dir/$username/$repo_name/$module_name/$location"); + $log->debug("Repo type: $repo_type"); + $log->debug("Filename(s): @filename"); + + if ($branch_sync) { + foreach my $file (@filename) { + %return = $repository->update( + file => "$file", + rev => "$branch_sync", + ); + push (@vcs_output, "$return{'output'}\n"); + push (@vcs_error, "$return{'error'}\n"); + } + } + if ($branch_switch) { + foreach my $file (@filename) { + %return = $repository->update( + file => "$file", + rev => "$branch_switch", + clobber => 1, + ); + push (@vcs_output, "$return{'output'}\n"); + push (@vcs_error, "$return{'error'}\n"); + } + } + if ($trunk_sync) { + foreach my $file (@filename) { + %return = $repository->update( + file => "$file", + reset => 1, + ); + push (@vcs_output, "$return{'output'}\n"); + push (@vcs_error, "$return{'error'}\n"); + } + } + if ($trunk_switch) { + foreach my $file (@filename) { + %return = $repository->update( + file => "$file", + clobber => 1, + reset => 1, + ); + push (@vcs_output, "$return{'output'}\n"); + push (@vcs_error, "$return{'error'}\n"); + } + } + + if ($create_branch) { + foreach my $file (@filename) { + %return = $repository->tag( + file => "$file", + name => "$create_branch", + branch => 1, + ); + push (@vcs_output, "$return{'output'}\n"); + push (@vcs_error, "$return{'error'}\n"); + } + } + if ($remove_branch) { + foreach my $file (@filename) { + %return = $repository->tag( + file => "$file", + name => "$remove_branch", + branch => 1, + delete => 1, + ); + push (@vcs_output, "$return{'output'}\n"); + push (@vcs_error, "$return{'error'}\n"); + } + } + + my $content = $ui->get_menu( + MENU => 'vcs_output', + LOCATION => $location, + FILENAME => @filename, + PROGNAME => $progname, + VCS_OUTPUT => join('', @vcs_output), + VCS_ERROR => join('', @vcs_error), + ); + + print CGI::header( -cookie => $ck_auth ); + $ui->print_popup( + TITLE=> "SandWeb : VCS branch", + MENU_TITLE => 'SandWeb', + SUBMENU_TITLE => "VCS branch", + FOOTER => '', + CONTENT => $content, + MESSAGE => $message, + ); + exit 0; +} |