@@ -52,63 +52,76 @@ public Repository(string path, RepositoryOptions options = null)
52
52
{
53
53
Ensure . ArgumentNotNullOrEmptyString ( path , "path" ) ;
54
54
55
- handle = Proxy . git_repository_open ( path ) ;
56
- RegisterForCleanup ( handle ) ;
57
-
58
- isBare = Proxy . git_repository_is_bare ( handle ) ;
55
+ try
56
+ {
57
+ handle = Proxy . git_repository_open ( path ) ;
58
+ RegisterForCleanup ( handle ) ;
59
59
60
- Func < Index > indexBuilder = ( ) => new Index ( this ) ;
60
+ isBare = Proxy . git_repository_is_bare ( handle ) ;
61
61
62
- string configurationGlobalFilePath = null ;
63
- string configurationXDGFilePath = null ;
64
- string configurationSystemFilePath = null ;
62
+ Func < Index > indexBuilder = ( ) => new Index ( this ) ;
65
63
66
- if ( options != null )
67
- {
68
- bool isWorkDirNull = string . IsNullOrEmpty ( options . WorkingDirectoryPath ) ;
69
- bool isIndexNull = string . IsNullOrEmpty ( options . IndexPath ) ;
64
+ string configurationGlobalFilePath = null ;
65
+ string configurationXDGFilePath = null ;
66
+ string configurationSystemFilePath = null ;
70
67
71
- if ( isBare && ( isWorkDirNull ^ isIndexNull ) )
68
+ if ( options != null )
72
69
{
73
- throw new ArgumentException ( "When overriding the opening of a bare repository, both RepositoryOptions.WorkingDirectoryPath an RepositoryOptions.IndexPath have to be provided." ) ;
74
- }
70
+ bool isWorkDirNull = string . IsNullOrEmpty ( options . WorkingDirectoryPath ) ;
71
+ bool isIndexNull = string . IsNullOrEmpty ( options . IndexPath ) ;
75
72
76
- isBare = false ;
73
+ if ( isBare && ( isWorkDirNull ^ isIndexNull ) )
74
+ {
75
+ throw new ArgumentException (
76
+ "When overriding the opening of a bare repository, both RepositoryOptions.WorkingDirectoryPath an RepositoryOptions.IndexPath have to be provided." ) ;
77
+ }
77
78
78
- if ( ! isIndexNull )
79
- {
80
- indexBuilder = ( ) => new Index ( this , options . IndexPath ) ;
79
+ isBare = false ;
80
+
81
+ if ( ! isIndexNull )
82
+ {
83
+ indexBuilder = ( ) => new Index ( this , options . IndexPath ) ;
84
+ }
85
+
86
+ if ( ! isWorkDirNull )
87
+ {
88
+ Proxy . git_repository_set_workdir ( handle , options . WorkingDirectoryPath ) ;
89
+ }
90
+
91
+ configurationGlobalFilePath = options . GlobalConfigurationLocation ;
92
+ configurationXDGFilePath = options . XdgConfigurationLocation ;
93
+ configurationSystemFilePath = options . SystemConfigurationLocation ;
81
94
}
82
95
83
- if ( ! isWorkDirNull )
96
+ if ( ! isBare )
84
97
{
85
- Proxy . git_repository_set_workdir ( handle , options . WorkingDirectoryPath ) ;
98
+ index = indexBuilder ( ) ;
99
+ conflicts = new ConflictCollection ( this ) ;
86
100
}
87
101
88
- configurationGlobalFilePath = options . GlobalConfigurationLocation ;
89
- configurationXDGFilePath = options . XdgConfigurationLocation ;
90
- configurationSystemFilePath = options . SystemConfigurationLocation ;
91
- }
102
+ commits = new CommitLog ( this ) ;
103
+ refs = new ReferenceCollection ( this ) ;
104
+ branches = new BranchCollection ( this ) ;
105
+ tags = new TagCollection ( this ) ;
106
+ info = new Lazy < RepositoryInformation > ( ( ) => new RepositoryInformation ( this , isBare ) ) ;
107
+ config =
108
+ new Lazy < Configuration > (
109
+ ( ) =>
110
+ RegisterForCleanup ( new Configuration ( this , configurationGlobalFilePath , configurationXDGFilePath ,
111
+ configurationSystemFilePath ) ) ) ;
112
+ odb = new Lazy < ObjectDatabase > ( ( ) => new ObjectDatabase ( this ) ) ;
113
+ diff = new Diff ( this ) ;
114
+ notes = new NoteCollection ( this ) ;
115
+ ignore = new Ignore ( this ) ;
116
+ network = new Lazy < Network > ( ( ) => new Network ( this ) ) ;
92
117
93
- if ( ! isBare )
118
+ EagerlyLoadTheConfigIfAnyPathHaveBeenPassed ( options ) ;
119
+ }
120
+ catch
94
121
{
95
- index = indexBuilder ( ) ;
96
- conflicts = new ConflictCollection ( this ) ;
122
+ CleanupDisposableDependencies ( ) ;
123
+ throw ;
97
124
}
98
-
<
F438
/td>99
- commits = new CommitLog ( this ) ;
100
- refs = new ReferenceCollection ( this ) ;
101
- branches = new BranchCollection ( this ) ;
102
- tags = new TagCollection ( this ) ;
103
- info = new Lazy < RepositoryInformation > ( ( ) => new RepositoryInformation ( this , isBare ) ) ;
104
- config = new Lazy < Configuration > ( ( ) => RegisterForCleanup ( new Configuration ( this , configurationGlobalFilePath , configurationXDGFilePath , configurationSystemFilePath ) ) ) ;
105
- odb = new Lazy < ObjectDatabase > ( ( ) => new ObjectDatabase ( this ) ) ;
106
- diff = new Diff ( this ) ;
107
- notes = new NoteCollection ( this ) ;
108
- ignore = new Ignore ( this ) ;
109
- network = new Lazy < Network > ( ( ) => new Network ( this ) ) ;
110
-
111
- EagerlyLoadTheConfigIfAnyPathHaveBeenPassed ( options ) ;
112
125
}
113
126
114
127
private void EagerlyLoadTheConfigIfAnyPathHaveBeenPassed ( RepositoryOptions options )
@@ -312,10 +325,7 @@ public void Dispose()
312
325
/// </summary>
313
326
protected virtual void Dispose ( bool disposing )
314
327
{
315
- while ( toCleanup . Count > 0 )
316
- {
317
- toCleanup . Pop ( ) . SafeDispose ( ) ;
318
- }
328
+ CleanupDisposableDependencies ( ) ;
319
329
}
320
330
321
331
#endregion
@@ -701,6 +711,14 @@ public virtual void RemoveUntrackedFiles()
701
711
Proxy . git_checkout_index ( Handle , new NullGitObjectSafeHandle ( ) , ref options ) ;
702
712
}
703
713
714
+ private void CleanupDisposableDependencies ( )
715
+ {
716
+ while ( toCleanup . Count > 0 )
717
+ {
718
+ toCleanup . Pop ( ) . SafeDispose ( ) ;
719
+ }
720
+ }
721
+
704
722
internal T RegisterForCleanup < T > ( T disposable ) where T : IDisposable
705
723
{
706
724
toCleanup . Push ( disposable ) ;
0 commit comments