diff --git a/LibGit2Sharp.Core/Database.cs b/LibGit2Sharp.Core/Database.cs index 91589fd43..8d049bab4 100644 --- a/LibGit2Sharp.Core/Database.cs +++ b/LibGit2Sharp.Core/Database.cs @@ -62,5 +62,13 @@ public RawObject ReadHeader(ObjectId id) GitError.Check(ret); return new RawObject(ro); } + + public RawObject Read(ObjectId id) + { + git_rawobj ro = new git_rawobj(); + int ret = NativeMethods.git_odb_read(&ro, database, &id.oid); + GitError.Check(ret); + return new RawObject(ro); + } } } diff --git a/LibGit2Sharp.Core/RawObject.cs b/LibGit2Sharp.Core/RawObject.cs index 6ffd1beb0..4839f4a73 100644 --- a/LibGit2Sharp.Core/RawObject.cs +++ b/LibGit2Sharp.Core/RawObject.cs @@ -52,6 +52,9 @@ public git_otype Type public byte[] GetData() { + if (rawobj.data == IntPtr.Zero) + return null; + byte[] rawData = new byte[Length]; Marshal.Copy(rawobj.data, rawData, 0, (int)Length); return rawData; diff --git a/LibGit2Sharp.Core/Repository.cs b/LibGit2Sharp.Core/Repository.cs index b27808539..bb7cbb4b3 100644 --- a/LibGit2Sharp.Core/Repository.cs +++ b/LibGit2Sharp.Core/Repository.cs @@ -190,6 +190,30 @@ public Database Database return new Database(NativeMethods.git_repository_database(repository)); } } + + public ObjectId HeadObjectId + { + get { + return ReferenceLookup("HEAD").Resolve().ObjectId; + } + } + + public GitObject GetHead() + { + return Lookup(HeadObjectId); + } + + public T GetHead() where T : GitObject + { + return Lookup(HeadObjectId); + } + + public Commit Head + { + get { + return GetHead(); + } + } #region IDisposable implementation public void Dispose() diff --git a/libgit2sharp.Tests/LookingUpAHeadReference.cs b/LibGit2Sharp.Tests/LookingUpAHeadReference.cs similarity index 100% rename from libgit2sharp.Tests/LookingUpAHeadReference.cs rename to LibGit2Sharp.Tests/LookingUpAHeadReference.cs diff --git a/libgit2sharp.Tests/ResolvingAHeadReference.cs b/LibGit2Sharp.Tests/ResolvingAHeadReference.cs similarity index 100% rename from libgit2sharp.Tests/ResolvingAHeadReference.cs rename to LibGit2Sharp.Tests/ResolvingAHeadReference.cs diff --git a/libgit2sharp.Tests/ResolvingATagReference.cs b/LibGit2Sharp.Tests/ResolvingATagReference.cs similarity index 100% rename from libgit2sharp.Tests/ResolvingATagReference.cs rename to LibGit2Sharp.Tests/ResolvingATagReference.cs diff --git a/libgit2sharp/IReferenceManager.cs b/LibGit2Sharp/IReferenceManager.cs similarity index 100% rename from libgit2sharp/IReferenceManager.cs rename to LibGit2Sharp/IReferenceManager.cs diff --git a/libgit2sharp/ReferenceManager.cs b/LibGit2Sharp/ReferenceManager.cs similarity index 100% rename from libgit2sharp/ReferenceManager.cs rename to LibGit2Sharp/ReferenceManager.cs diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 62c3d6725..264520c1a 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -71,7 +71,7 @@ public Header ReadHeader(string objectId) return new Header(objectId, (ObjectType)rawObj.Type, rawObj.Length); }; - return ReadInternal(objectId, builder); + return ReadHeaderInternal(objectId, builder); } public RawObject Read(string objectId) @@ -91,9 +91,16 @@ public bool Exists(string objectId) return _lifecycleManager.CoreRepository.Database.Exists(new Core.ObjectId(objectId)); } - private TType ReadInternal(string objectid, Func builder) + private TType ReadHeaderInternal(string objectid, Func builder) { var rawObj = _lifecycleManager.CoreRepository.Database.ReadHeader(new Core.ObjectId(objectid)); + + return builder(rawObj); + } + + private TType ReadInternal(string objectid, Func builder) + { + var rawObj = _lifecycleManager.CoreRepository.Database.Read(new Core.ObjectId(objectid)); return builder(rawObj); } diff --git a/README.md b/README.md index 0bae58fcb..4b50d66ee 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,15 @@ NativeMethods.cs for LibGit2.Core. You can do it via the command line: Or just use "Run this item" from your IDE. +Coding Guidelines +================= + +We are using the default Microsoft/MSDN guidlines for coding. +Please don't forget that our tab consists of 4 spaces and every +text file should have a new line at the ending. +The later rule makes it easier for patch tools used by vanilla +git to retrieve patch hunks. + Authors =======