//------------------------------------------------------------------------------ // Copyright (c) 2004, Perforce Software, Inc. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //------------------------------------------------------------------------------ #include <clientapi.h> #include <error.h> #include <errorlog.h> #include <errornum.h> #include <enviro.h> #include <hostenv.h> #include <ident.h> #include <i18napi.h> #include <options.h> #include <debug.h> #include "adminclient.h" class MyIdent { public: void Format( StrBuf &b ); const char *name; const char *os; const char *rel; const char *patch; const char *api_rel; const char *api_patch; }; void MyIdent::Format( StrBuf &b ) { b.Clear(); b << "A Perforce client for Unix System Administrators.\n"; b << "Copyright 2004 Perforce Software. All rights reserved.\n"; b << name << "/" << os << "/" << rel << "/" << patch; b << " (Perforce API " << api_rel << "/" << api_patch << ")\n"; } MyIdent ident = { "P4U", ID_OS, P4U_VERSION, P4U_PATCH, ID_REL, ID_PATCH }; ErrorId usage = { ErrorOf( ES_CLIENT, 0, E_INFO, EV_USAGE, 0 ), "\n" "Usage:\n" "\n" " p4u [options] command [command-options] [command-args]\n\n" "\n" " Where options are:\n\n" " -h -? print this message\n" " -v level debug modes\n" " -V print version\n" " -x file read args from named file\n" "\n" " -c client set client name (default $P4CLIENT)\n" " -C charset set character set (default $P4CHARSET)\n" " -d dir set current directory for relative paths\n" " -H host set host name (default $P4HOST)\n" " -L language set message langauge (default $P4LANGUAGE)\n" " -p port set server port (default $P4PORT)\n" " -P password set user's password (default $P4PASSWD)\n" " -u user set user's username (default $P4USER)\n" "\n" " Try 'p4u help' for information on Perforce commands.\n" "\n" }; int main( int argc, char **argv ) { // // Parse the command line // Options opts; Error * e = new Error; StrPtr * s = 0; StrPtr * xfile = 0; opts.Parse( --argc, ++argv, "?C:c:d:H:hL:P:p:u:Vv:x:", OPT_ANY, usage, e); ErrorLog::Abort( e ); // // Now override the defaults with values from the command line // where appropriate. We don't have to worry about the values in the // environment or in P4CONFIG files since the ClientApi class will // load those for us. // AdminClient client; // // Simple options first // if( s = opts[ 'c' ] ) client.SetClient( s ); if( s = opts[ 'd' ] ) client.SetCwd( s ); if( s = opts[ 'H' ] ) client.SetHost( s ); if( s = opts[ 'L' ] ) client.SetLanguage( s ); if( s = opts[ 'P' ] ) client.SetPassword( s ); if( s = opts[ 'p' ] ) client.SetPort( s ); if( s = opts[ 'u' ] ) client.SetUser( s ); xfile = opts[ 'x' ]; // // Now the options that would cause us to exit without much further // ado. // if( opts[ 'h' ] || opts[ '?' ] ) { StrBuf t; e->Set( usage ); e->Fmt( &t ); printf( "%s", t.Text() ); exit( 0 ); } if( opts[ 'V' ] ) { StrBuf t; ident.Format( t ); printf( "%s", t.Text() ); return 0; } // // Now the options that need more complex handling // int i; for( i = 0; s = opts.GetValue( 'v', i ); i++ ) p4debug.SetLevel( s->Text() ); // // Charset needs special handling because ClientApi::SetCharset() // doesn't work properly. We need to use SetTrans() and that means // we need to lookup the value. We also check the environment value // now to make sure they're using a valid charset before we continue. // const char * charset = 0; if( s = opts[ 'C' ] ) { charset = s->Text(); } else { Enviro env; HostEnv hostEnv; StrBuf cwd; hostEnv.GetCwd( cwd ); env.Config( cwd ); charset = env.Get("P4CHARSET"); } if( charset ) { CharSetApi::CharSet cs = CharSetApi::Lookup( charset ); if( cs == (CharSetApi::CharSet) -1 ) { fprintf( stderr, "Bad Charset: %s is not a valid charset\n", charset ); return 1; } client.SetTrans( cs ); } // // If the user's forgotten to type a command, we'll run // 'p4 help' for them. // if( !argc ) { argv = new char*[2]; argv[ 0 ] = "help"; argv[ 1 ] = 0; argc = 1; } // // OK, we're about ready to go. Connect to the server // client.Init( e ); ErrorLog::Abort( e ); // // Run the command: // If we've got a -x flag we have to read our arguments from // a file. If not, we just go with what we've got. Get the simple // version out of the way first. // if( ! xfile ) { client.SetArgv( argc - 1, argv + 1 ); client.Run( argv[ 0 ] ); // Close connection client.Final( e ); ErrorLog::Abort( e ); return 0; } // -x version FileSys *xf = FileSys::Create( FST_TEXT ); xf->Set( *xfile ); xf->Open( FOM_READ, e ); ErrorLog::Abort( e ); StrBuf l; int eof = 0; int ac = 0; while( !e->Test() && !client.Dropped() && !eof ) { eof = !xf->ReadLine( &l, e ); if( !eof ) { if( ac == 0 ) client.SetArgv( argc - 1, argv + 1 ); client.SetVar( "", &l ); ac++; } if( eof && ac || ( ac == 128 ) ) { client.Run( argv[ 0 ] ); ac = 0; } } xf->Close( e ); ErrorLog::Abort( e ); client.Final( e ); ErrorLog::Abort( e ); return 0; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 4780 | Tony Smith |
Add support for 'p4u -x <file>'. Same functionality as 'p4 -x <file>'. It's the only feature I've really felt the lack of in using the initial release. |
||
#1 | 4662 | Tony Smith |
Add the first release of my Perforce command line client for Unix sysadmins. On a Unix box, some of the files you really want under version control need to be protected. P4 uses the user's umask to control the permissions on the files it manages but when you're managing a unix box these permissions can vary on a per-file basis and that makes it tricky to manage unix boxes properly with Perforce. Enter P4U. It uses the 2004.2 server's ability to store per-revision attributes to store a permission-mask for each file that requires custom handling. The bits in the mask are removed from the permissions of the relevant files when normal Perforce commands are executed using 'p4u' instead of 'p4'. i.e. p4u add /etc/shadow p4u attribute -n unixMask -v 077 /etc/shadow p4u submit This will cause /etc/shadow to have the mode you would hope for (0400). The mode will be restricted whenever you: p4u submit p4u edit p4u revert p4u sync Currently that's it. |