예제 #1
0
        public SvnDirectory GetDirectory(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            lock (_lock)
            {
                SvnDirectory dir;

                if (DirectoryMap.TryGetValue(path, out dir))
                {
                    return(dir);
                }

                var item = this[path];

                if (item.IsDirectory)
                {
                    dir = new SvnDirectory(path);
                    dir.Add(item);
                    return(dir);
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #2
0
        internal void OnCleanup()
        {
            lock (_lock)
            {
                _postedCleanup = false;

                while (_cleanup.Count > 0)
                {
                    SvnDirectory dir  = _cleanup[0];
                    string       path = dir.FullPath;

                    _cleanup.RemoveAt(0);

                    for (int i = 0; i < dir.Count; i++)
                    {
                        SvnItem item = dir[i];
                        if (((ISvnItemUpdate)item).ShouldClean())
                        {
                            RemoveItem(item);
                            dir.RemoveAt(i--);
                        }
                    }

                    if (dir.Count == 0)
                    {
                        // We cache the path before.. as we don't want the svnitem to be generated again
                        _dirMap.Remove(path);
                    }
                }
            }
        }
예제 #3
0
 private void ScheduleForCleanup(SvnDirectory directory)
 {
     lock (_lock)
     {
         if (!_cleanup.Contains(directory))
         {
             _cleanup.Add(directory);
         }
     }
 }
예제 #4
0
        private void ScheduleForCleanup(SvnDirectory directory)
        {
            lock (_lock)
            {
                if (!_cleanup.Contains(directory))
                {
                    _cleanup.Add(directory);
                }

                if (!_postedCleanup)
                {
                    CommandService.SafePostTickCommand(ref _postedCleanup, AnkhCommand.SvnCacheFinishTasks);
                }
            }
        }
예제 #5
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
            {
                if (item.IsVersioned || !item.IsVersionable)
                {
                    continue;
                }

                SvnDirectory dir = item.ParentDirectory;
                if (dir != null && !dir.NeedsWorkingCopyUpgrade)
                {
                    return; // We found an add item
                }
            }

            e.Enabled = false;
        }
예제 #6
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            if (StatusCache == null || !StatusCache.EnableUpgradeCommand)
            {
                e.Enabled = false;
                return;
            }

            foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
            {
                SvnDirectory dir = item.ParentDirectory;
                if (dir != null && dir.NeedsWorkingCopyUpgrade)
                {
                    return;
                }
                else if (item.IsDirectory && item.AsDirectory().NeedsWorkingCopyUpgrade)
                {
                    return;
                }
            }
            e.Enabled = false;
        }
        protected List <SvnDirectory> GetSvnDirectories(SvnDirectoryType type)
        {
            List <SvnDirectory> listSvnDirectories = new List <SvnDirectory>();

            string physicalPath = Server.MapPath("/");

            string[] directories = Directory.GetDirectories(physicalPath, "buyer*");

            foreach (string directory in directories)
            {
                DirectoryInfo di           = new DirectoryInfo(directory);
                SvnDirectory  svnDirectory = new SvnDirectory()
                {
                    Name = di.Name
                };

                if (svnDirectory.Type == type)
                {
                    listSvnDirectories.Add(svnDirectory);
                }
            }

            return(listSvnDirectories);
        }
예제 #8
0
        private void StatDirectory(string walkPath, SvnDirectory directory, bool noWcAtAll)
        {
            // Note: There is a lock(_lock) around this in our caller

            bool canRead;
            var  adminName   = SvnClient.AdministrativeDirectoryName;
            var  noSccStatus = noWcAtAll ? NoSccStatus.NotVersionable : NoSccStatus.NotVersioned;

            foreach (var node in SccFileSystemNode.GetDirectoryNodes(walkPath, out canRead))
            {
                if (string.Equals(node.Name, adminName, StringComparison.OrdinalIgnoreCase) || node.IsHiddenOrSystem)
                {
                    continue;
                }

                SvnItem item;
                if (node.IsFile)
                {
                    if (!Map.TryGetValue(node.FullPath, out item))
                    {
                        StoreItem(CreateItem(node.FullPath, noSccStatus, SvnNodeKind.File));
                    }
                    else
                    {
                        ISvnItemUpdate updateItem = item;
                        if (updateItem.ShouldRefresh())
                        {
                            updateItem.RefreshTo(noSccStatus, SvnNodeKind.File);
                        }
                    }
                }
                else
                {
                    if (!Map.TryGetValue(node.FullPath, out item))
                    {
                        StoreItem(CreateItem(node.FullPath, noSccStatus, SvnNodeKind.Directory));
                    }
                    // Don't clear state of a possible working copy
                }
            }

            if (canRead) // The directory exists
            {
                SvnItem item;

                if (!Map.TryGetValue(walkPath, out item))
                {
                    StoreItem(CreateItem(walkPath, NoSccStatus.NotVersioned, SvnNodeKind.Directory));
                    // Mark it as existing if we are sure
                }
                else
                {
                    ISvnItemUpdate updateItem = item;
                    if (updateItem.ShouldRefresh())
                    {
                        updateItem.RefreshTo(NoSccStatus.NotVersioned, SvnNodeKind.Directory);
                    }
                }
            }

            // Note: There is a lock(_lock) around this in our caller
        }
예제 #9
0
        /// <summary>
        /// Refreshes the specified path using the specified depth
        /// </summary>
        /// <param name="path">A normalized path</param>
        /// <param name="pathKind"></param>
        /// <param name="depth"></param>
        /// <remarks>
        /// If the path is a file and depth is greater that <see cref="SvnDepth.Empty"/> the parent folder is walked instead.
        ///
        /// <para>This method guarantees that after calling it at least one up-to-date item exists
        /// in the statusmap for <paramref name="path"/>. If we can not find information we create
        /// an unspecified item
        /// </para>
        /// </remarks>
        void RefreshPath(string path, SvnNodeKind pathKind)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            var walkPath         = path;
            var walkingDirectory = false;

            switch (pathKind)
            {
            case SvnNodeKind.Directory:
                walkingDirectory = true;
                break;

            case SvnNodeKind.File:
                walkPath         = SvnTools.GetNormalizedDirectoryName(path);
                walkingDirectory = true;
                break;

            default:
                try
                {
                    if (File.Exists(path))     // ### Not long path safe
                    {
                        pathKind = SvnNodeKind.File;
                        goto case SvnNodeKind.File;
                    }
                }
                catch (PathTooLongException)
                { /* Fall through */ }
                break;
            }

            var args = new SvnStatusArgs();

            args.Depth = SvnDepth.Children;
            args.RetrieveAllEntries     = true;
            args.RetrieveIgnoredEntries = true;
            args.ThrowOnError           = false;

            lock (_lock)
            {
                ISvnDirectoryUpdate updateDir;
                SvnItem             walkItem = null;

                // We get more information for free, lets use that to update other items
                DirectoryMap.TryGetValue(walkPath, out var directory);
                if (null != directory)
                {
                    updateDir = directory;
                    updateDir.TickAll();
                }
                else
                {
                    // No existing directory instance, let's create one
                    directory = new SvnDirectory(walkPath);
                    updateDir = directory = GetDirectory(walkPath);
                    DirectoryMap[walkPath] = directory;
                }


                bool ok;
                var  statSelf  = false;
                var  noWcAtAll = false;

                // Don't retry file open/read operations on failure. These would only delay the result
                // (default number of delays = 100)
                using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0))
                {
                    ok = _client.Status(walkPath, args, RefreshCallback);
                }

                if (directory != null)
                {
                    walkItem = directory.Directory; // Might have changed via casing
                }
                if (!statSelf && null != walkItem)
                {
                    if (((ISvnItemUpdate)walkItem).ShouldRefresh())
                    {
                        statSelf = true;
                    }
                    else if (walkingDirectory && !walkItem.IsVersioned)
                    {
                        statSelf = true;
                    }
                }

                if (statSelf)
                {
                    // Svn did not stat the items for us.. Let's make something up

                    if (walkingDirectory)
                    {
                        StatDirectory(walkPath, directory, noWcAtAll);
                    }
                    else
                    {
                        // Just stat the item passed and nothing else in the Depth.Empty case

                        if (walkItem == null)
                        {
                            var truepath = SvnTools.GetTruePath(walkPath); // Gets the on-disk casing if it exists

                            StoreItem(walkItem = CreateItem(truepath ?? walkPath,
                                                            (truepath != null) ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown));
                        }
                        else
                        {
                            ((ISvnItemUpdate)walkItem).RefreshTo(walkItem.Exists ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown);
                        }
                    }
                }

                if (directory != null)
                {
                    foreach (ISvnItemUpdate item in directory)
                    {
                        if (item.IsItemTicked()) // These items were not found in the stat calls
                        {
                            item.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown);
                        }
                    }

                    if (updateDir.ScheduleForCleanup)
                    {
                        ScheduleForCleanup(directory); // Handles removing already deleted items
                    }
                    // We keep them cached for the current command only
                }


                SvnItem pathItem; // We promissed to return an updated item for the specified path; check if we updated it

                if (!Map.TryGetValue(path, out pathItem))
                {
                    // We did not; it does not even exist in the cache
                    StoreItem(pathItem = CreateItem(path, NoSccStatus.NotExisting));

                    if (directory != null)
                    {
                        updateDir.Store(pathItem);
                        ScheduleForCleanup(directory);
                    }
                }
                else
                {
                    ISvnItemUpdate update = pathItem;

                    if (!update.IsStatusClean())
                    {
                        update.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); // We did not see it in the walker

                        if (directory != null)
                        {
                            ((ISvnDirectoryUpdate)directory).Store(pathItem);
                            ScheduleForCleanup(directory);
                        }
                    }
                }
            }
        }
        public ActionResult Edit(SvnDirectory svnDirectory)
        {
            ViewBag.Title = "Edit";

            return(PartialView(svnDirectory));
        }
예제 #11
0
        /// <summary>
        /// Refreshes the specified path using the specified depth
        /// </summary>
        /// <param name="path">A normalized path</param>
        /// <param name="pathKind"></param>
        /// <param name="depth"></param>
        /// <remarks>
        /// If the path is a file and depth is greater that <see cref="SvnDepth.Empty"/> the parent folder is walked instead.
        ///
        /// <para>This method guarantees that after calling it at least one up-to-date item exists
        /// in the statusmap for <paramref name="path"/>. If we can not find information we create
        /// an unspecified item
        /// </para>
        /// </remarks>
        void RefreshPath(string path, SvnNodeKind pathKind)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            string walkPath         = path;
            bool   walkingDirectory = false;

            switch (pathKind)
            {
            case SvnNodeKind.Directory:
                walkingDirectory = true;
                break;

            case SvnNodeKind.File:
                walkPath         = SvnTools.GetNormalizedDirectoryName(path);
                walkingDirectory = true;
                break;

            default:
                try
                {
                    if (File.Exists(path))     // ### Not long path safe
                    {
                        pathKind = SvnNodeKind.File;
                        goto case SvnNodeKind.File;
                    }
                }
                catch (PathTooLongException)
                { /* Fall through */ }
                break;
            }

            SvnStatusArgs args = new SvnStatusArgs();

            args.Depth = SvnDepth.Children;
            args.RetrieveAllEntries     = true;
            args.RetrieveIgnoredEntries = true;
            args.ThrowOnError           = false;

            lock (_lock)
            {
                SvnDirectory        directory;
                ISvnDirectoryUpdate updateDir;
                SvnItem             walkItem;

                // We get more information for free, lets use that to update other items
                if (_dirMap.TryGetValue(walkPath, out directory))
                {
                    updateDir = directory;
                    updateDir.TickAll();
                }
                else
                {
                    // No existing directory instance, let's create one
                    updateDir         = directory = new SvnDirectory(Context, walkPath);
                    _dirMap[walkPath] = directory;
                }

                walkItem = directory.Directory;

                bool ok;
                bool statSelf  = false;
                bool noWcAtAll = false;

                // Don't retry file open/read operations on failure. These would only delay the result
                // (default number of delays = 100)
                using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0))
                {
                    ok = _client.Status(walkPath, args, RefreshCallback);
                }

                if (!ok)
                {
                    if (args.LastException != null)
                    {
                        switch (args.LastException.SvnErrorCode)
                        {
                        case SvnErrorCode.SVN_ERR_WC_UNSUPPORTED_FORMAT:
                            if (CommandService != null)
                            {
                                CommandService.PostExecCommand(AnkhCommand.NotifyWcToNew, walkPath);
                            }
                            break;

                        case SvnErrorCode.SVN_ERR_WC_UPGRADE_REQUIRED:
                            _enableUpgrade = true;

                            if (updateDir != null)
                            {
                                updateDir.SetNeedsUpgrade();
                            }

                            if (!_sendUpgrade && CommandService != null)
                            {
                                _sendUpgrade = true;
                                CommandService.PostExecCommand(AnkhCommand.NotifyUpgradeRequired, walkPath);
                            }
                            break;

                        case SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY:
                            // Status only reports this error if there is no ancestor working copy
                            // We should avoid statting all parent directories again for .IsVersionable
                            noWcAtAll = true;
                            break;

                        case SvnErrorCode.SVN_ERR_WC_CLEANUP_REQUIRED:
                            if (updateDir != null)
                            {
                                updateDir.SetNeedsCleanup();
                            }
                            break;
                        }
                    }
                    statSelf = true;
                }
                else if (directory != null)
                {
                    walkItem = directory.Directory; // Might have changed via casing
                }
                if (!statSelf)
                {
                    if (((ISvnItemUpdate)walkItem).ShouldRefresh())
                    {
                        statSelf = true;
                    }
                    else if (walkingDirectory && !walkItem.IsVersioned)
                    {
                        statSelf = true;
                    }
                }

                if (statSelf)
                {
                    // Svn did not stat the items for us.. Let's make something up

                    if (walkingDirectory)
                    {
                        StatDirectory(walkPath, directory, noWcAtAll);
                    }
                    else
                    {
                        // Just stat the item passed and nothing else in the Depth.Empty case

                        if (walkItem == null)
                        {
                            string truepath = SvnTools.GetTruePath(walkPath); // Gets the on-disk casing if it exists

                            StoreItem(walkItem = CreateItem(truepath ?? walkPath,
                                                            (truepath != null) ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown));
                        }
                        else
                        {
                            ((ISvnItemUpdate)walkItem).RefreshTo(walkItem.Exists ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown);
                        }
                    }
                }

                if (directory != null)
                {
                    foreach (ISvnItemUpdate item in directory)
                    {
                        if (item.IsItemTicked()) // These items were not found in the stat calls
                        {
                            item.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown);
                        }
                    }

                    if (updateDir.ScheduleForCleanup)
                    {
                        ScheduleForCleanup(directory); // Handles removing already deleted items
                    }
                    // We keep them cached for the current command only
                }


                SvnItem pathItem; // We promissed to return an updated item for the specified path; check if we updated it

                if (!_map.TryGetValue(path, out pathItem))
                {
                    // We did not; it does not even exist in the cache
                    StoreItem(pathItem = CreateItem(path, NoSccStatus.NotExisting));

                    if (directory != null)
                    {
                        updateDir.Store(pathItem);
                        ScheduleForCleanup(directory);
                    }
                }
                else
                {
                    ISvnItemUpdate update = pathItem;

                    if (!update.IsStatusClean())
                    {
                        update.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); // We did not see it in the walker

                        if (directory != null)
                        {
                            ((ISvnDirectoryUpdate)directory).Store(pathItem);
                            ScheduleForCleanup(directory);
                        }
                    }
                }
            }
        }
예제 #12
0
        public override void OnExecute(CommandEventArgs e)
        {
            HybridCollection <string> dirs = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);

            foreach (SvnItem i in e.Selection.GetSelectedSvnItems(true))
            {
                SvnDirectory dir = i.ParentDirectory;
                if (dir != null && dir.NeedsWorkingCopyUpgrade && !dirs.Contains(dir.FullPath))
                {
                    dirs.Add(dir.FullPath);
                }
                else if (i.IsDirectory && i.AsDirectory().NeedsWorkingCopyUpgrade&& !dirs.Contains(i.FullPath))
                {
                    dirs.Add(i.FullPath);
                }
            }

            e.GetService <IProgressRunner>().RunModal(CommandStrings.UpgradingWorkingCopy,
                                                      delegate(object sender, ProgressWorkerArgs a)
            {
                HybridCollection <string> done = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
                foreach (string dir in dirs)
                {
                    SvnInfoArgs ia  = new SvnInfoArgs();
                    ia.ThrowOnError = false;

                    if (done.Contains(dir))
                    {
                        continue;
                    }

                    if (a.Client.Info(dir, ia, null) || ia.LastException.SvnErrorCode != SvnErrorCode.SVN_ERR_WC_UPGRADE_REQUIRED)
                    {
                        continue;
                    }

                    SvnUpgradeArgs ua = new SvnUpgradeArgs();
                    ua.ThrowOnError   = false;

                    /* Capture the already upgraded directories to avoid a lot of work */
                    ua.Notify += delegate(object sender2, SvnNotifyEventArgs n)
                    {
                        if (n.Action == SvnNotifyAction.UpgradedDirectory)
                        {
                            if (!done.Contains(n.FullPath))
                            {
                                done.Add(n.FullPath);
                            }
                        }
                    };

                    string tryDir = dir;
                    while (true)
                    {
                        if (a.Client.Upgrade(tryDir, ua) ||
                            ua.LastException.SvnErrorCode != SvnErrorCode.SVN_ERR_WC_INVALID_OP_ON_CWD)
                        {
                            break;
                        }

                        string pd = SvnTools.GetNormalizedDirectoryName(tryDir);

                        if (pd == tryDir || string.IsNullOrEmpty(pd))
                        {
                            break;
                        }

                        tryDir = pd;
                    }
                }
            });

            if (dirs.Count > 0)
            {
                StatusCache.ResetUpgradeWarning();
            }
        }