Пример #1
0
        /// <summary>Adds the specified path</summary>
        /// <returns>true if the operation succeeded; false if it did not</returns>
        /// <exception type="SvnException">Operation failed and args.ThrowOnError = true</exception>
        /// <exception type="ArgumentException">Parameters invalid</exception>
        public unsafe bool Add(string path, SvnAddArgs args)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            EnsureState(SvnContextState.ConfigLoaded, SvnExtendedState.MimeTypesLoaded);
            using var pool  = new AprPool(_pool);
            using var store = new ArgsStore(this, args, pool);

            svn_error_t r = svn_client.svn_client_add5(
                pool.AllocDirent(path),
                (svn_depth_t)args.Depth,
                args.Force,
                args.NoIgnore,
                args.NoAutoProps,
                args.AddParents,
                CtxHandle,
                pool.Handle);

            return(args.HandleResult(this, r, path));
        }
Пример #2
0
        /// <summary>Retrieves an authorization baton allocated in the specified pool; containing the current authorization settings</summary>
        internal unsafe svn_auth_baton_t GetAuthorizationBaton(ref int cookie)
        {
            if (_currentBaton != null && _cookie == cookie)
            {
                return(_currentBaton);
            }

            using var tmpPool = new AprPool(_parentPool);

            apr_hash_t creds = null;

            if (_currentBaton != null)
            {
                creds = clone_credentials(get_cache(_currentBaton), null, tmpPool);
            }

            _authPool.Clear();

            var authArray = new AprArray <ISvnAuthWrapper, SvnAuthProviderMarshaller>(_handlers, _authPool);

            svn_auth_baton_t.__Internal *rsltPtr = null;

            svn_auth.svn_auth_open((void **)&rsltPtr, authArray.Handle, _authPool.Handle);

            var rslt = svn_auth_baton_t.__CreateInstance(new IntPtr(rsltPtr));

            if (creds != null)
            {
                clone_credentials(creds, get_cache(rslt), _authPool);
            }

            if (_clientContext._configPath != null)
            {
                svn_auth.svn_auth_set_parameter(
                    rslt,
                    tmpPool.AllocString(Constants.SVN_AUTH_PARAM_CONFIG_DIR),
                    new IntPtr(_authPool.AllocDirent(_clientContext._configPath)));
            }

            if (_forcedUser != null)
            {
                svn_auth.svn_auth_set_parameter(
                    rslt,
                    tmpPool.AllocString(Constants.SVN_AUTH_PARAM_DEFAULT_USERNAME),
                    new IntPtr(_authPool.AllocString(_forcedUser)));
            }

            if (_forcedPassword != null)
            {
                svn_auth.svn_auth_set_parameter(
                    rslt,
                    tmpPool.AllocString(Constants.SVN_AUTH_PARAM_DEFAULT_PASSWORD),
                    new IntPtr(_authPool.AllocString(_forcedPassword)));
            }

            _currentBaton = rslt;

            cookie = _cookie;
            return(rslt);
        }
Пример #3
0
        /// <summary>Performs a checkout of <paramref name="url" /> to <paramref name="path" /> to the specified param</summary>
        /// <exception type="SvnException">Operation failed and args.ThrowOnError = true</exception>
        /// <exception type="ArgumentException">Parameters invalid</exception>
        /// <returns>true if the operation succeeded; false if it did not</returns>
        public unsafe bool CheckOut(SvnUriTarget url, string path, SvnCheckOutArgs args, out SvnUpdateResult result)
        {
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            if (args.Revision.RequiresWorkingCopy)
            {
                throw new ArgumentException(SharpSvnStrings.RevisionTypeMustBeHeadDateOrSpecific, nameof(args));
            }
            if (url.Revision.RequiresWorkingCopy)
            {
                throw new ArgumentException(SharpSvnStrings.RevisionTypeMustBeHeadDateOrSpecific, nameof(url));
            }

            EnsureState(SvnContextState.AuthorizationInitialized);
            using var pool  = new AprPool(_pool);
            using var store = new ArgsStore(this, args, pool);

            int version = 0;

            svn_opt_revision_t pegRev = url.Revision.AllocSvnRevision(pool);
            svn_opt_revision_t coRev  = args.Revision.Or(url.Revision).Or(SvnRevision.Head).AllocSvnRevision(pool);

            svn_error_t r = svn_client.svn_client_checkout3(
                ref version,
                pool.AllocUri(url.Uri),
                pool.AllocDirent(path),
                pegRev,
                coRev,
                (svn_depth_t)args.Depth,
                args.IgnoreExternals,
                args.AllowObstructions,
                CtxHandle,
                pool.Handle);

            result = SvnUpdateResult.Create(this, args, version);

            return(args.HandleResult(this, r, url));
        }
Пример #4
0
        /// <summary>Exports the specified target to the specified path</summary>
        /// <remarks>Subversion optimizes this call if you specify a workingcopy file instead of an url</remarks>
        public unsafe bool Export(SvnTarget from, string toPath, SvnExportArgs args, out SvnUpdateResult result)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }
            if (toPath == null)
            {
                throw new ArgumentNullException(nameof(toPath));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            EnsureState(SvnContextState.AuthorizationInitialized);

            using var pool  = new AprPool(_pool);
            using var store = new ArgsStore(this, args, pool);

            result = null;

            int resultRev             = 0;
            svn_opt_revision_t pegRev = from.Revision.AllocSvnRevision(pool);
            svn_opt_revision_t rev    = args.Revision.Or(from.GetSvnRevision(SvnRevision.Working, SvnRevision.Head)).AllocSvnRevision(pool);

            svn_error_t r = svn_client.svn_client_export5(
                ref resultRev,
                from.AllocAsString(pool),
                pool.AllocDirent(toPath),
                pegRev,
                rev,
                args.Overwrite,
                args.IgnoreExternals,
                args.IgnoreKeywords,
                (svn_depth_t)args.Depth,
                pool.AllocString(GetEolPtr(args.LineStyle)),
                CtxHandle,
                pool.Handle);

            if (args.HandleResult(this, r, from))
            {
                result = SvnUpdateResult.Create(this, args, resultRev);
                return(true);
            }

            return(false);
        }
Пример #5
0
        /// <summary>Move and/or rename something in working copy, remembering history (<c>svn move</c>)</summary>
        public unsafe bool Move(ICollection <string> sourcePaths, string toPath, SvnMoveArgs args)
        {
            if (sourcePaths == null)
            {
                throw new ArgumentNullException(nameof(sourcePaths));
            }
            if (string.IsNullOrEmpty(toPath))
            {
                throw new ArgumentNullException(nameof(toPath));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            foreach (string s in sourcePaths)
            {
                if (string.IsNullOrEmpty(s))
                {
                    throw new ArgumentException(SharpSvnStrings.ItemInListIsNull, nameof(sourcePaths));
                }
                if (!IsNotUri(s))
                {
                    throw new ArgumentException(SharpSvnStrings.ArgumentMustBeAPathNotAUri, nameof(sourcePaths));
                }
            }

            EnsureState(SvnContextState.AuthorizationInitialized);
            using var pool  = new AprPool(_pool);
            using var store = new ArgsStore(this, args, pool);

            svn_error_t r = svn_client.svn_client_move7(
                AllocDirentArray(sourcePaths, pool),
                pool.AllocDirent(toPath),
                args.AlwaysMoveAsChild || (sourcePaths.Count > 1),
                args.CreateParents,
                args.AllowMixedRevisions,
                args.MetaDataOnly,
                null,
                null,
                IntPtr.Zero,
                CtxHandle,
                pool.Handle);

            return(args.HandleResult(this, r, sourcePaths));
        }
Пример #6
0
        internal static unsafe bool TryParse(string targetName, bool allowOperationalRevisions, out SvnPathTarget target, AprPool pool)
        {
            if (string.IsNullOrEmpty(targetName))
            {
                throw new ArgumentNullException(nameof(targetName));
            }
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            target = null;

            if (!IsNotUri(targetName))
            {
                return(false);
            }

            if (allowOperationalRevisions)
            {
                svn_error_t r;
                sbyte *     truePath;

                var path = pool.AllocDirent(targetName);

                if ((r = svn_opt.svn_opt_parse_path(out svn_opt_revision_t rev, &truePath, path, pool.Handle)) == null)
                {
                    var realPath = Utf8_PtrToString(truePath);

                    if (!realPath.Contains("://"))
                    {
                        var pegRev = SvnRevision.Load(rev);

                        target = new SvnPathTarget(realPath, pegRev);
                        return(true);
                    }
                }
                else
                {
                    svn_error.svn_error_clear(r);
                }
            }
Пример #7
0
 internal override unsafe sbyte *AllocAsString(AprPool pool, bool absolute)
 {
     return(absolute
         ? pool.AllocAbsoluteDirent(TargetPath)
         : pool.AllocDirent(TargetPath));
 }
Пример #8
0
        /// <summary>Gets status data for the specified path</summary>
        public unsafe bool Status(string path, SvnStatusArgs args, EventHandler <SvnStatusEventArgs> statusHandler)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            if (!IsNotUri(path))
            {
                throw new ArgumentException(SharpSvnStrings.ArgumentMustBeAPathNotAUri, nameof(path));
            }

            // We allow a null statusHandler; the args object might just handle it itself

            if (args.ContactRepository)
            {
                EnsureState(SvnContextState.AuthorizationInitialized);
            }
            else
            {
                EnsureState(SvnContextState.ConfigLoaded);
            }

            using var pool  = new AprPool(_pool);
            using var store = new ArgsStore(this, args, pool);

            if (statusHandler != null)
            {
                args.Status += statusHandler;
            }

            try
            {
                int version = 0;

                svn_opt_revision_t pegRev = args.Revision.AllocSvnRevision(pool);

                using var svnclient_status_func_handle = new SafeFuncHandle <svn_client_status_func_t>(svnclient_status_handler);

                svn_error_t r = svn_client.svn_client_status6(
                    ref version,
                    CtxHandle,
                    pool.AllocDirent(path),
                    pegRev,
                    (svn_depth_t)args.Depth,
                    args.RetrieveAllEntries,
                    args.RetrieveRemoteStatus,
                    !args.IgnoreWorkingCopyStatus,
                    args.RetrieveIgnoredEntries,
                    args.IgnoreExternals,
                    args.KeepDepth,
                    CreateChangeListsList(args.ChangeLists, pool), // Intersect ChangeLists
                    svnclient_status_func_handle.Get(),
                    _clientBaton.Handle,
                    pool.Handle);

                return(args.HandleResult(this, r, path));
            }
            finally
            {
                if (statusHandler != null)
                {
                    args.Status -= statusHandler;
                }
            }
        }