@@ -23,7 +23,7 @@ public sealed class Repository : IRepository
23
23
private readonly CommitLog commits ;
24
24
private readonly Lazy < Configuration > config ;
25
25
private readonly RepositorySafeHandle handle ;
26
- private readonly Index index ;
26
+ private readonly Lazy < Index > index ;
27
27
private readonly ReferenceCollection refs ;
28
28
private readonly TagCollection tags ;
29
29
private readonly StashCollection stashes ;
@@ -98,7 +98,7 @@ public Repository(string path, RepositoryOptions options = null)
98
98
99
99
if ( ! isBare )
100
100
{
101
- index = indexBuilder ( ) ;
101
+ index = new Lazy < Index > ( ( ) => indexBuilder ( ) ) ;
102
102
}
103
103
104
104
commits = new CommitLog ( this ) ;
@@ -120,7 +120,7 @@ public Repository(string path, RepositoryOptions options = null)
120
120
pathCase = new Lazy < PathCase > ( ( ) => new PathCase ( this ) ) ;
121
121
submodules = new SubmoduleCollection ( this ) ;
122
122
123
- EagerlyLoadTheConfigIfAnyPathHaveBeenPassed ( options ) ;
123
+ EagerlyLoadComponentsWithSpecifiedPaths ( options ) ;
124
124
}
125
125
catch
126
126
{
@@ -153,26 +153,33 @@ static public bool IsValid(string path)
153
153
return true ;
154
154
10000
code>
}
155
155
156
- private void EagerlyLoadTheConfigIfAnyPathHaveBeenPassed ( RepositoryOptions options )
156
+ private void EagerlyLoadComponentsWithSpecifiedPaths ( RepositoryOptions options )
157
157
{
158
158
if ( options == null )
159
159
{
160
160
return ;
161
161
}
162
162
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 )
166
166
{
167
- return ;
168
- }
167
+ // Dirty hack to force the eager load of the configuration
168
+ // without Resharper pestering about useless code
169
169
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
+ }
172
175
173
- if ( ! Config . HasConfig ( ConfigurationLevel . Local ) )
176
+ if ( ! string . IsNullOrEmpty ( options . IndexPath ) )
174
177
{
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
+ }
176
183
}
177
184
}
178
185
@@ -224,7 +231,7 @@ public Index Index
224
231
throw new BareRepositoryException ( "Index is not available in a bare repository." ) ;
225
232
}
226
233
227
- return index ;
234
+ return index . Value ;
228
235
}
229
236
}
230
237
0 commit comments