From e5d62690f5d6fe6f626f7c1f04c415e73a9278b5 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Wed, 9 Mar 2011 15:37:06 +0100 Subject: [PATCH 1/5] Fix building. Move files from legacy folders. --- .../LookingUpAHeadReference.cs | 0 .../ResolvingAHeadReference.cs | 0 .../ResolvingATagReference.cs | 0 {libgit2sharp => LibGit2Sharp}/IReferenceManager.cs | 0 {libgit2sharp => LibGit2Sharp}/ReferenceManager.cs | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {libgit2sharp.Tests => LibGit2Sharp.Tests}/LookingUpAHeadReference.cs (100%) rename {libgit2sharp.Tests => LibGit2Sharp.Tests}/ResolvingAHeadReference.cs (100%) rename {libgit2sharp.Tests => LibGit2Sharp.Tests}/ResolvingATagReference.cs (100%) rename {libgit2sharp => LibGit2Sharp}/IReferenceManager.cs (100%) rename {libgit2sharp => LibGit2Sharp}/ReferenceManager.cs (100%) 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 From f153f6c20c2e0e58d1fb288a03ba32a0577a5077 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Wed, 9 Mar 2011 15:54:34 +0100 Subject: [PATCH 2/5] Add fields to retrieve HEAD easily. This will make life easier! --- LibGit2Sharp.Core/Repository.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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() From d4e24455f6355216cdf5a1767c562e77804a55f1 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Wed, 9 Mar 2011 15:56:54 +0100 Subject: [PATCH 3/5] Fix GetData Marshal exception. rawobj can be obtained with read_header which will result in the lack of a proper pointer. So we need to check for if the pointer is not null. --- LibGit2Sharp.Core/Database.cs | 8 ++++++++ LibGit2Sharp.Core/RawObject.cs | 3 +++ 2 files changed, 11 insertions(+) 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; From a6607cdf2b351bcd336d443156e01ed18b3c6b73 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Wed, 9 Mar 2011 16:07:05 +0100 Subject: [PATCH 4/5] Fix AnExistingObjectCanBeRead TestCase. There are two functions, ReadHeader and Read in the main API. The one reads the size of an rawobj, the other additionaly the pointer where it points to (most probably it will load stuff into memory). --- LibGit2Sharp/Repository.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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); } From 5a0232f8413a92b78f5912437db5097a1a62be17 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Wed, 9 Mar 2011 16:12:58 +0100 Subject: [PATCH 5/5] Update README.md Add Coding Style Guidlines! --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) 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 =======