diff options
author | yorah <yoram.harmelin@gmail.com> | 2012-08-29 20:05:47 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-08-29 22:14:31 +0400 |
commit | eb304fb0c92df60339836b962a96a3d43f48d7f7 (patch) | |
tree | b49ad08201406d354304010c5f17d241d1b99c3c /LibGit2Sharp/ObjectDatabase.cs | |
parent | 8fa70ffce8bca7ff66fe4b84293d14b66bbed29f (diff) |
Make retrieval of error message thread-safe
Fix #203
Diffstat (limited to 'LibGit2Sharp/ObjectDatabase.cs')
-rw-r--r-- | LibGit2Sharp/ObjectDatabase.cs | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index 373081fa..35183ef2 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -26,7 +26,7 @@ namespace LibGit2Sharp internal ObjectDatabase(Repository repo) { this.repo = repo; - Ensure.Success(NativeMethods.git_repository_odb(out handle, repo.Handle)); + handle = Proxy.git_repository_odb(repo.Handle); repo.RegisterForCleanup(handle); } @@ -40,9 +40,7 @@ namespace LibGit2Sharp { Ensure.ArgumentNotNull(objectId, "objectId"); - var oid = objectId.Oid; - - return NativeMethods.git_odb_exists(handle, ref oid) != (int)GitErrorCode.Ok; + return Proxy.git_odb_exists(handle, objectId); } /// <summary> @@ -56,18 +54,16 @@ namespace LibGit2Sharp { Ensure.ArgumentNotNullOrEmptyString(path, "path"); - var oid = new GitOid(); - if (repo.Info.IsBare && !Path.IsPathRooted(path)) { throw new InvalidOperationException(string.Format("Cannot create a blob in a bare repository from a relative path ('{0}').", path)); } - Ensure.Success(Path.IsPathRooted(path) - ? NativeMethods.git_blob_create_fromdisk(ref oid, repo.Handle, path) - : NativeMethods.git_blob_create_fromfile(ref oid, repo.Handle, path)); + ObjectId id = Path.IsPathRooted(path) + ? Proxy.git_blob_create_fromdisk(repo.Handle, path) + : Proxy.git_blob_create_fromfile(repo.Handle, path); - return repo.Lookup<Blob>(new ObjectId(oid)); + return repo.Lookup<Blob>(id); } private class Processor @@ -100,12 +96,10 @@ namespace LibGit2Sharp { Ensure.ArgumentNotNull(reader, "reader"); - var oid = new GitOid(); - var proc = new Processor(reader); - Ensure.Success(NativeMethods.git_blob_create_fromchunks(ref oid, repo.Handle, hintpath, proc.Provider, IntPtr.Zero)); + ObjectId id = Proxy.git_blob_create_fromchunks(repo.Handle, hintpath, proc.Provider); - return repo.Lookup<Blob>(new ObjectId(oid)); + return repo.Lookup<Blob>(id); } /// <summary> @@ -120,15 +114,6 @@ namespace LibGit2Sharp return treeDefinition.Build(repo); } - internal static string PrettifyMessage(string message) - { - var buffer = new byte[NativeMethods.GIT_PATH_MAX]; - int res = NativeMethods.git_message_prettify(buffer, buffer.Length, message, false); - Ensure.Success(res); - - return Utf8Marshaler.Utf8FromBuffer(buffer) ?? string.Empty; - } - /// <summary> /// Inserts a <see cref = "Commit"/> into the object database, referencing an existing <see cref = "Tree"/>. /// </summary> @@ -151,25 +136,12 @@ namespace LibGit2Sharp Ensure.ArgumentNotNull(tree, "tree"); Ensure.ArgumentNotNull(parents, "parents"); - string prettifiedMessage = PrettifyMessage(message); - + string prettifiedMessage = Proxy.git_message_prettify(message); IEnumerable<ObjectId> parentIds = parents.Select(p => p.Id); - GitOid commitOid; - using (var treePtr = new ObjectSafeWrapper(tree.Id, repo)) - using (var parentObjectPtrs = new DisposableEnumerable<ObjectSafeWrapper>(parentIds.Select(id => new ObjectSafeWrapper(id, repo)))) - using (SignatureSafeHandle authorHandle = author.BuildHandle()) - using (SignatureSafeHandle committerHandle = committer.BuildHandle()) - { - string encoding = null; //TODO: Handle the encoding of the commit to be created - - IntPtr[] parentsPtrs = parentObjectPtrs.Select(o => o.ObjectPtr.DangerousGetHandle()).ToArray(); - int res = NativeMethods.git_commit_create(out commitOid, repo.Handle, referenceName, authorHandle, - committerHandle, encoding, prettifiedMessage, treePtr.ObjectPtr, parentObjectPtrs.Count(), parentsPtrs); - Ensure.Success(res); - } + ObjectId commitId = Proxy.git_commit_create(repo.Handle, referenceName, author, committer, prettifiedMessage, tree, parentIds); - return repo.Lookup<Commit>(new ObjectId(commitOid)); + return repo.Lookup<Commit>(commitId); } } } |