diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-04-16 02:12:07 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-04-24 12:51:44 +0400 |
commit | 00d6d1be22a8fe92d8bb3765220db6c66b03a40a (patch) | |
tree | 6a8660305cd7efcd9b3e81f324fbe1f3eaa85add /LibGit2Sharp/ObjectDatabase.cs | |
parent | 49f12808e25e38e8f4493fe72ba137a5eaea2f37 (diff) |
Add Repository.ObjectDatabase.CreateBlob()
Diffstat (limited to 'LibGit2Sharp/ObjectDatabase.cs')
-rw-r--r-- | LibGit2Sharp/ObjectDatabase.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index 76d2c0b4..293cf8de 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -1,3 +1,4 @@ +using System; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; @@ -9,10 +10,12 @@ namespace LibGit2Sharp /// </summary> public class ObjectDatabase { + private readonly Repository repo; private readonly ObjectDatabaseSafeHandle handle; internal ObjectDatabase(Repository repo) { + this.repo = repo; Ensure.Success(NativeMethods.git_repository_odb(out handle, repo.Handle)); repo.RegisterForCleanup(handle); @@ -29,5 +32,22 @@ namespace LibGit2Sharp return NativeMethods.git_odb_exists(handle, ref oid) != (int)GitErrorCode.GIT_SUCCESS; } + + /// <summary> + /// Inserts a <see cref="Blob"/> into the object database, created from the content of a file. + /// </summary> + /// <param name="path">Relative path to the file in the working directory.</param> + /// <returns>The created <see cref="Blob"/>.</returns> + public Blob CreateBlob(string path) + { + if (repo.Info.IsBare) + { + throw new NotImplementedException(); + } + + var oid = new GitOid(); + Ensure.Success(NativeMethods.git_blob_create_fromfile(ref oid, repo.Handle, path)); + return repo.Lookup<Blob>(new ObjectId(oid)); + } } } |