Пример #1
0
        private static bool TryFindBranch(Uri uri, string path, string name, bool branch, out RepositoryLayoutInfo info)
        {
            info = null;
            string r = path;

            name = '/' + name.Trim('/') + '/';

            while (r.Length > 0 && !r.EndsWith(name, StringComparison.OrdinalIgnoreCase))
            {
                int n = r.LastIndexOf('/', r.Length - 1);

                if (n >= 0)
                {
                    int lastCharIndex = r.Length - 1;
                    // if '/' is the last character, strip and continue
                    // otherwise include '/' to give "/tags/" check a chance
                    r = r.Substring(0, (n == lastCharIndex) ? n : (n + 1));
                }
                else
                {
                    r = "";
                }
            }

            if (!string.IsNullOrEmpty(r))
            {
                info = new RepositoryLayoutInfo();

                string dir = (path.Length > r.Length) ? path.Substring(0, path.IndexOf('/', r.Length) + 1) : path;

                info.WorkingRoot      = new Uri(uri, dir);
                info.WholeProjectRoot = new Uri(new Uri(uri, r), "../");
                info.BranchesRoot     = new Uri(info.WholeProjectRoot, "branches/"); // Always set some branches suggestion?
                info.SelectedBranch   = info.BranchesRoot.MakeRelativeUri(info.WorkingRoot);

                Uri itemRoot = new Uri(info.WholeProjectRoot, r.Substring(r.Length - name.Length + 1, name.Length - 1)); // 'tags/' but with repos casing

                if (branch)
                {
                    info.BranchesRoot = itemRoot;
                }
                else
                {
                    info.TagsRoot = itemRoot;
                }
                return(true);
            }

            return(false);
        }
Пример #2
0
        public static bool TryGuessLayout(IAnkhServiceProvider context, Uri uri, out RepositoryLayoutInfo info)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            else if (uri == null)
                throw new ArgumentNullException("uri");

            info = null;

            uri = SvnTools.GetNormalizedUri(uri);

            GC.KeepAlive(context); // Allow future external hints

            string path;
            if (uri.IsUnc)
            {
                string p = uri.GetComponents(UriComponents.Host | UriComponents.Path, UriFormat.SafeUnescaped);
                if(string.IsNullOrEmpty(p))
                    return false;

                path = "//" + p;
            }
            else
                path = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);

            if (string.IsNullOrEmpty(path))
                return false;

            if (path[0] != '/' && !uri.IsFile) // Don't do this for files, because it will cause duplicate drive roots
                path = '/' + path;
            if (path[path.Length - 1] != '/')
                path += '/';

            if (string.IsNullOrEmpty(path) || path.Length == 1)
                return false;

            string r = path;

            while (r.Length > 0 && !r.EndsWith("/trunk/", StringComparison.OrdinalIgnoreCase))
            {
                int n = r.LastIndexOf('/', r.Length - 1);

                if (n >= 0)
                {
                    int lastCharIndex = r.Length - 1;
                    // if '/' is the last character, strip and continue
                    // otherwise include '/' to give "/trunk/" check a chance
                    r = r.Substring(0, (n == lastCharIndex) ? n : (n+1));
                }
                else
                    r = "";
            }

            if (!string.IsNullOrEmpty(r))
            {
                info = new RepositoryLayoutInfo();
                info.WorkingRoot = new Uri(uri, r);
                info.WholeProjectRoot = new Uri(uri, r.Substring(0, r.Length - 6));
                info.BranchesRoot = new Uri(info.WholeProjectRoot, "branches/");
                info.SelectedBranch = info.WholeProjectRoot.MakeRelativeUri(info.WorkingRoot);
                return true;
            }

            if (TryFindBranch(uri, path, "branches", true, out info))
                return true;
            else if (TryFindBranch(uri, path, "tags", false, out info))
                return true;
            else if (TryFindBranch(uri, path, "releases", false, out info))
                return true;

            info = new RepositoryLayoutInfo();
            info.WorkingRoot = new Uri(uri, ".");
            info.WholeProjectRoot = new Uri(info.WorkingRoot, "../");
            info.BranchesRoot = new Uri(info.WholeProjectRoot, "branches/");
            info.TagsRoot = new Uri(info.WholeProjectRoot, "tags/");
            info.SelectedBranch = info.WholeProjectRoot.MakeRelativeUri(info.WorkingRoot);
            return true;
        }
Пример #3
0
        private static bool TryFindBranch(Uri uri, string path, string name, bool branch, out RepositoryLayoutInfo info)
        {
            info = null;
            string r = path;

            name = '/' + name.Trim('/') + '/';

            while (r.Length > 0 && !r.EndsWith(name, StringComparison.OrdinalIgnoreCase))
            {
                int n = r.LastIndexOf('/', r.Length - 1);

                if (n >= 0)
                {
                    int lastCharIndex = r.Length - 1;
                    // if '/' is the last character, strip and continue
                    // otherwise include '/' to give "/tags/" check a chance
                    r = r.Substring(0, (n == lastCharIndex) ? n : (n + 1));
                }
                else
                    r = "";
            }

            if (!string.IsNullOrEmpty(r))
            {
                info = new RepositoryLayoutInfo();

                string dir = (path.Length > r.Length) ? path.Substring(0, path.IndexOf('/', r.Length) + 1) : path;

                info.WorkingRoot = new Uri(uri, dir);
                info.WholeProjectRoot = new Uri(new Uri(uri, r), "../");
                info.BranchesRoot = new Uri(info.WholeProjectRoot, "branches/"); // Always set some branches suggestion?
                info.SelectedBranch = info.BranchesRoot.MakeRelativeUri(info.WorkingRoot);

                Uri itemRoot = new Uri(info.WholeProjectRoot, r.Substring(r.Length - name.Length + 1, name.Length-1)); // 'tags/' but with repos casing

                if (branch)
                    info.BranchesRoot = itemRoot;
                else
                    info.TagsRoot = itemRoot;
                return true;
            }

            return false;
        }
Пример #4
0
        public static bool TryGuessLayout(IAnkhServiceProvider context, Uri uri, out RepositoryLayoutInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            else if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            info = null;

            uri = SvnTools.GetNormalizedUri(uri);

            GC.KeepAlive(context); // Allow future external hints

            string path;

            if (uri.IsUnc)
            {
                string p = uri.GetComponents(UriComponents.Host | UriComponents.Path, UriFormat.SafeUnescaped);
                if (string.IsNullOrEmpty(p))
                {
                    return(false);
                }

                path = "//" + p;
            }
            else
            {
                path = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);
            }

            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            if (path[0] != '/' && !uri.IsFile) // Don't do this for files, because it will cause duplicate drive roots
            {
                path = '/' + path;
            }
            if (path[path.Length - 1] != '/')
            {
                path += '/';
            }

            if (string.IsNullOrEmpty(path) || path.Length == 1)
            {
                return(false);
            }

            string r = path;

            while (r.Length > 0 && !r.EndsWith("/trunk/", StringComparison.OrdinalIgnoreCase))
            {
                int n = r.LastIndexOf('/', r.Length - 1);

                if (n >= 0)
                {
                    int lastCharIndex = r.Length - 1;
                    // if '/' is the last character, strip and continue
                    // otherwise include '/' to give "/trunk/" check a chance
                    r = r.Substring(0, (n == lastCharIndex) ? n : (n + 1));
                }
                else
                {
                    r = "";
                }
            }

            if (!string.IsNullOrEmpty(r))
            {
                info                  = new RepositoryLayoutInfo();
                info.WorkingRoot      = new Uri(uri, r);
                info.WholeProjectRoot = new Uri(uri, r.Substring(0, r.Length - 6));
                info.BranchesRoot     = new Uri(info.WholeProjectRoot, "branches/");
                info.SelectedBranch   = info.WholeProjectRoot.MakeRelativeUri(info.WorkingRoot);
                return(true);
            }

            if (TryFindBranch(uri, path, "branches", true, out info))
            {
                return(true);
            }
            else if (TryFindBranch(uri, path, "tags", false, out info))
            {
                return(true);
            }
            else if (TryFindBranch(uri, path, "releases", false, out info))
            {
                return(true);
            }

            info                  = new RepositoryLayoutInfo();
            info.WorkingRoot      = new Uri(uri, ".");
            info.WholeProjectRoot = new Uri(info.WorkingRoot, "../");
            info.BranchesRoot     = new Uri(info.WholeProjectRoot, "branches/");
            info.TagsRoot         = new Uri(info.WholeProjectRoot, "tags/");
            info.SelectedBranch   = info.WholeProjectRoot.MakeRelativeUri(info.WorkingRoot);
            return(true);
        }