static unsafe string GetErrorText(svn_error_t error) { if (error == null) { return(""); } try { if (error.message != null) { return(SvnBase.Utf8_PtrToString(error.message)); } var buffer = new sbyte[1024]; string msg; fixed(sbyte *buf = &buffer[0]) { svn_error.svn_err_best_message(error, buf, Convert.ToUInt64(buffer.Length) - 1); msg = SvnBase.Utf8_PtrToString(buf); } return(msg?.Trim()); } catch (Exception) { return("Subversion error: Unable to retrieve error text"); } }
internal unsafe SvnListEventArgs( sbyte *path, svn_dirent_t dirent, svn_lock_t @lock, sbyte *absPath, Uri repositoryRoot, sbyte *externalParentUrl, sbyte *externalTarget) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (absPath == null) { throw new ArgumentNullException(nameof(absPath)); } Path = SvnBase.Utf8_PtrToString(path); _pDirEnt = dirent; _pLock = @lock; _pAbsPath = absPath; RepositoryRoot = repositoryRoot; _external_parent_url = externalParentUrl; _external_target = externalTarget; }
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)); }
internal SvnInfoEventArgs(string path, svn_client_info2_t info, AprPool pool) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } if (pool == null) { throw new ArgumentNullException(nameof(pool)); } _info = info; _pool = pool; Path = path; Revision = info.rev; NodeKind = (SvnNodeKind)info.kind; LastChangeRevision = info.last_changed_rev; LastChangeTime = SvnBase.DateTimeFromAprTime(info.last_changed_date); HasLocalInfo = (info.wc_info != null); if (info.wc_info != null) { _wcSchedule = (SvnSchedule)info.wc_info.schedule; CopyFromRevision = info.wc_info.copyfrom_rev; Depth = (SvnDepth)info.wc_info.depth; ContentTime = SvnBase.DateTimeFromAprTime(info.wc_info.recorded_time); if (info.wc_info.recorded_size == -1) { WorkingCopySize = -1; } else { WorkingCopySize = info.wc_info.recorded_size; } Conflicted = info.wc_info.conflicts != null && (info.wc_info.conflicts.nelts > 0); } else { Depth = SvnDepth.Unknown; WorkingCopySize = -1; CopyFromRevision = -1; } if (info.size == -1) { RepositorySize = -1; } else { RepositorySize = info.size; } }
internal SvnDirEntry(svn_dirent_t entry) { _entry = entry ?? throw new ArgumentNullException(nameof(entry)); NodeKind = (SvnNodeKind)entry.kind; FileSize = entry.size; HasProperties = entry.has_props; Revision = entry.created_rev; Time = (entry.time != 0) ? SvnBase.DateTimeFromAprTime(entry.time) : DateTime.MinValue; }
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)); }
static unsafe /*svn_error_t*/ IntPtr _svn_auth_ssl_server_trust_prompt_func( /*out svn_auth_cred_ssl_server_trust_t*/ void **ppCred, IntPtr baton, sbyte *realm, uint failures, /*svn_auth_ssl_server_cert_info_t*/ IntPtr certInfo, int maySave, /*apr_pool_t*/ IntPtr pool) { var wrapper = AprBaton <SvnAuthWrapper <SvnSslServerTrustEventArgs> > .Get(baton); var certInfoT = svn_auth_ssl_server_cert_info_t.__CreateInstance(certInfo); var args = new SvnSslServerTrustEventArgs( (SvnCertificateTrustFailures)failures, SvnBase.Utf8_PtrToString(certInfoT.hostname), SvnBase.Utf8_PtrToString(certInfoT.fingerprint), SvnBase.Utf8_PtrToString(certInfoT.valid_from), SvnBase.Utf8_PtrToString(certInfoT.valid_until), SvnBase.Utf8_PtrToString(certInfoT.issuer_dname), SvnBase.Utf8_PtrToString(certInfoT.ascii_cert), SvnBase.Utf8_PtrToString(realm), maySave != 0); var cred = (svn_auth_cred_ssl_server_trust_t.__Internal * *)ppCred; using (var tmpPool = new AprPool(pool, false)) { *cred = null; try { wrapper.Raise(args); } catch (Exception e) { return(SvnException.CreateExceptionSvnError("Authorization handler", e).__Instance); } if (args.Cancel) { return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Authorization canceled operation").__Instance); } if (args.Break) { return(IntPtr.Zero); } if (args.AcceptedFailures != SvnCertificateTrustFailures.None) { *cred = (svn_auth_cred_ssl_server_trust_t.__Internal *)tmpPool.AllocCleared( sizeof(svn_auth_cred_ssl_server_trust_t.__Internal)); (*cred)->accepted_failures = (uint)args.AcceptedFailures; (*cred)->may_save = args.Save ? 1 : 0; } } return(IntPtr.Zero); }
internal SvnLockInfo(svn_lock_t @lock, bool localData) { if (@lock == null) { throw new ArgumentNullException(nameof(@lock)); } _localData = localData; _lock = @lock; IsRawNetworkComment = @lock.is_dav_comment; CreationTime = SvnBase.DateTimeFromAprTime(@lock.creation_date); ExpirationTime = SvnBase.DateTimeFromAprTime(@lock.expiration_date); }
internal SvnStatusEventArgs(sbyte *path, svn_client_status_t status, SvnClientContext client, AprPool pool) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (status == null) { throw new ArgumentNullException(nameof(status)); } if (pool == null) { throw new ArgumentNullException(nameof(pool)); } _pPath = path; _status = status; _pool = pool; _client = client; Versioned = status.versioned; Conflicted = status.conflicted; NodeKind = (SvnNodeKind)status.kind; FileLength = (status.filesize >= 0) ? status.filesize : -1; LocalNodeStatus = (SvnStatus)status.node_status; LocalTextStatus = (SvnStatus)status.text_status; LocalPropertyStatus = (SvnStatus)status.prop_status; Wedged = status.wc_is_locked; LocalCopied = status.copied; Revision = status.revision; LastChangeRevision = status.changed_rev; LastChangeTime = SvnBase.DateTimeFromAprTime(status.changed_date); Switched = status.switched; IsFileExternal = status.file_external; Depth = (SvnDepth)status.depth; RemoteNodeStatus = (SvnStatus)status.repos_node_status; RemoteTextStatus = (SvnStatus)status.repos_text_status; RemotePropertyStatus = (SvnStatus)status.repos_prop_status; RemoteUpdateRevision = status.ood_changed_rev; if (status.ood_changed_rev != -1) { RemoteUpdateCommitTime = SvnBase.DateTimeFromAprTime(status.ood_changed_date); RemoteUpdateNodeKind = (SvnNodeKind)status.ood_kind; } }
internal unsafe SvnLoggingEventArgs(svn_log_entry_t entry, AprPool pool) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } if (pool == null) { throw new ArgumentNullException(nameof(pool)); } _entry = entry; _pool = pool; sbyte *pcAuthor = null; sbyte *pcDate = null; sbyte *pcMessage = null; if (entry.revprops != null) { svn_compat.svn_compat_log_revprops_out(&pcAuthor, &pcDate, &pcMessage, entry.revprops); } if (pcDate != null) { long when = 0; // Documentation: date must be parsable by svn_time_from_cstring() svn_error_t err = pcDate != null?svn_time.svn_time_from_cstring(ref when, pcDate, pool.Handle) : null; if (err == null) { Time = SvnBase.DateTimeFromAprTime(when); } else { svn_error.svn_error_clear(err); } } else { Time = DateTime.MinValue; } Revision = entry.revision; _pcAuthor = pcAuthor; _pcMessage = pcMessage; NotInheritable = entry.non_inheritable; SubtractiveMerge = entry.subtractive_merge; }
internal static SvnRevision Load(svn_opt_revision_t revData) { if (revData == null) { throw new ArgumentNullException(nameof(revData)); } var type = (SvnRevisionType)revData.kind; switch (type) { case SvnRevisionType.None: return(None); case SvnRevisionType.Committed: return(Committed); case SvnRevisionType.Previous: return(Previous); case SvnRevisionType.Base: return(Base); case SvnRevisionType.Working: return(Working); case SvnRevisionType.Head: return(Head); case SvnRevisionType.Number: if (revData.value.number == 0) { return(Zero); } if (revData.value.number == 1) { return(One); } return(new SvnRevision(revData.value.number)); case SvnRevisionType.Time: // apr_time_t is in microseconds since 1-1-1970 UTC; filetime is in 100 nanoseconds return(new SvnRevision(SvnBase.DateTimeFromAprTime(revData.value.date))); default: throw new ArgumentException(SharpSvnStrings.InvalidSvnRevisionTypeValue, nameof(revData)); } }
internal virtual void RaiseOnNotify(SvnNotifyEventArgs e) { switch (e.Action) { case SvnNotifyAction.LockFailedLock: case SvnNotifyAction.LockFailedUnlock: case SvnNotifyAction.PropertyDeletedNonExistent: case SvnNotifyAction.ExternalFailed: if (e.Error != null) { _warnings = SvnBase.ExtendArray(_warnings, e.Error); } break; } OnNotify(e); }
internal unsafe void Ensure() { if (_ensured || _status == null) { return; } _ensured = true; svn_wc_status2_t.__Internal *status2; var error = libsvnsharp_wc_private.svn_wc__status2_from_3( (void **)&status2, svn_wc_status3_t.__CreateInstance(_status.backwards_compatibility_baton), _client.CtxHandle.wc_ctx, _status.local_abspath, _pool.Handle, _pool.Handle); if (error != null) { throw SvnException.Create(error); } var entry = svn_wc_entry_t.__CreateInstance(status2->entry); _entry = entry; _revision = entry.revision; _nodeKind = (SvnNodeKind)entry.kind; _schedule = (SvnSchedule)entry.schedule; _copied = entry.copied; _deleted = entry.deleted; _absent = entry.absent; _incomplete = entry.incomplete; _copyFromRev = entry.copyfrom_rev; _textTime = SvnBase.DateTimeFromAprTime(entry.text_time); _lastChangeRev = entry.cmt_rev; _lastChangeTime = SvnBase.DateTimeFromAprTime(entry.cmt_date); _lockTime = SvnBase.DateTimeFromAprTime(entry.lock_creation_date); _hasProperties = entry.has_props; _hasPropertyChanges = entry.has_prop_mods; _wcSize = entry.working_size; _keepLocal = entry.keep_local; _depth = (SvnDepth)entry.depth; }
/// <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 _)); }
/// <summary>Gets the filename of the specified target</summary> public static string GetFileName(Uri target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } target = SvnBase.CanonicalizeUri(target); var path = target.AbsolutePath; var nEnd = path.LastIndexOf('?'); if (nEnd < 0) { nEnd = path.Length - 1; } if (path.Length != 0 && nEnd <= path.Length && path[nEnd] == '/') { nEnd--; } if (nEnd <= 0) { return(""); } var nStart = path.LastIndexOf('/', nEnd); if (nStart >= 0) { nStart++; } else { nStart = 0; } path = path.Substring(nStart, nEnd - nStart + 1); return(UriPartToPath(path)); }
internal svn_opt_revision_t.__Internal ToSvnRevision() { var r = new svn_opt_revision_t.__Internal(); r.kind = (svn_opt_revision_kind)RevisionType; // Values are identical by design switch (RevisionType) { case SvnRevisionType.Number: r.value.number = (int)_value; break; case SvnRevisionType.Time: r.value.date = SvnBase.AprTimeFromDateTime(new DateTime(_value, DateTimeKind.Utc)); break; } return(r); }
internal unsafe SvnChangeItem(string path, svn_log_changed_path2_t changed_path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (changed_path == null) { throw new ArgumentNullException(nameof(changed_path)); } _changed_path = changed_path; Path = path; Action = (SvnChangeAction)changed_path.action; _copyFromPath = SvnBase.Utf8_PtrToString(changed_path.copyfrom_path); CopyFromRevision = changed_path.copyfrom_path != null ? changed_path.copyfrom_rev : -1; NodeKind = (SvnNodeKind)changed_path.node_kind; switch (changed_path.text_modified) { case svn_tristate_t.svn_tristate_false: ContentModified = false; break; case svn_tristate_t.svn_tristate_true: ContentModified = true; break; } switch (changed_path.props_modified) { case svn_tristate_t.svn_tristate_false: PropertiesModified = false; break; case svn_tristate_t.svn_tristate_true: PropertiesModified = true; break; } }
static unsafe /*svn_error_t*/ IntPtr _svn_auth_simple_prompt_func( /*out svn_auth_cred_simple_t*/ void **credPtr, IntPtr baton, sbyte *realm, sbyte *username, int maySave, /*apr_pool_t*/ IntPtr pool) { var wrapper = AprBaton <SvnAuthWrapper <SvnUserNamePasswordEventArgs> > .Get(baton); var args = new SvnUserNamePasswordEventArgs(SvnBase.Utf8_PtrToString(username), SvnBase.Utf8_PtrToString(realm), maySave != 0); var cred = (svn_auth_cred_simple_t.__Internal * *)credPtr; using (var tmpPool = new AprPool(pool, false)) { *cred = null; try { wrapper.Raise(args); } catch (Exception e) { return(SvnException.CreateExceptionSvnError("Authorization handler", e).__Instance); } if (args.Cancel) { return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Authorization canceled operation").__Instance); } if (args.Break) { return(IntPtr.Zero); } *cred = (svn_auth_cred_simple_t.__Internal *)tmpPool.AllocCleared(sizeof(svn_auth_cred_simple_t.__Internal)); (*cred)->username = new IntPtr(tmpPool.AllocString(args.UserName)); (*cred)->password = new IntPtr(tmpPool.AllocString(args.Password)); (*cred)->may_save = args.Save ? 1 : 0; } return(IntPtr.Zero); }
internal unsafe SvnCommitResult(svn_commit_info_t commitInfo, AprPool pool) { if (commitInfo == null) { throw new ArgumentNullException(nameof(commitInfo)); } if (pool == null) { throw new ArgumentNullException(nameof(pool)); } Revision = commitInfo.revision; long when = 0; svn_error_t err = svn_time.svn_time_from_cstring(ref when, commitInfo.date, pool.Handle); // pool is not used at this time (might be for errors in future versions) if (err == null) { Time = SvnBase.DateTimeFromAprTime(when); } else { svn_error.svn_error_clear(err); Time = DateTime.MinValue; } Author = SvnBase.Utf8_PtrToString(commitInfo.author); PostCommitError = commitInfo.post_commit_err != null ? SvnBase.Utf8_PtrToString(commitInfo.post_commit_err) .Replace("\n", Environment.NewLine) .Replace("\r\r", "\r") : null; if (commitInfo.repos_root != null) { RepositoryRoot = SvnBase.Utf8_PtrToUri(commitInfo.repos_root, SvnNodeKind.Directory); } }
static unsafe IntPtr svn_info_receiver(IntPtr baton, sbyte *path, IntPtr info_ptr, IntPtr pool) { var client = AprBaton <SvnClient> .Get(baton); using var thePool = new AprPool(pool, false); if (!(client.CurrentCommandArgs is SvnInfoArgs args)) { return(IntPtr.Zero); } var info = svn_client_info2_t.__CreateInstance(info_ptr); var e = new SvnInfoEventArgs(SvnBase.Utf8_PathPtrToString(path, thePool), info, thePool); try { args.OnInfo(e); if (e.Cancel) { return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CEASE_INVOCATION, null, "Info receiver canceled operation").__Instance); } else { return(IntPtr.Zero); } } catch (Exception ex) { return(SvnException.CreateExceptionSvnError("Info receiver", ex).__Instance); } finally { e.Detach(false); } }
/// <summary>Duplicate something in repository, remembering history (<c>svn copy</c>)</summary> /// <remarks>Can be called with either a list of <see cref="SvnTarget" />, <see cref="SvnUriTarget" /> or <see cref="SvnPathTarget" />. /// All members must be of the same type.</remarks> public unsafe bool RemoteCopy <TSvnTarget>(ICollection <TSvnTarget> sources, Uri toUri, SvnCopyArgs args, out SvnCommitResult result) where TSvnTarget : SvnTarget { if (sources == null) { throw new ArgumentNullException(nameof(sources)); } if (toUri == null) { throw new ArgumentNullException(nameof(toUri)); } if (args == null) { throw new ArgumentNullException(nameof(args)); } if (!SvnBase.IsValidReposUri(toUri)) { throw new ArgumentException(SharpSvnStrings.ArgumentMustBeAValidRepositoryUri, nameof(toUri)); } if (sources.Count == 0) { throw new ArgumentException(SharpSvnStrings.CollectionMustContainAtLeastOneItem, nameof(sources)); } bool isFirst = true; bool isLocal = false; foreach (SvnTarget target in sources) { if (target == null) { throw new ArgumentException(SharpSvnStrings.ItemInListIsNull, nameof(sources)); } SvnPathTarget pt = target as SvnPathTarget; if (isFirst) { isLocal = (null != pt); isFirst = false; } else if (isLocal != (null != pt)) { throw new ArgumentException(SharpSvnStrings.AllTargetsMustBeUriOrPath, nameof(sources)); } } EnsureState(SvnContextState.AuthorizationInitialized); using var pool = new AprPool(_pool); using var store = new ArgsStore(this, args, pool); using var crr = new CommitResultReceiver(this); apr_array_header_t copies = AllocCopyArray(sources, pool); if (copies != null && args.Revision.RevisionType != SvnRevisionType.None) { svn_opt_revision_t rev = args.Revision.AllocSvnRevision(pool); for (int i = 0; i < copies.nelts; i++) { var cp = ((svn_client_copy_source_t.__Internal * *)copies.elts)[i]; cp->revision = rev.__Instance; } } svn_error_t r = svn_client.svn_client_copy7( copies, pool.AllocUri(toUri), args.AlwaysCopyAsChild || (sources.Count > 1), args.CreateParents, args.IgnoreExternals, args.MetaDataOnly, args.PinExternals, null /* */, CreateRevPropList(args.LogProperties, pool), crr.CommitCallback.Get(), crr.CommitBaton, CtxHandle, pool.Handle); result = crr.CommitResult; return(args.HandleResult(this, r, sources)); }
static SvnClientArgs() { SvnBase.EnsureLoaded(); }