Example #1
0
        // Example 'p4 fstat' output:
        // ... depotFile //DOW2/Tech/ASSETS/Simulation/Attrib/Templates/position.xml
        // ... clientFile c:\DOW2\ASSETS\Simulation\Attrib\Templates\position.xml
        // ... isMapped
        // ... headAction branch
        // ... headType text
        // ... headTime 1178746388
        // ... headRev 1
        // ... headChange 8283
        // ... headModTime 1174929670
        // ... haveRev 1
        // ... action edit
        // ... change default
        // ... type text
        // ... actionOwner beau.brennen
        // ... ... otherOpen0 beau.brennen@R-BBRENNEN0372-2
        // ... ... otherAction0 edit
        // ... ... otherChange0 default
        // ... ... otherLock0 beau.brennen@R-BBRENNEN0372-2
        // ... ... otherOpen1 beau.brennen@R-BBRENNEN0372-3
        // ... ... otherAction1 edit
        // ... ... otherChange1 default
        // ... ... otherOpen 2
        // ... ... otherLock
        public static List<FileStats> GetFileStats( string filePath )
        {
            List<FileStats> fileStats = new List<FileStats>();

            if( P4Shell.Online == false )
                return fileStats;

            Execute( string.Format( "fstat {0}", filePath ), null );

            FileStats curFileStats = null;

            string[] errors = m_Error.Split(new string[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);

            for (int lineIndex = 0; lineIndex < errors.Length; ++lineIndex)
            {
                string line = errors[lineIndex];

                if (line.Contains(" - no such file(s)."))
                {
                    // This indicates the file isn't in p4, so make an unaddded file entry
                    curFileStats = new FileStats();
                    fileStats.Add(curFileStats);

                    int valueIndex = line.IndexOf(" - no such file(s).");
                    curFileStats.UnaddedFilename = line.Substring(0, valueIndex);
                    curFileStats = null;    // Don't accidentally populate this with more data, since this is the only line relating to this file
                }
            }

            string[] output = m_Output.Split( new string[]{"\r\n"}, StringSplitOptions.RemoveEmptyEntries );

            for( int lineIndex=0; lineIndex<output.Length; ++lineIndex )
            {
                string line = output[lineIndex];

                if (line.Contains(" - no such file(s)."))
                {
                    // This indicates the file isn't in p4, so make an unaddded file entry
                    curFileStats = new FileStats();
                    fileStats.Add(curFileStats);

                    int valueIndex = line.IndexOf(" - no such file(s).");
                    curFileStats.UnaddedFilename = line.Substring(0, valueIndex);
                    curFileStats = null;    // Don't accidentally populate this with more data, since this is the only line relating to this file
                }
                else if (line.Contains("depotFile"))
                {
                    // "depotFile" is the first line of every fstat returned.
                    // Therefore create a new FileStats object and update our current index.
                    curFileStats = new FileStats();
                    fileStats.Add( curFileStats );

                    int valueIndex = line.IndexOf( "depotFile" ) + "depotFile".Length + 1;
                    curFileStats.DepotFile = line.Substring( valueIndex );
                }
                else if( line.Contains( "clientFile" ) )
                {
                    int valueIndex = line.IndexOf( "clientFile" ) + "clientFile".Length + 1;
                    curFileStats.ClientFile = line.Substring( valueIndex );
                }
                else if( line.Contains( "headAction" ) )
                {
                    curFileStats.HeadAction = StringToAction( line.Substring( line.LastIndexOf( ' ' ) + 1 ) );
                }
                else if( line.Contains( "headRev" ) )
                {
                    curFileStats.HeadRev = int.Parse( line.Substring( line.LastIndexOf( ' ' ) + 1 ) );
                }
                else if( line.Contains( "headChange" ) )
                {
                    curFileStats.HeadChange = int.Parse( line.Substring( line.LastIndexOf( ' ' ) + 1 ) );
                }
                else if( line.Contains( "haveRev" ) )
                {
                    curFileStats.HaveRev = int.Parse( line.Substring( line.LastIndexOf( ' ' ) + 1 ) );
                }
                else if( line.Contains( "action " ) )
                {
                    int valueIndex = line.IndexOf( "action" ) + "action".Length + 1;
                    string actionName = line.Substring( valueIndex );
                    curFileStats.OurAction = StringToAction( actionName );
                }
                else if( line.Contains( "change " ) )
                {
                    string changelistIDString = line.Substring( line.LastIndexOf( ' ' ) + 1 );
                    if( string.Compare( changelistIDString, "default", true ) == 0 )
                        curFileStats.OurChangelistID = P4Shell.DefaultChangelistID;
                    else
                        curFileStats.OurChangelistID = int.Parse( changelistIDString );
                }
                else if( line.Contains( "ourLock" ) )
                {
                    curFileStats.OurLock = true;
                }
                else if( line.Contains( "otherOpen " ) )
                {
                    // Note: This conditional must come before the 'otherOpen' (with no space) conditional.
                }
                else if( line.Contains( "otherOpen" ) )
                {
                    int otherIndex = FileStats.Other.GetIndex( line, "otherOpen" );

                    // Ensure we have enough 'others' allocated.
                    while( curFileStats.Others.Count <= otherIndex )
                        curFileStats.Others.Add( new FileStats.Other() );

                    curFileStats.Others[otherIndex].User = line.Substring( line.LastIndexOf( ' ' ) + 1 );
                }
                else if( line.Contains( "otherAction" ) )
                {
                    int otherIndex = FileStats.Other.GetIndex( line, "otherAction" );
                    string actionName = line.Substring( line.LastIndexOf( ' ' ) + 1 );
                    curFileStats.Others[otherIndex].Action = StringToAction( actionName );
                }
                else if( line.Contains( "otherChange" ) )
                {
                    int		otherIndex	= FileStats.Other.GetIndex(line , "otherChange");
                    string	changelist	= line.Substring( line.LastIndexOf( ' ' ) + 1 );

                    curFileStats.Others[otherIndex].ChangelistID = ( changelist == "default" ? -1 : int.Parse( changelist ) );
                }
                else if( line.Contains( "otherLock" ) && line.Contains( "otherLock " ) == false )
                {
                    int otherIndex = FileStats.Other.GetIndex( line, "otherLock" );
                    curFileStats.LockedByOtherIndex = otherIndex;
                }
                else if( line.Contains( "resolveFromFile0" ) )	// note: this index may change, I'm not entirely sure what it's for.
                {
                    int valueIndex = line.IndexOf( "resolveFromFile0" ) + "resolveFromFile0".Length + 1;
                    curFileStats.ResolveFromFile = line.Substring( valueIndex );
                }
            }

            return fileStats;
        }
Example #2
0
 public static bool IsHeadRevisionDelete(FileStats fileStat)
 {
     return (fileStat.HeadAction == Action.Delete);
 }