Ejemplo n.º 1
0
        public SvnStreamWrapper(Stream stream, bool enableRead, bool enableWrite, AprPool pool)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (!enableRead && !enableWrite)
            {
                throw new ArgumentException("enableRead or enableWrite must be set to true");
            }

            Stream       = stream;
            _streamBaton = new AprBaton <SvnStreamWrapper>(this);
            _pool        = pool;

            if (enableRead && !Stream.CanRead)
            {
                throw new InvalidOperationException("Can't enable reading on an unreadable stream");
            }
            if (enableWrite && !Stream.CanWrite)
            {
                throw new InvalidOperationException("Can't enable writing on an unwritable stream");
            }

            Init(enableRead, enableWrite, stream.CanSeek);
        }
Ejemplo n.º 2
0
        internal AprArray(IEnumerable items, AprPool pool)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            int nItems = 0;

            foreach (TManaged t in items)
            {
                if (ReferenceEquals(t, null))
                {
                    throw new ArgumentException(SharpSvnStrings.ItemInListIsNull, nameof(items));
                }

                nItems++;
            }

            _marshaller = Activator.CreateInstance <TMarshaller>();
            _pool       = pool;
            _handle     = apr_tables.apr_array_make(pool.Handle, nItems, _marshaller.ItemSize);

            foreach (TManaged t in items)
            {
                var ptr = apr_tables.apr_array_push(_handle);

                _marshaller.Write(t, ptr, pool);
            }
        }
Ejemplo n.º 3
0
        public unsafe SvnCommitItem Read(IntPtr ptr, AprPool pool)
        {
            var ppcCommitItem = (svn_client_commit_item3_t.__Internal * *)ptr.ToPointer();

            var pcCommitItem = svn_client_commit_item3_t.__CreateInstance(new IntPtr(*ppcCommitItem));

            return(new SvnCommitItem(pcCommitItem, pool));
        }
Ejemplo n.º 4
0
        static unsafe IntPtr _svn_wc_conflict_resolver_func(
            void **resultPtr, IntPtr descriptionPtr, IntPtr baton, IntPtr resultPoolPtr, IntPtr scratchPoolPtr)
        {
            var client = AprBaton <SvnClient> .Get(baton);

            var conflictResult = svn_wc.svn_wc_create_conflict_result(
                svn_wc_conflict_choice_t.svn_wc_conflict_choose_postpone,
                null,
                apr_pool_t.__CreateInstance(resultPoolPtr));

            *resultPtr = conflictResult.__Instance.ToPointer();

            var resultPool  = new AprPool(resultPoolPtr, false);  // Connect to parent pool
            var scratchPool = new AprPool(scratchPoolPtr, false); // Connect to parent pool

            var description = svn_wc_conflict_description2_t.__CreateInstance(descriptionPtr);

            var ea = new SvnConflictEventArgs(description, scratchPool);

            try
            {
                client.HandleClientConflict(ea);

                if (ea.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Operation canceled from OnConflict").__Instance);
                }

                conflictResult.choice = (svn_wc_conflict_choice_t)ea.Choice;

                if (ea.Choice == SvnAccept.Merged)
                {
                    if (ea.MergedValue != null)
                    {
                        conflictResult.merged_value = resultPool.AllocSvnString(ea.MergedValue);
                    }
                    if (ea.MergedFile != null)
                    {
                        conflictResult.merged_file = resultPool.AllocAbsoluteDirent(ea.MergedFile);
                    }
                }

                return(IntPtr.Zero);
            }
            catch (Exception e)
            {
                return(SvnException.CreateExceptionSvnError("Conflict resolver", e).__Instance);
            }
            finally
            {
                ea.Detach(false);

                scratchPool.Dispose();
                resultPool.Dispose();
            }
        }
Ejemplo n.º 5
0
        /// <summary>Creates a childpool within the specified parent pool</summary>
        public AprPool(AprPool parentPool)
        {
            if (parentPool == null)
            {
                throw new ArgumentNullException(nameof(parentPool));
            }

            _tag         = new AprPoolTag(parentPool._tag);
            _parent      = parentPool;
            _handle      = svn_pools.svn_pool_create(parentPool.Handle);
            _destroyPool = true;
        }
Ejemplo n.º 6
0
        public void Write(SvnTarget value, IntPtr ptr, AprPool pool)
        {
            var srcObj = svn_client_copy_source_t.__CreateInstance(
                pool.AllocCleared(sizeof(svn_client_copy_source_t.__Internal)));

            var src = (svn_client_copy_source_t.__Internal * *)ptr;

            *src = (svn_client_copy_source_t.__Internal *)srcObj.__Instance;

            srcObj.path         = value.AllocAsString(pool, true);
            srcObj.revision     = value.GetSvnRevision(SvnRevision.Working, SvnRevision.Head).AllocSvnRevision(pool);
            srcObj.peg_revision = value.GetSvnRevision(SvnRevision.Working, SvnRevision.Head).AllocSvnRevision(pool);
        }
Ejemplo n.º 7
0
        public unsafe ArgsStore(SvnClientContext client, SvnClientArgs args, AprPool pool)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            if (client._currentArgs != null)
            {
                throw new InvalidOperationException(SharpSvnStrings.SvnClientOperationInProgress);
            }

            args.Prepare();
            client._currentArgs = args;
            _client             = client;

            var ctx = _client.CtxHandle;

            _wcCtx = ctx.wc_ctx;

            {
                svn_client__private_ctx_t pctx = libsvnsharp_client.svn_client__get_private_ctx(ctx);
                pctx.total_progress = 0;
            }

            _lastContext = SvnClientContext._activeContext;
            SvnClientContext._activeContext = _client;

            try
            {
                if (!client.KeepSession && pool != null)
                {
                    svn_wc_context_t.__Internal *p_wc_ctx = null;

                    var error = svn_wc.svn_wc_context_create((void **)&p_wc_ctx, null, pool.Handle, pool.Handle);
                    if (error != null)
                    {
                        throw SvnException.Create(error);
                    }

                    ctx.wc_ctx = svn_wc_context_t.__CreateInstance(new IntPtr(p_wc_ctx));
                }

                client.HandleProcessing(new SvnProcessingEventArgs(args.CommandType));
            }
            catch (Exception)
            {
                client._currentArgs             = null;
                SvnClientContext._activeContext = _lastContext;
                throw;
            }
        }
Ejemplo n.º 8
0
        internal static unsafe string Utf8_PathPtrToString(sbyte *ptr, AprPool pool)
        {
            if (ptr == null || pool == null)
            {
                return(null);
            }

            if (*ptr == 0)
            {
                return(string.Empty);
            }

            return(Utf8_PtrToString(svn_dirent_uri.svn_dirent_local_style(ptr, pool.Handle)));
        }
Ejemplo n.º 9
0
        static unsafe IntPtr svnStreamMark(IntPtr baton, void **mark, IntPtr pool_ptr)
        {
            SvnStreamWrapper sw = AprBaton <SvnStreamWrapper> .Get(baton);

            using (var pool = new AprPool(pool_ptr, false))
            {
                long *pos = (long *)pool.Alloc(sizeof(long));

                *pos = sw.Stream.Position;

                *mark = (void *)pos;
            }

            return(IntPtr.Zero);
        }
Ejemplo n.º 10
0
        static unsafe IntPtr _libsvnsharp_commit_log_func(
            sbyte **logMsg, sbyte **tmpFile, IntPtr commitItemsPtr, IntPtr baton, IntPtr pool)
        {
            var client = AprBaton <SvnClientContext> .Get(baton);

            var tmpPool = new AprPool(pool, false);

            var commit_items = apr_array_header_t.__CreateInstance(commitItemsPtr);

            var ea = new SvnCommittingEventArgs(commit_items, client.CurrentCommandArgs.CommandType, tmpPool);

            *logMsg  = null;
            *tmpFile = null;

            try
            {
                client.HandleClientCommitting(ea);

                if (ea.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Operation canceled from OnCommitting").__Instance);
                }
                else if (ea.LogMessage != null)
                {
                    *logMsg = tmpPool.AllocUnixString(ea.LogMessage);
                }
                else if (!client._noLogMessageRequired)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Commit canceled: A logmessage is required").__Instance);
                }
                else
                {
                    *logMsg = tmpPool.AllocString("");
                }

                return(IntPtr.Zero);
            }
            catch (Exception e)
            {
                return(SvnException.CreateExceptionSvnError("Commit log", e).__Instance);
            }
            finally
            {
                ea.Detach(false);

                tmpPool.Dispose();
            }
        }
Ejemplo n.º 11
0
        internal AprArray(apr_array_header_t handle, AprPool pool)
        {
            if (handle == null)
            {
                throw new ArgumentNullException(nameof(handle));
            }
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            _marshaller = Activator.CreateInstance <TMarshaller>();
            _handle     = handle;
            _pool       = pool;
            IsReadOnly  = true;
        }
Ejemplo n.º 12
0
        internal static apr_array_header_t AllocArray(ICollection <string> strings, AprPool pool)
        {
            if (strings == null)
            {
                throw new ArgumentNullException(nameof(strings));
            }
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }
            if (strings.Any(s => s == null))
            {
                throw new ArgumentException(SharpSvnStrings.ItemInListIsNull, nameof(strings));
            }

            var aprStrings = new AprArray <string, AprCStrMarshaller>(strings, pool);

            return(aprStrings.Handle);
        }
Ejemplo n.º 13
0
        static void _svn_wc_notify_func2(IntPtr baton, IntPtr notifyPtr, IntPtr pool)
        {
            var client = AprBaton <SvnClient> .Get(baton);

            var aprPool = new AprPool(pool, false);

            var notify = svn_wc_notify_t.__CreateInstance(notifyPtr);

            var ea = new SvnNotifyEventArgs(notify, client.CurrentCommandArgs.CommandType, aprPool);

            try
            {
                client.HandleClientNotify(ea);
            }
            finally
            {
                ea.Detach(false);

                aprPool.Dispose();
            }
        }
Ejemplo n.º 14
0
        static IntPtr the_commit_callback2(IntPtr commit_info_ptr, IntPtr baton, IntPtr pool)
        {
            var tmpPool  = new AprPool(pool, false);
            var receiver = AprBaton <CommitResultReceiver> .Get(baton);

            try
            {
                var commit_info = svn_commit_info_t.__CreateInstance(commit_info_ptr);

                receiver.ProvideCommitResult(commit_info, tmpPool);

                return(IntPtr.Zero);
            }
            catch (Exception e)
            {
                return(SvnException.CreateExceptionSvnError("CommitResult function", e).__Instance);
            }
            finally
            {
                tmpPool.Dispose();
            }
        }
Ejemplo n.º 15
0
        internal AprArray(ICollection <TManaged> items, AprPool pool)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            _marshaller = Activator.CreateInstance <TMarshaller>();
            _pool       = pool;
            _handle     = apr_tables.apr_array_make(pool.Handle, items.Count, _marshaller.ItemSize);

            foreach (var t in items)
            {
                var ptr = apr_tables.apr_array_push(_handle);

                _marshaller.Write(t, ptr, pool);
            }
        }
Ejemplo n.º 16
0
        public unsafe NoArgsStore(SvnClientContext client, AprPool pool)
        {
            if (client._currentArgs != null)
            {
                throw new InvalidOperationException(SharpSvnStrings.SvnClientOperationInProgress);
            }

            _client = client;

            var ctx = _client.CtxHandle;

            _wcCtx = ctx.wc_ctx;

            _lastContext = SvnClientContext._activeContext;
            SvnClientContext._activeContext = _client;

            try
            {
                if (!client.KeepSession && pool != null)
                {
                    svn_wc_context_t.__Internal *p_wc_ctx = null;

                    var error = svn_wc.svn_wc_context_create((void **)&p_wc_ctx, null, pool.Handle, pool.Handle);
                    if (error != null)
                    {
                        throw SvnException.Create(error);
                    }

                    ctx.wc_ctx = svn_wc_context_t.__CreateInstance(new IntPtr(p_wc_ctx));
                }
            }
            catch (Exception)
            {
                SvnClientContext._activeContext = _lastContext;
                throw;
            }
        }
Ejemplo n.º 17
0
        void IItemMarshaller <string> .Write(string value, IntPtr ptr, AprPool pool)
        {
            sbyte **ppStr = (sbyte **)ptr.ToPointer();

            *ppStr = pool.AllocUri(value);
        }
Ejemplo n.º 18
0
        Uri IItemMarshaller <Uri> .Read(IntPtr ptr, AprPool pool)
        {
            sbyte **ppcStr = (sbyte **)ptr.ToPointer();

            return(SvnBase.Utf8_PtrToUri(*ppcStr, SvnNodeKind.Unknown));
        }
Ejemplo n.º 19
0
        string IItemMarshaller <string> .Read(IntPtr ptr, AprPool pool)
        {
            sbyte **ppcStr = (sbyte **)ptr.ToPointer();

            return(SvnBase.Utf8_PtrToString(*ppcStr));
        }
Ejemplo n.º 20
0
 public unsafe long Read(IntPtr ptr, AprPool pool)
 {
     return(*(long *)ptr);
 }
Ejemplo n.º 21
0
        public unsafe void Write(long value, IntPtr ptr, AprPool pool)
        {
            long *pRev = (long *)ptr;

            *pRev = value;
        }
Ejemplo n.º 22
0
        public string Read(IntPtr ptr, AprPool pool)
        {
            var ppcStr = (sbyte **)ptr;

            return(SvnBase.Utf8_PtrToString(*ppcStr));
        }
Ejemplo n.º 23
0
        internal static unsafe SvnPropertyCollection CreatePropertyDictionary(apr_hash_t propHash, AprPool pool)
        {
            if (propHash == null)
            {
                throw new ArgumentNullException(nameof(propHash));
            }
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            var _properties = new SvnPropertyCollection();

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

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

                var propVal = svn_string_t.__CreateInstance(new IntPtr(propValPtr));
                _properties.Add(SvnPropertyValue.Create(pKey, propVal, null));
            }

            return(_properties);
        }
Ejemplo n.º 24
0
        internal static unsafe apr_hash_t CreateRevPropList(SvnRevisionPropertyCollection revProps, AprPool pool)
        {
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            if (revProps != null && revProps.Count != 0)
            {
                apr_hash_t items = apr_hash.apr_hash_make(pool.Handle);

                foreach (SvnPropertyValue value in revProps)
                {
                    sbyte *key = pool.AllocString(value.Key);

                    var val = pool.AllocSvnString((byte[])value.RawValue);

                    apr_hash.apr_hash_set(items, new IntPtr(key), Constants.APR_HASH_KEY_STRING, val.__Instance);
                }

                return(items);
            }

            return(null);
        }
Ejemplo n.º 25
0
        internal static apr_array_header_t CreateChangeListsList(ICollection <string> changelists, AprPool pool)
        {
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            if (changelists != null && changelists.Count > 0)
            {
                return(AllocArray(changelists, pool));
            }

            return(null);
        }
Ejemplo n.º 26
0
        internal static apr_array_header_t AllocCopyArray <TSvnTarget>(ICollection <TSvnTarget> targets, AprPool pool)
            where TSvnTarget : SvnTarget
        {
            if (targets == null)
            {
                throw new ArgumentNullException(nameof(targets));
            }

            foreach (SvnTarget s in targets)
            {
                if (s == null)
                {
                    throw new ArgumentException(SharpSvnStrings.ItemInListIsNull, nameof(targets));
                }
            }

            var aprTargets = new AprArray <SvnTarget, SvnCopyTargetMarshaller>(targets, pool);

            return(aprTargets.Handle);
        }
Ejemplo n.º 27
0
        public void Write(string value, IntPtr ptr, AprPool pool)
        {
            var ppStr = (sbyte **)ptr;

            *ppStr = pool.AllocString(value);
        }
Ejemplo n.º 28
0
        public void Write(string value, IntPtr ptr, AprPool pool)
        {
            sbyte **ppStr = (sbyte **)ptr;

            *ppStr = pool.AllocDirent(value);
        }
Ejemplo n.º 29
0
        public string Read(IntPtr ptr, AprPool pool)
        {
            sbyte **ppcStr = (sbyte **)ptr;

            return(SvnBase.Utf8_PtrToString(svn_dirent_uri.svn_dirent_local_style(*ppcStr, pool.Handle)));
        }
Ejemplo n.º 30
0
        internal void ProvideCommitResult(svn_commit_info_t commit_info, AprPool pool)
        {
            CommitResult = SvnCommittedEventArgs.Create(_client, commit_info, pool);

            _client.HandleClientCommitted(CommitResult);
        }