@@ -23,7 +23,7 @@ public sealed class Repository : IRepository
2323 private readonly CommitLog commits ;
2424 private readonly Lazy < Configuration > config ;
2525 private readonly RepositorySafeHandle handle ;
26- private readonly Index index ;
26+ private readonly Lazy < Index > index ;
2727 private readonly ReferenceCollection refs ;
2828 private readonly TagCollection tags ;
2929 private readonly StashCollection stashes ;
@@ -98,7 +98,7 @@ public Repository(string path, RepositoryOptions options = null)
9898
9999 if ( ! isBare )
100100 {
101- index = indexBuilder ( ) ;
101+ index = new Lazy < Index > ( ( ) => indexBuilder ( ) ) ;
102102 }
103103
104104 commits = new CommitLog ( this ) ;
@@ -120,7 +120,7 @@ public Repository(string path, RepositoryOptions options = null)
120120 pathCase = new Lazy < PathCase > ( ( ) => new PathCase ( this ) ) ;
121121 submodules = new SubmoduleCollection ( this ) ;
122122
123- EagerlyLoadTheConfigIfAnyPathHaveBeenPassed ( options ) ;
123+ EagerlyLoadComponentsWithSpecifiedPaths ( options ) ;
124124 }
125125 catch
126126 {
@@ -153,26 +153,33 @@ static public bool IsValid(string path)
153153 return true ;
154154 }
155155
156- private void EagerlyLoadTheConfigIfAnyPathHaveBeenPassed ( RepositoryOptions options )
156+ private void EagerlyLoadComponentsWithSpecifiedPaths ( RepositoryOptions options )
157157 {
158158 if ( options == null )
159159 {
160160 return ;
161161 }
162162
163- if ( options . GlobalConfigurationLocation == null &&
164- options . XdgConfigurationLocation == null &&
165- options . SystemConfigurationLocation = = null )
163+ if ( options . GlobalConfigurationLocation != null ||
164+ options . XdgConfigurationLocation != null ||
165+ options . SystemConfigurationLocation ! = null )
166166 {
167- return ;
168- }
167+ // Dirty hack to force the eager load of the configuration
168+ // without Resharper pestering about useless code
169169
170- // Dirty hack to force the eager load of the configuration
171- // without Resharper pestering about useless code
170+ if ( ! Config . HasConfig ( ConfigurationLevel . Local ) )
171+ {
172+ throw new InvalidOperationException ( "Unexpected state." ) ;
173+ }
174+ }
172175
173- if ( ! Config . HasConfig ( ConfigurationLevel . Local ) )
176+ if ( ! string . IsNullOrEmpty ( options . IndexPath ) )
174177 {
175- throw new InvalidOperationException ( "Unexpected state." ) ;
178+ // Another dirty hack to avoid warnings
179+ if ( Index . Count < 0 )
180+ {
181+ throw new InvalidOperationException ( "Unexpected state." ) ;
182+ }
176183 }
177184 }
178185
@@ -224,7 +231,7 @@ public Index Index
224231 throw new BareRepositoryException ( "Index is not available in a bare repository." ) ;
225232 }
226233
227- return index ;
234+ return index . Value ;
228235 }
229236 }
230237
0 commit comments