// // Copyright 2000 Perforce Software. All rights reserved. // // This file is part of Perforce - the FAST SCM System. // // // p4wIntegProcessorView -- parses form in order to generate // integrate command #include <stdlib.h> #include <string.h> #include <p4wp4.h> #include "p4wView.h" #include "p4wIntegProcessorView.h" #include "p4wCmdPane.h" #include "p4wPreviewPane.h" p4wIntegProcessorView::p4wIntegProcessorView(p4wRequest & Request) : p4wView(Request) { // // Build a spec to parse the integrate action (preview or not), // and the integration type (from file, from path browser, or // using a branch view). Then build the title strings and set // some state variables accordingly. Error e; Spec spec; StrBufDict actionTable; spec.Add( "integType" ); SpecElem * se = spec.Add( "formActions" ); se->type = SDT_LLIST; if( !fRequest.ProcessForm( spec, &actionTable ) ) { fShortTitle.Set( "Error" ); fFullTitle.Set( "Error" ); return; } StrPtr * chosenAction = NULL; StrPtr * action = NULL; for( int curAction = 0; ( action = actionTable.GetVar( StrRef("formActions"), curAction ) ) != NULL; curAction++ ) { // See if this action is the one that was selected. Spec actionItemSpec; StrBufDict actionItemTable; actionItemSpec.Add( *action ); (void)fRequest.ProcessForm( actionItemSpec, &actionItemTable ); chosenAction = actionItemTable.GetVar( action->Text() ); if( chosenAction != NULL ) { chosenAction = action; break; } } // // Integration type StrPtr *integType = actionTable.GetVar( "integType" ); if( !integType ) { fIntegType = fromPath; } else { fIntegType = (IntegType)atoi( integType->Text() ); } // // Preview mode or not... if( *chosenAction == "preview" ) { fShortTitle.Set( "Command Result" ); fFullTitle.Set( "Integrate Preview Result" ); fPreview = 1; fTitle.Set( "Integrate " ); } else if( *chosenAction == "integrate" ) { fShortTitle.Set( "Command Result" ); fFullTitle.Set( "Integrate Result" ); fPreview = 0; fTitle.Set( "Integrate " ); } else { fShortTitle.Set( "Error" ); fFullTitle.Set( "Error" ); } } p4wIntegProcessorView::~p4wIntegProcessorView() { } void p4wIntegProcessorView::RenderContent() { // // Issue integrate command based on options chosen in form Spec spec; StrBufDict specTable; spec.Add( "Path1" ); spec.Add( "Path2" ); spec.Add( "Branch" ); spec.Add( "Use" ); spec.Add( "DestDir" ); spec.Add( "Dir" ); spec.Add( "In" ); spec.Add( "Rev1" ); spec.Add( "Rev2" ); spec.Add( "Pattern" ); spec.Add( "Changelist" ); spec.Add( "fl" )->type = SDT_LLIST; StrBuf pathArg1; StrBuf pathArg2; // // If post data is missing return immediately. if( !fRequest.ProcessForm( spec, &specTable ) ) { RenderError("Requested URL is invalid in this context."); return; } const StrPtr *use = specTable.GetVar( "Use" ); const StrPtr *path1 = specTable.GetVar( "Path1" ); const StrPtr *path2 = specTable.GetVar( "Path2" ); const StrPtr *branch = specTable.GetVar( "Branch" ); const StrPtr *destDir = specTable.GetVar( "DestDir" ); const StrPtr *dir = specTable.GetVar( "Dir" ); const StrPtr *in = specTable.GetVar( "In" ); const StrPtr *rev1 = specTable.GetVar( "Rev1" ); const StrPtr *rev2 = specTable.GetVar( "Rev2" ); const StrPtr *pattern = specTable.GetVar( "Pattern" ); const StrPtr *changelist = specTable.GetVar( "Changelist" ); // // Process all the flags if( fPreview ) { fRequest.p4Arg( "-n" ); fTitle << "-n "; } int j; StrPtr *flag; StrRef flagVar( "fl" ); for( j = 0; flag = specTable.GetVar( flagVar, j ); j++ ) { fRequest.p4Arg( flag->Text() ); fTitle << flag->Text() << " "; } if( changelist->Length() && *changelist != "default" ) { fRequest.p4Arg( "-c" ); fRequest.p4Arg( changelist->Text() ); fTitle << "-c " << changelist->Text() << " "; } // // Determine integrate command type based on options chosen // from form, and where command was invoked. enum CmdType { pathsOnly, pathsAndBranch, branchOnly } cmdType; if( *use == "p" && fIntegType != fromBranch ) { cmdType = pathsOnly; } else if( (fIntegType == fromBranch && *use == "b" ) || ( in && fIntegType == fromPath && *use == "b" && *in == "all" ) ) { cmdType = branchOnly; } else { cmdType = pathsAndBranch; } // Parse form and generate command. // // Command takes 2 path args. if( cmdType == pathsOnly ) { if( !path1->Length() || !path2->Length() ) { if( fIntegType == fromPath ) RenderError("Error: Required path argument is missing."); else RenderError("Error: Required file argument is missing."); return; } if( *destDir == "to" ) { pathArg1.Set( path2 ); pathArg2.Set( path1 ); } else { pathArg1.Set( path1 ); pathArg2.Set( path2 ); } if( fIntegType == fromPath ) { SetPathArg( pathArg1, pattern ); SetPathArg( pathArg2, pattern ); } // // Command takes a branch argument, and possibly a revision // argument. } else if( cmdType == branchOnly ) { if( !branch->Length() ) { RenderError("Error: Required branch argument is missing."); return; } if( *dir == "reverse" ) { fRequest.p4Arg( "-r" ); fTitle << "-r "; } fRequest.p4Arg( "-b" ); fRequest.p4Arg( branch->Text() ); fTitle << "-b " << branch->Text() << " "; if( pattern->Length() && *pattern != "..." ) { pathArg1.Set( "//" ); pathArg1 << pattern; } // // Command takes a branch and path arguments. } else { if( !path1->Length() || !branch->Length() ) { if( fIntegType == fromFile ) RenderError("Error: Required file or branch argument is missing."); else RenderError("Error: Required path or branch argument is missing."); return; } fRequest.p4Arg( "-b" ); fRequest.p4Arg( branch->Text() ); fTitle << "-b " << branch->Text() << " "; if( *destDir == "to" ) { pathArg1.Set( "//..." ); pathArg2.Set( path1 ); if( fIntegType != fromFile ) SetPathArg( pathArg2, pattern ); } else { pathArg2.Set( "//..." ); pathArg1.Set( path1 ); if( fIntegType != fromFile ) SetPathArg( pathArg1, pattern ); } fRequest.p4Arg( "-s" ); fTitle << "-s "; } // // Revision args always append to the first path argument if( rev1->Length() ) { char fc = rev1->Text()[0]; if( fc != '@' && fc != '#' ) pathArg1 << "@"; pathArg1 << rev1; if( rev2->Length() ) pathArg1 << "," << rev2; } else if( rev2->Length() ) { char fc = rev2->Text()[0]; if( fc != '@' && fc != '#' ) pathArg1 << "@"; pathArg1 << rev2; } // // Send the path args, if any if( pathArg1.Length() ) { fRequest.p4Arg( pathArg1.Text() ); fTitle << pathArg1.Text() << " "; } if( pathArg2.Length() ) { fRequest.p4Arg( pathArg2.Text() ); fTitle << pathArg2.Text() << " "; } // Run the command. if( fPreview ) { p4wPreviewPane prevPane( *this, fRequest, fTitle.Text() ); fRequest.p4( "integrate", 0, 0, &prevPane ); fRequest.p4Wait(); } else { p4wCmdPane cmdPane( *this, fRequest, fTitle.Text() ); fRequest.p4( "integrate", 0, 0, &cmdPane ); fRequest.p4Wait(); } } void p4wIntegProcessorView::SetPathArg( StrBuf &path, const StrPtr *pattern ) { // // Construct the path argument from the path and pattern // that were entered on the form. const char *end; int useSysDelim = 0; char sysDelim; char delim; p4wURL urlMaker; // // Handle the case where the user ended the path with "...". // If the pattern is missing or is also "...", the path // needs no massaging. Otherwise the pattern takes // precedence, so we need to strip the "..." and append // the pattern. end = path.Text() + strlen( path.Text() ) - 1; if( strlen( path.Text() ) > 2 && !strcmp( end - 2, "..." ) ) { if ( pattern->Length() && *pattern != "..." ) { path.Set( path.Text(), strlen( path.Text() ) - 3 ); path << pattern; } return; } // // Get the path delimiter. If the path was entered in depot syntax, // the delimiter is '/'; otherwise it is the system-dependent // delimiter. (void)urlMaker.GetSysDirDelim( &sysDelim ); if( !strncmp( path.Text(), "//", 2 ) ) { delim = '/'; } else { delim = sysDelim; useSysDelim = 1; } // // If path does not end in the delimiter, append it if( *end != delim ) { if( useSysDelim ) path << urlMaker.GetSysDirDelim( NULL ); else path << "/"; } // // Finally append the pattern or ... if there is no pattern if( pattern->Length() ) path << pattern; else path << "..."; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/Views/p4wIntegProcessorView.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |