// Implementation of ClientDiffUser. Most of the real work is in DoDiff(). #include <clientapi.h> #include <enviro.h> #include <qapplication.h> #include <qlayout.h> #include <qmessagebox.h> #include <qprocess.h> #include <qtextedit.h> #define QTREEDIFFRUNNER_H #include "qtreediffrunner.h" #define QTREEDIFFDIALOG_H #include "qtreediffdialog.h" #include "clientdiffuser.h" ClientDiffUser::ClientDiffUser ( StrBuf file1, StrBuf file2, ClientApi* cli, Error* e ) :ClientUser(), client( cli ), f1( file1 ), f2( file2 ), error( e ), diffs( StrBuf() ) { } ClientDiffUser::~ClientDiffUser() { } // Figure out what diff method to use, and spawn a new window/dialog // with the result. If P4DIFF is set, use that; otherwise pop up a // dialog with "p4 diff2" results. void ClientDiffUser::DoDiff( QWidget* parent, bool binary ) { // Borrowed from ClientUser::Diff() - get P4DIFF/DIFF const char* diff = NULL; Enviro env = Enviro(); if ( binary ) { diff = env.Get( "P4DIFFBIN" ); } else { if ( !( diff = env.Get( "P4DIFF" ) ) ) diff = getenv( "DIFF" ); } if ( !diff ) { // Use "p4 diff2" and pop up a nice dialog. client->Init( error ); if ( error->Test() ) HandleError( error ); char* args[2]; args[0] = f1.Text(); args[1] = f2.Text(); client->SetArgv( 2, args ); client->Run( "diff2", this ); client->Final( error ); if ( error->Test() ) HandleError( error ); QTreeDiffDialog* dia = new QTreeDiffDialog( parent, diffs ); dia->exec(); delete dia; } else { // Use "p4 print -o" twice and P4DIFF those files. // First get two temp files FileSys* t1 = FileSys::CreateGlobalTemp( FST_TEXT ); t1->ClearDeleteOnClose(); // need to use it later, don't delete it t1->Open( FOM_WRITE, error ); t1->Chmod( FPM_RW, error ); t1->Close( error ); if ( error->Test() ) { HandleError( error ); return; } FileSys* t2 = FileSys::CreateGlobalTemp( FST_TEXT ); t2->ClearDeleteOnClose(); // need to use it later, don't delete it t2->Open( FOM_WRITE, error ); t2->Chmod( FPM_RW, error ); t2->Close( error ); if ( error->Test() ) { HandleError( error ); return; } // Now call "p4 print -o" using those filenames. client->Init( error ); if ( error->Test() ) { HandleError( error ); t1->Unlink(); t2->Unlink(); delete t1; delete t2; return; } char* args1[3]; args1[0] = "-o"; args1[1] = t1->Path().Text(); args1[2] = f1.Text(); client->SetArgv( 3, args1 ); client->Run( "print", this ); if ( client->Dropped() ) { client->Final( error ); HandleError( error ); t1->Unlink(); t2->Unlink(); delete t1; delete t2; return; } char* args2[3]; args2[0] = "-o"; args2[1] = t2->Path().Text(); args2[2] = f2.Text(); client->SetArgv( 3, args2 ); client->Run( "print", this ); client->Final( error ); if ( error->Test() ) { HandleError( error ); t1->Unlink(); t2->Unlink(); delete t1; delete t2; return; } // Now invoke P4DIFF using QTreeDiffRunner. It'll handle cleanup // of itself and the temp files, so we can just leave it. new QTreeDiffRunner( parent, diff, t1, t2, f1.Text(), f2.Text() ); } } // Pop up a dialog with error results. void ClientDiffUser::HandleError( Error* err ) { StrBuf msg; err->Fmt( &msg ); QMessageBox::warning ( qApp->activeWindow(), "P4QTree Warning", msg.Text(), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton ); err->Clear(); } // Header. Just spit it out as is. void ClientDiffUser::OutputInfo( char level, const_char* data ) { diffs.Append( data ); diffs.Append( "<br>\n" ); } // Diff text. Do HTML markup to color it purty. void ClientDiffUser::OutputText( const_char* data, int length ) { bool endline = false; // this keeps track of whether we just newlined diffs.Append( "<code>" ); for ( char* ptr = data ; *ptr ; ptr++ ) { if ( *ptr == '\n' ) // Newline { diffs.Append( "</font><br>\n" ); endline = true; } else if ( !endline ) //Body text { switch ( *ptr ) { case '>': diffs.Append( ">" ); break; case '<': diffs.Append( "<" ); break; default: diffs.Append( ptr, 1 ); break; } } else // Start of a line - color appropriately. { endline = false; switch ( *ptr ) { case '>': diffs.Append( "<font color=darkBlue>>" ); break; case '<': diffs.Append( "<font color=darkRed><" ); break; default: diffs.Append( "<font color=black><b>" ); diffs.Append( ptr, 1 ); break; } } } diffs.Append( "</code>" ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 2405 | Sam Stafford | Add support for binary diff programs, as well as "-l" and "-r" for P4Diff and SQUID. | ||
#2 | 2394 | Sam Stafford |
Fix uninitialized variable. No functional change. |
||
#1 | 2377 | Sam Stafford | P4QTree. |