Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2011-06-07 23:56:53 +0400
committernulltoken <emeric.fermas@gmail.com>2011-06-07 23:57:47 +0400
commit272b92db12cad8e80ef57c3b29ec4e37692195e9 (patch)
treed8c12903bb66ff60fd799fa1b7532476e867b98e
parentc52db7dfc77cf31616dfe1feb0fbbfd9cff98ce4 (diff)
Defer resolving of Repository.Info
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs4
-rw-r--r--LibGit2Sharp/Repository.cs18
-rw-r--r--LibGit2Sharp/RepositoryInformation.cs8
3 files changed, 21 insertions, 9 deletions
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index fdac1e28..e539f6c5 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -151,6 +151,10 @@ namespace LibGit2Sharp.Core
[DllImport(libgit2)]
[return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool git_repository_is_bare(RepositorySafeHandle handle);
+
+ [DllImport(libgit2)]
+ [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool git_repository_is_empty(RepositorySafeHandle repo);
[DllImport(libgit2)]
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 7600c7ea..b1d76c3a 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -14,6 +14,8 @@ namespace LibGit2Sharp
private readonly Index index;
private readonly ReferenceCollection refs;
private readonly TagCollection tags;
+ private RepositoryInformation info;
+ private readonly bool isBare;
/// <summary>
/// Initializes a new instance of the <see cref = "Repository" /> class.
@@ -27,13 +29,12 @@ namespace LibGit2Sharp
var res = NativeMethods.git_repository_open(out handle, PosixPathHelper.ToPosix(path));
Ensure.Success(res);
- string normalizedPath = NativeMethods.git_repository_path(handle, GitRepositoryPathId.GIT_REPO_PATH).MarshallAsString();
- string normalizedWorkDir = NativeMethods.git_repository_path(handle, GitRepositoryPathId.GIT_REPO_PATH_WORKDIR).MarshallAsString();
+ isBare = NativeMethods.git_repository_is_bare(handle);
- Info = new RepositoryInformation(this, normalizedPath, normalizedWorkDir, normalizedWorkDir == null);
-
- if (!Info.IsBare)
+ if (!isBare)
+ {
index = new Index(this);
+ }
commits = new CommitCollection(this);
refs = new ReferenceCollection(this);
@@ -45,11 +46,11 @@ namespace LibGit2Sharp
{
get { return handle; }
}
+
/// <summary>
/// Shortcut to return the reference to HEAD
/// </summary>
/// <returns></returns>
-
public Reference Head
{
get { return Refs["HEAD"]; }
@@ -99,7 +100,10 @@ namespace LibGit2Sharp
/// <summary>
/// Provides high level information about this repository.
/// </summary>
- public RepositoryInformation Info { get; set; }
+ public RepositoryInformation Info
+ {
+ get { return info ?? (info = new RepositoryInformation(this, isBare)); }
+ }
#region IDisposable Members
diff --git a/LibGit2Sharp/RepositoryInformation.cs b/LibGit2Sharp/RepositoryInformation.cs
index 97588070..7129806b 100644
--- a/LibGit2Sharp/RepositoryInformation.cs
+++ b/LibGit2Sharp/RepositoryInformation.cs
@@ -9,11 +9,15 @@ namespace LibGit2Sharp
{
private readonly Repository repo;
- internal RepositoryInformation(Repository repo, string posixPath, string posixWorkingDirectoryPath, bool isBare)
+ internal RepositoryInformation(Repository repo, bool isBare)
{
this.repo = repo;
- Path = PosixPathHelper.ToNative(posixPath);
IsBare = isBare;
+
+ string posixPath = NativeMethods.git_repository_path(repo.Handle, GitRepositoryPathId.GIT_REPO_PATH).MarshallAsString();
+ string posixWorkingDirectoryPath = NativeMethods.git_repository_path(repo.Handle, GitRepositoryPathId.GIT_REPO_PATH_WORKDIR).MarshallAsString();
+
+ Path = PosixPathHelper.ToNative(posixPath);
WorkingDirectory = PosixPathHelper.ToNative(posixWorkingDirectoryPath);
}