Esempio n. 1
0
        /// <summary>Writes the content of specified files or URLs to a stream. (<c>svn cat</c>)</summary>
        public unsafe bool Write(SvnTarget target, Stream output, SvnWriteArgs args, out SvnPropertyCollection properties)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (args == null)
            {
                throw new ObjectDisposedException(nameof(args));
            }

            using var pool = new AprPool(_pool);
            apr_hash_t.__Internal *props_ptr = null;

            properties = null;

            if (InternalWrite(target, output, args, &props_ptr, pool))
            {
                var props = apr_hash_t.__CreateInstance(new IntPtr(props_ptr));
                properties = CreatePropertyDictionary(props, pool);
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>Gets the specified property from the specfied path</summary>
        /// <returns>true if property is set, otherwise false</returns>
        /// <exception type="SvnException">path is not a valid workingcopy path</exception>
        public bool GetProperty(SvnTarget target, string propertyName, out SvnPropertyValue value)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            value = null;

            if (GetProperty(target, propertyName, new SvnGetPropertyArgs(), out var result))
            {
                if (result.Count != 0)
                {
                    value = result[0];
                }

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>Tries to get a property from the specified path (<c>svn propget</c>)</summary>
        /// <remarks>Eats all (non-argument) exceptions</remarks>
        /// <returns>True if the property is fetched, otherwise false</returns>
        /// <remarks>Equivalent to GetProperty with <see cref="SvnGetPropertyArgs" />'s ThrowOnError set to false</remarks>
        public bool TryGetProperty(SvnTarget target, string propertyName, out string value)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            value = null;

            var args = new SvnGetPropertyArgs();

            args.ThrowOnError = false;

            if (GetProperty(target, propertyName, args, out var result))
            {
                if (result.Count > 0)
                {
                    value = result[0].StringValue;

                    return(value != null);
                }

                // Fall through if no property fetched
            }
            return(false);
        }
Esempio n. 4
0
        /// <summary>Streamingly lists directory entries in the repository. (<c>svn list</c>)</summary>
        public unsafe bool List(SvnTarget target, SvnListArgs args, EventHandler <SvnListEventArgs> listHandler)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

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

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

            args.Prepare(target, args.Revision.RevisionType != SvnRevisionType.None);

            if (listHandler != null)
            {
                args.List += listHandler;
            }

            try
            {
                svn_opt_revision_t pegrev = target.Revision.AllocSvnRevision(pool);
                svn_opt_revision_t rev    = args.Revision.Or(target.Revision).AllocSvnRevision(pool);

                using var svnclient_list_func_handle = new SafeFuncHandle <svn_client_list_func2_t>(svnclient_list_handler);

                svn_error_t r = svn_client.svn_client_list3(
                    target.AllocAsString(pool),
                    pegrev,
                    rev,
                    (svn_depth_t)args.Depth,
                    (uint)args.RetrieveEntries,
                    args.RetrieveLocks,
                    args.IncludeExternals,
                    svnclient_list_func_handle.Get(),
                    _clientBaton.Handle,
                    CtxHandle,
                    pool.Handle);

                return(args.HandleResult(this, r, target));
            }
            finally
            {
                if (listHandler != null)
                {
                    args.List -= listHandler;
                }
            }
        }
Esempio n. 5
0
        /// <summary>Streamingly retrieves information about a local or remote item (<c>svn info</c>)</summary>
        public unsafe bool Info(SvnTarget target, SvnInfoArgs args, EventHandler <SvnInfoEventArgs> infoHandler)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

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

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

            if (infoHandler != null)
            {
                args.Info += infoHandler;
            }

            try
            {
                var pegRev = target.GetSvnRevision(SvnRevision.None, SvnRevision.Head).AllocSvnRevision(pool);
                var rev    = args.Revision.Or(target.GetSvnRevision(SvnRevision.None, SvnRevision.Head)).AllocSvnRevision(pool);

                using var svn_info_receiver_handle = new SafeFuncHandle <svn_client_info_receiver2_t>(svn_info_receiver);

                svn_error_t r = svn_client.svn_client_info4(
                    target.AllocAsString(pool, true),
                    pegRev,
                    rev,
                    (svn_depth_t)args.Depth,
                    args.RetrieveExcluded,
                    args.RetrieveActualOnly,
                    args.IncludeExternals,
                    CreateChangeListsList(args.ChangeLists, pool), // Intersect ChangeLists
                    svn_info_receiver_handle.Get(),
                    _clientBaton.Handle,
                    CtxHandle,
                    pool.Handle);

                return(args.HandleResult(this, r, target));
            }
            finally
            {
                if (infoHandler != null)
                {
                    args.Info -= infoHandler;
                }
            }
        }
Esempio n. 6
0
        /// <summary>Streamingly retrieves information about a local or remote item (<c>svn info</c>)</summary>
        public bool Info(SvnTarget target, EventHandler <SvnInfoEventArgs> infoHandler)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (infoHandler == null)
            {
                throw new ArgumentNullException(nameof(infoHandler));
            }

            return(Info(target, new SvnInfoArgs(), infoHandler));
        }
Esempio n. 7
0
        /// <summary>Duplicate something in repository, remembering history (<c>svn copy</c>)</summary>
        public bool RemoteCopy(SvnTarget source, Uri toUri, out SvnCommitResult result)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (toUri == null)
            {
                throw new ArgumentNullException(nameof(toUri));
            }

            return(RemoteCopy(NewSingleItemCollection(source), toUri, new SvnCopyArgs(), out result));
        }
Esempio n. 8
0
        /// <summary>Writes the content of specified files or URLs to a stream. (<c>svn cat</c>)</summary>
        public bool Write(SvnTarget target, Stream output, out SvnPropertyCollection properties)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            return(Write(target, output, new SvnWriteArgs(), out properties));
        }
Esempio n. 9
0
        // List Client Command

        /// <summary>Streamingly lists directory entries in the repository. (<c>svn list</c>)</summary>
        public bool List(SvnTarget target, EventHandler <SvnListEventArgs> listHandler)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (listHandler == null)
            {
                throw new ArgumentNullException(nameof(listHandler));
            }

            return(List(target, new SvnListArgs(), listHandler));
        }
Esempio n. 10
0
        /// <overloads>Writes the content of specified files or URLs to a stream. (<c>svn cat</c>)</overloads>
        /// <summary>Writes the content of specified files or URLs to a stream. (<c>svn cat</c>)</summary>
        public bool Write(SvnTarget target, Stream output)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            return(Write(target, output, new SvnWriteArgs()));
        }
Esempio n. 11
0
        /*internal SvnPropertyValue(String key, String value, SvnTarget target)
         * {
         *  if (String.IsNullOrEmpty(key))
         *      throw new ArgumentNullException("key");
         *  else if (!value)
         *      throw new ArgumentNullException("value");
         *
         *  _target = target;
         *  _key = key;
         *  _strValue = value;
         * }*/

        internal SvnPropertyValue(string key, byte[] value, SvnTarget target)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            Target = target;
            Key    = key;
            _value = value;
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        /// <summary>Duplicate something in repository, remembering history (<c>svn copy</c>)</summary>
        public bool RemoteCopy(SvnTarget source, Uri toUri, SvnCopyArgs args)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (toUri == null)
            {
                throw new ArgumentNullException(nameof(toUri));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            return(RemoteCopy(NewSingleItemCollection(source), toUri, args, out _));
        }
Esempio n. 14
0
        /// <summary>Duplicate something in repository, remembering history (<c>svn copy</c>)</summary>
        public bool RemoteCopy(SvnTarget source, Uri toUri)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (toUri == null)
            {
                throw new ArgumentNullException(nameof(toUri));
            }
            if (!SvnBase.IsValidReposUri(toUri))
            {
                throw new ArgumentException(SharpSvnStrings.ArgumentMustBeAValidRepositoryUri, nameof(toUri));
            }

            return(RemoteCopy(NewSingleItemCollection(source), toUri, new SvnCopyArgs(), out _));
        }
Esempio n. 15
0
        /// <summary>Recursively 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 bool Export(SvnTarget from, string toPath, out SvnUpdateResult result)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }
            if (toPath == null)
            {
                throw new ArgumentNullException(nameof(toPath));
            }
            if (!IsNotUri(toPath))
            {
                throw new ArgumentException(SharpSvnStrings.ArgumentMustBeAPathNotAUri, nameof(toPath));
            }

            return(Export(from, toPath, new SvnExportArgs(), out result));
        }
Esempio n. 16
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 bool Export(SvnTarget from, string toPath, SvnExportArgs args)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }
            if (toPath == null)
            {
                throw new ArgumentNullException(nameof(toPath));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            return(Export(from, toPath, args, out _));
        }
Esempio n. 17
0
        /// <summary>Gets a list of directory entries in the repository. (<c>svn list</c>)</summary>
        public bool GetList(SvnTarget target, out Collection <SvnListEventArgs> list)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var results = new InfoItemCollection <SvnListEventArgs>();

            try
            {
                return(List(target, new SvnListArgs(), results.Handler));
            }
            finally
            {
                list = results;
            }
        }
Esempio n. 18
0
        /// <summary>Gets information about the specified target</summary>
        public bool GetInfo(SvnTarget target, out SvnInfoEventArgs info)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var results = new InfoItemCollection <SvnInfoEventArgs>();

            try
            {
                return(Info(target, new SvnInfoArgs(), results.Handler));
            }
            finally
            {
                info = results.Count > 0 ? results[0] : null;
            }
        }
Esempio n. 19
0
        /// <summary>Writes the content of specified files or URLs to a stream. (<c>svn cat</c>)</summary>
        public unsafe bool Write(SvnTarget target, Stream output, SvnWriteArgs args)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (args == null)
            {
                throw new ObjectDisposedException(nameof(args));
            }

            using var pool = new AprPool(_pool);

            return(InternalWrite(target, output, args, null, pool));
        }
Esempio n. 20
0
        /// <summary>Gets information about the specified target</summary>
        public bool GetInfo(SvnTarget target, SvnInfoArgs args, out Collection <SvnInfoEventArgs> info)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var results = new InfoItemCollection <SvnInfoEventArgs>();

            try
            {
                return(Info(target, args, results.Handler));
            }
            finally
            {
                info = results;
            }
        }
Esempio n. 21
0
        /// <overloads>Retrieves the value of a property on files, dirs, or revisions (<c>svn propget</c>)</overloads>
        /// <summary>Gets the specified property from the specfied path</summary>
        /// <returns>true if property is set, otherwise false</returns>
        /// <exception type="SvnException">path is not a valid workingcopy path</exception>
        public bool GetProperty(SvnTarget target, string propertyName, out string value)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            value = null;

            bool ok = GetProperty(target, propertyName, new SvnGetPropertyArgs(), out var result);

            if (ok && result != null && (result.Count > 0))
            {
                value = result[0].StringValue;
            }

            return(ok);
        }
Esempio n. 22
0
        unsafe bool InternalWrite(SvnTarget target, Stream output, SvnWriteArgs args, apr_hash_t.__Internal **props, AprPool resultPool)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (args == null)
            {
                throw new ObjectDisposedException(nameof(args));
            }

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

            using var wrapper = new SvnStreamWrapper(output, false, true, scratchPool);

            svn_opt_revision_t pegRev = target.Revision.AllocSvnRevision(scratchPool);
            svn_opt_revision_t rev    = args.Revision.Or(target.Revision).AllocSvnRevision(scratchPool);

            svn_error_t r = svn_client.svn_client_cat3(
                (void **)props,
                wrapper.Handle,
                target.AllocAsString(scratchPool, true),
                pegRev,
                rev,
                !args.IgnoreKeywords,
                CtxHandle,
                resultPool.Handle,
                scratchPool.Handle);

            return(args.HandleResult(this, r, target));
        }
Esempio n. 23
0
        internal static unsafe SvnPropertyValue Create(sbyte *propertyName, svn_string_t value, SvnTarget target, string name)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            object val = SvnBase.PtrToStringOrByteArray(value.data, (int)value.len);

            if (val is string strVal)
            {
                if (svn_props.svn_prop_needs_translation(propertyName))
                {
                    strVal = strVal.Replace("\n", Environment.NewLine);
                }

                return(new SvnPropertyValue(name, SvnBase.PtrToByteArray(value.data, (int)value.len), strVal, target));
            }

            return(new SvnPropertyValue(name, (byte[])val, target));
        }
Esempio n. 24
0
        /// <summary>Sets the specified property on the specfied path to value</summary>
        /// <remarks>Use <see cref="DeleteProperty(string, string, SvnSetPropertyArgs)" /> to remove an existing property</remarks>
        public unsafe bool GetProperty(SvnTarget target, string propertyName, SvnGetPropertyArgs args, out SvnTargetPropertyCollection properties)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

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

            var pegRev    = target.Revision.AllocSvnRevision(pool);
            var rev       = args.Revision.Or(target.Revision).AllocSvnRevision(pool);
            int actualRev = 0;

            apr_hash_t.__Internal *pHash = null;

            sbyte *pName = pool.AllocString(propertyName);

            sbyte *prefix     = null;
            sbyte *targetName = target.AllocAsString(pool);

            if (!svn_path.svn_path_is_url(targetName))
            {
                prefix = targetName;

                targetName = target.AllocAsString(pool, true);
            }

            svn_error_t r = svn_client.svn_client_propget5(
                (void **)&pHash,
                null,
                pName,
                targetName,
                pegRev,
                rev,
                ref actualRev,
                (svn_depth_t)args.Depth,
                CreateChangeListsList(args.ChangeLists, pool), // Intersect ChangeLists
                CtxHandle,
                pool.Handle,
                pool.Handle);

            if (pHash != null)
            {
                var rd = new SvnTargetPropertyCollection();

                apr_hash_t hash = apr_hash_t.__CreateInstance(new IntPtr(pHash));

                for (apr_hash_index_t hi = apr_hash.apr_hash_first(pool.Handle, hash); hi != null; hi = apr_hash.apr_hash_next(hi))
                {
                    sbyte *pKey;
                    long   keyLen = 0;
                    svn_string_t.__Internal *propVal;

                    apr_hash.apr_hash_this(hi, (void **)&pKey, ref keyLen, (void **)&propVal);

                    SvnTarget itemTarget;
                    if (prefix != null && !svn_path.svn_path_is_url(pKey))
                    {
                        string path = Utf8_PathPtrToString(
                            svn_dirent_uri.svn_dirent_join(
                                prefix,
                                svn_dirent_uri.svn_dirent_skip_ancestor(targetName, pKey),
                                pool.Handle),
                            pool);

                        if (!string.IsNullOrEmpty(path))
                        {
                            itemTarget = path;
                        }
                        else
                        {
                            itemTarget = ".";
                        }
                    }
                    else
                    {
                        itemTarget = Utf8_PtrToUri(pKey, SvnNodeKind.Unknown);
                    }

                    var propValStr = svn_string_t.__CreateInstance(new IntPtr(propVal));
                    rd.Add(SvnPropertyValue.Create(pName, propValStr, itemTarget, propertyName));
                }

                properties = rd;
            }

            return(args.HandleResult(this, r, target));
        }
Esempio n. 25
0
        internal static unsafe SvnPropertyValue Create(sbyte *propertyName, svn_string_t value, SvnTarget target)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            string name = SvnBase.Utf8_PtrToString(propertyName);

            return(Create(propertyName, value, target, name));
        }