Example #1
0
 /// <summary>
 /// Add a file to the cache
 /// </summary>
 /// <param name="filePath"></param>
 public void AddToCache(string filePath)
 {
     _repo = filePath;
     try
     {
         Collection <SvnStatusEventArgs> statusContents;
         if (_svnClient.GetStatus(_repo, new SvnStatusArgs
         {
             Depth = SvnDepth.Infinity,
             RetrieveAllEntries = true
         }, out statusContents))
         {
             foreach (var content in statusContents)
             {
                 var contentStatusData = new SvnStatusData(content);
                 _statusCache.StoreItem(_statusCache.CreateItem(content.FullPath, contentStatusData));
                 var handler = SvnStatusUpdatedEvent;
                 handler?.Invoke(this, new SvnStatusUpdatedEventArgs(content.FullPath));
             }
         }
     }
     catch (Exception e)
     {
         //TODO: confirm this is ok
     }
 }
Example #2
0
        static bool MightBeNestedWorkingCopy(SvnStatusData status)
        {
            switch (status.LocalNodeStatus)
            {
            case SvnStatus.NotVersioned:
            case SvnStatus.Ignored:
            case SvnStatus.Obstructed:
                return(true);

            default:
                return(false);
            }
        }
Example #3
0
        public SvnItem(string fullPath, SvnStatusData status)
            : base(fullPath)
        {
            if (status == null)
            {
                throw new ArgumentNullException("status");
            }

            _status = status;

            _enqueued = true;
            RefreshTo(status);
            _enqueued = false;
        }
Example #4
0
        void RefreshTo(NoSccStatus status, SvnNodeKind nodeKind)
        {
            _cookie      = NextCookie();
            _statusDirty = XBool.False;

            var set   = SvnItemState.None;
            var unset = SvnItemState.Modified | SvnItemState.Added | SvnItemState.HasCopyOrigin
                        | SvnItemState.Deleted | SvnItemState.ContentConflicted | SvnItemState.Ignored
                        | SvnItemState.Obstructed | SvnItemState.Replaced | SvnItemState.Versioned
                        | SvnItemState.SvnDirty | SvnItemState.PropertyModified | SvnItemState.PropertiesConflicted | SvnItemState.Conflicted
                        | SvnItemState.Obstructed | SvnItemState.MustLock | SvnItemState.IsWCRoot
                        | SvnItemState.HasProperties | SvnItemState.HasLockToken | SvnItemState.HasCopyOrigin
                        | SvnItemState.MovedHere;

            switch (status)
            {
            case NoSccStatus.NotExisting:
                SetState(set, SvnItemState.Exists | SvnItemState.ReadOnly | SvnItemState.IsDiskFile | SvnItemState.IsDiskFolder | SvnItemState.Versionable | unset);
                _status = SvnStatusData.NotExisting;
                break;

            case NoSccStatus.NotVersionable:
                unset |= SvnItemState.Versionable;
                goto case NoSccStatus.NotVersioned;     // fall through

            case NoSccStatus.NotVersioned:
                SetState(SvnItemState.Exists | set, SvnItemState.None | unset);
                _status = SvnStatusData.NotVersioned;
                break;

            case NoSccStatus.Unknown:
            default:
                SetDirty(set | unset);
                _statusDirty = XBool.True;
                break;
            }

            InitializeFromKind(nodeKind);
        }
Example #5
0
        /// <summary>
        /// Copies all information from other.
        /// </summary>
        /// <param name="lead"></param>
        /// <remarks>When this method is called the other item will eventually replace this item</remarks>
        void ISvnItemUpdate.RefreshTo(SvnItem lead)
        {
            if (lead == null)
            {
                throw new ArgumentNullException("lead");
            }
            else if (lead._status == null)
            {
                throw new InvalidOperationException("Lead status = null");
            }

            _status      = lead._status;
            _statusDirty = lead._statusDirty;

            var current = lead._currentState;
            var valid   = lead._validState;

            SetState(current & valid, (~current) & valid);
            _ticked   = false;
            _modified = lead._modified;
            _cookie   = NextCookie(); // Status 100% the same, but changed... Cookies are free ;)
        }
Example #6
0
 void ISvnItemUpdate.RefreshTo(SvnStatusData status)
 {
     _ticked = false;
     RefreshTo(status);
 }
Example #7
0
        void RefreshTo(SvnStatusData status)
        {
            if (status == null)
            {
                throw new ArgumentNullException("status");
            }

            if (status.LocalNodeStatus == SvnStatus.External)
            {
                // When iterating the status of an external in it's parent directory
                // We get an external status and no really usefull information

                SetState(SvnItemState.Exists | SvnItemState.Versionable | SvnItemState.IsDiskFolder,
                         SvnItemState.IsDiskFile | SvnItemState.ReadOnly | SvnItemState.MustLock | SvnItemState.IsTextFile);

                if (_statusDirty != XBool.False)
                {
                    _statusDirty = XBool.True; // Walk the path itself to get the data you want
                }
                return;
            }
            else if (MightBeNestedWorkingCopy(status) && IsDirectory)
            {
                // A not versioned directory might be a working copy by itself!

                if (_statusDirty == XBool.False)
                {
                    return; // No need to remove valid cache entries
                }
                if (SvnTools.IsManagedPath(FullPath))
                {
                    _statusDirty = XBool.True; // Walk the path itself to get the data

                    // Extract useful information we got anyway

                    SetState(SvnItemState.Exists | SvnItemState.Versionable | SvnItemState.Versioned | SvnItemState.IsWCRoot | SvnItemState.IsDiskFolder,
                             SvnItemState.IsDiskFile | SvnItemState.ReadOnly | SvnItemState.MustLock | SvnItemState.IsTextFile);

                    return;
                }
                else
                {
                    SetState(SvnItemState.None, SvnItemState.IsWCRoot);
                }
                // Fall through
            }

            _cookie      = NextCookie();
            _statusDirty = XBool.False;
            _status      = status;

            const SvnItemState unset = SvnItemState.Modified | SvnItemState.Added |
                                       SvnItemState.HasCopyOrigin | SvnItemState.Deleted | SvnItemState.ContentConflicted |
                                       SvnItemState.Ignored | SvnItemState.Obstructed | SvnItemState.Replaced |
                                       SvnItemState.MovedHere;

            const SvnItemState managed = SvnItemState.Versioned;


            // Let's assume status is more recent than our internal property cache
            // Set all caching properties we can

            var svnDirty        = true;
            var exists          = true;
            var provideDiskInfo = true;

            switch (status.LocalNodeStatus)
            {
            case SvnStatus.None:
                SetState(SvnItemState.None, managed | unset);
                svnDirty        = false;
                exists          = false;
                provideDiskInfo = false;
                break;

            case SvnStatus.NotVersioned:
                // Node exists but is not managed by us in this directory
                // (Might be from an other location as in the nested case)
                SetState(SvnItemState.None, unset | managed);
                svnDirty = false;
                break;

            case SvnStatus.Ignored:
                // Node exists but is not managed by us in this directory
                // (Might be from an other location as in the nested case)
                SetState(SvnItemState.Ignored, unset | managed);
                svnDirty = false;
                break;

            case SvnStatus.Added:
                if (status.IsMoved && status.IsCopied)
                {
                    SetState(managed | SvnItemState.Added | SvnItemState.HasCopyOrigin | SvnItemState.MovedHere, unset);
                }
                else if (status.IsCopied)
                {
                    SetState(managed | SvnItemState.Added | SvnItemState.HasCopyOrigin, unset);
                }
                else
                {
                    SetState(managed | SvnItemState.Added, unset);
                }

                if (status.LocalTextStatus == SvnStatus.Modified)
                {
                    SetState(SvnItemState.Modified, SvnItemState.None);
                }
                else if (status.LocalTextStatus == SvnStatus.Normal)
                {
                    SetState(SvnItemState.None, SvnItemState.Modified);
                }
                break;

            case SvnStatus.Replaced:
                if (status.IsMoved && status.IsCopied)
                {
                    SetState(managed | SvnItemState.Replaced | SvnItemState.HasCopyOrigin | SvnItemState.MovedHere, unset);
                }
                else if (status.IsCopied)
                {
                    SetState(managed | SvnItemState.Replaced | SvnItemState.HasCopyOrigin, unset);
                }
                else
                {
                    SetState(managed | SvnItemState.Replaced, unset);
                }

                if (status.LocalTextStatus == SvnStatus.Modified)
                {
                    SetState(SvnItemState.Modified, SvnItemState.None);
                }
                else if (status.LocalTextStatus == SvnStatus.Normal)
                {
                    SetState(SvnItemState.None, SvnItemState.Modified);
                }
                break;

            case SvnStatus.Modified:
            case SvnStatus.Conflicted:
            {
                var done = false;
                switch (status.LocalTextStatus)
                {
                case SvnStatus.Modified:
                    SetState(managed | SvnItemState.Modified, unset);
                    done = true;
                    break;

                case SvnStatus.Conflicted:
                    SetState(managed | SvnItemState.ContentConflicted | SvnItemState.Conflicted, unset);
                    done = true;
                    break;
                }
                if (!done)
                {
                    goto case SvnStatus.Normal;
                }
                break;
            }

            case SvnStatus.Obstructed:     // node exists but is of the wrong type
                SetState(SvnItemState.None, managed | unset);
                provideDiskInfo = false;   // Info is wrong
                break;

            case SvnStatus.Missing:
                exists          = false;
                provideDiskInfo = false;     // Info is wrong
                SetState(managed, unset);
                break;

            case SvnStatus.Deleted:
                SetState(managed | SvnItemState.Deleted, unset);
                if (status.LocalFileExists)
                {
                    exists = provideDiskInfo = true;
                }
                else
                {
                    exists          = false;
                    provideDiskInfo = false;     // Folder might still exist
                }
                break;

            case SvnStatus.External:
                // Should be handled above
                throw new InvalidOperationException();

            case SvnStatus.Incomplete:
                SetState(managed, unset);
                break;

            default:
                Trace.WriteLine(string.Format("Ignoring undefined status {0} in SvnItem.Refresh()", status.LocalNodeStatus));
                provideDiskInfo = false;     // Can't trust an unknown status
                goto case SvnStatus.Normal;

            case SvnStatus.Normal:
                SetState(managed | SvnItemState.Exists, unset);
                svnDirty = false;
                break;
            }

            if (exists)
            {
                SetState(SvnItemState.Versionable, SvnItemState.None);
            }
            else
            {
                SetState(SvnItemState.None, SvnItemState.Versionable);
            }

            if (status.Conflicted)
            {
                SetState(SvnItemState.Conflicted, SvnItemState.None);
            }
            else
            {
                SetState(SvnItemState.None, SvnItemState.Conflicted);
            }


            var hasProperties = true;

            switch (status.LocalPropertyStatus)
            {
            case SvnStatus.None:
                hasProperties = false;
                SetState(SvnItemState.None, SvnItemState.PropertiesConflicted | SvnItemState.PropertyModified | SvnItemState.HasProperties);
                break;

            case SvnStatus.Modified:
                SetState(SvnItemState.PropertyModified | SvnItemState.HasProperties,
                         SvnItemState.PropertiesConflicted);
                svnDirty = true;
                break;

            case SvnStatus.Conflicted:
                SetState(SvnItemState.PropertyModified | SvnItemState.PropertiesConflicted | SvnItemState.HasProperties,
                         SvnItemState.None);
                svnDirty = true;
                break;

            case SvnStatus.Normal:
            default:
                SetState(SvnItemState.HasProperties,
                         SvnItemState.PropertiesConflicted | SvnItemState.PropertyModified);
                break;
            }

            if (svnDirty)
            {
                SetState(SvnItemState.SvnDirty, SvnItemState.None);
            }
            else
            {
                SetState(SvnItemState.None, SvnItemState.SvnDirty);
            }

            if (!hasProperties)
            {
                SetState(SvnItemState.None, SvnItemState.MustLock);
            }

            if (provideDiskInfo)
            {
                if (exists) // Behaviour must match updating from UpdateAttributeInfo()
                {
                    switch (status.NodeKind)
                    {
                    case SvnNodeKind.Directory:
                        SetState(SvnItemState.IsDiskFolder | SvnItemState.Exists, SvnItemState.ReadOnly | SvnItemState.MustLock | SvnItemState.IsTextFile | SvnItemState.IsDiskFile);
                        break;

                    case SvnNodeKind.File:
                        SetState(SvnItemState.IsDiskFile | SvnItemState.Exists, SvnItemState.IsDiskFolder);
                        break;

                    default:
                        // Handle direct replacement without an additional stat
                        if (status.LocalFileExists)
                        {
                            goto case SvnNodeKind.File;
                        }
                        break;
                    }
                }
                else
                {
                    SetState(SvnItemState.None, SvnItemState.Exists);
                }
            }

            if (status.IsLockedLocal)
            {
                SetState(SvnItemState.HasLockToken, SvnItemState.None);
            }
            else
            {
                SetState(SvnItemState.None, SvnItemState.HasLockToken);
            }
        }