2
2
using System . Diagnostics ;
3
3
using System . Globalization ;
4
4
using LibGit2Sharp . Core ;
5
- using LibGit2Sharp . Core . Compat ;
6
- using LibGit2Sharp . Core . Handles ;
7
5
8
6
namespace LibGit2Sharp
9
7
{
@@ -13,25 +11,43 @@ namespace LibGit2Sharp
13
11
[ DebuggerDisplay ( "{DebuggerDisplay,nq}" ) ]
14
12
public class Submodule : IEquatable < Submodule >
15
13
{
14
+ private readonly SubmoduleLazyGroup group ;
15
+
16
16
private static readonly LambdaEqualityHelper < Submodule > equalityHelper =
17
17
new LambdaEqualityHelper < Submodule > ( x => x . Name , x => x . HeadCommitId ) ;
18
18
19
- private readonly SubmoduleSafeHandle handle ;
20
19
private readonly string name ;
21
- private readonly Lazy < string > lazyPath ;
20
+ private readonly ILazy < string > lazyPath ;
21
+ private readonly ILazy < ObjectId > lazyIndexCommitId ;
22
+ private readonly ILazy < ObjectId > lazyHeadCommitId ;
23
+ private readonly ILazy < ObjectId > lazyWorkdirCommitId ;
24
+ private readonly ILazy < string > lazyUrl ;
25
+ private readonly ILazy < bool > lazyFetchRecurseSubmodulesRule ;
26
+ private readonly ILazy < SubmoduleIgnore > lazyIgnoreRule ;
27
+ private readonly ILazy < SubmoduleUpdate > lazyUpdateRule ;
28
+ private readonly ILazy < SubmoduleStatus > lazyStatus ;
22
29
23
30
/// <summary>
24
31
/// Needed for mocking purposes.
25
32
/// </summary>
26
33
protected Submodule ( )
27
34
{ }
28
35
29
- private Submodule ( SubmoduleSafeHandle handle , string name )
36
+ internal Submodule ( Repository repo , string name )
30
37
{
31
- this . handle = handle ;
32
38
this . name = name ;
33
39
34
- lazyPath = new Lazy < string > ( ( ) => Proxy . git_submodule_path ( handle ) ) ;
40
+ group = new SubmoduleLazyGroup ( repo , name ) ;
41
+ lazyPath = group . AddLazy ( Proxy . git_submodule_path ) ;
42
+ lazyIndexCommitId = group . AddLazy ( Proxy . git_submodule_index_id ) ;
43
+ lazyHeadCommitId = group . AddLazy ( Proxy . git_submodule_head_id ) ;
44
+ lazyWorkdirCommitId = group . AddLazy ( Proxy . git_submodule_wd_id ) ;
45
+ lazyUrl = group . AddLazy ( Proxy . git_submodule_url ) ;
46
+
47
+ lazyFetchRecurseSubmodulesRule = group . AddLazy ( Proxy . git_submodule_fetch_recurse_submodules ) ;
48
+ lazyIgnoreRule = group . AddLazy ( Proxy . git_submodule_ignore ) ;
49
+ lazyUpdateRule = group . AddLazy ( Proxy . git_submodule_update ) ;
50
+ lazyStatus = group . AddLazy ( Proxy . git_submodule_status ) ;
35
51
}
36
52
37
53
/// <summary>
@@ -47,73 +63,52 @@ private Submodule(SubmoduleSafeHandle handle, string name)
47
63
/// <summary>
48
64
/// The commit ID for this submodule in the index.
49
65
/// </summary>
50
- public virtual ObjectId IndexCommitId { get { return Proxy . git_submodule_index_id ( handle ) ; } }
66
+ public virtual ObjectId IndexCommitId { get { return lazyIndexCommitId . Value ; } }
51
67
52
68
/// <summary>
53
69
/// The commit ID for this submodule in the current HEAD tree.
54
70
/// </summary>
55
- public virtual ObjectId HeadCommitId { get { return Proxy . git_submodule_head_id ( handle ) ; } }
71
+ public virtual ObjectId HeadCommitId { get { return lazyHeadCommitId . Value ; } }
56
72
57
73
/// <summary>
58
74
/// The commit ID for this submodule in the current working directory.
59
75
/// </summary>
60
- public virtual ObjectId WorkDirCommitId { get { return Proxy . git_submodule_wd_id ( handle ) ; } }
76
+ public virtual ObjectId WorkDirCommitId { get { return lazyWorkdirCommitId . Value ; } }
61
77
62
78
/// <summary>
63
79
/// The URL of the submodule.
64
80
/// </summary>
65
- public virtual string Url
66
- {
67
- get { return Proxy . git_submodule_url ( handle ) ; }
68
- }
81
+ public virtual string Url { get { return lazyUrl . Value ; } }
69
82
70
83
/// <summary>
71
84
/// The fetchRecurseSubmodules rule for the submodule.
72
85
///
73
86
/// Note that at this time, LibGit2Sharp does not honor this setting and the
74
87
/// fetch functionality current ignores submodules.
75
88
/// </summary>
76
- public virtual bool FetchRecurseSubmodules
89
+ public virtual bool FetchRecurseSubmodulesRule
77
90
{
78
- get { return Proxy . git_submodule_fetch_recurse_submodules ( handle ) ; }
91
+ get { return lazyFetchRecurseSubmodulesRule . Value ; }
79
92
}
80
93
81
94
/// <summary>
82
95
/// The ignore rule of the submodule.
83
96
/// </summary>
84
- public virtual SubmoduleIgnore Ignore
85
- {
86
- get { return Proxy . git_submodule_ignore ( handle ) ; }
87
- }
97
+ public virtual SubmoduleIgnore IgnoreRule { get { return lazyIgnoreRule . Value ; } }
88
98
89
99
/// <summary>
90
100
/// The update rule of the submodule.
91
101
/// </summary>
92
- public virtual SubmoduleUpdate Update
93
- {
94
- get { return Proxy . git_submodule_update ( handle ) ; }
95
- }
96
-
97
- /// <summary>
98
- /// Add current submodule HEAD commit to index of superproject.
99
- /// </summary>
100
- public virtual void Stage ( )
101
- {
102
- Stage ( true ) ;
103
- }
104
-
105
- internal virtual void Stage ( bool writeIndex )
106
- {
107
- Proxy . git_submodule_add_to_index ( handle , writeIndex ) ;
108
- }
102
+ public virtual SubmoduleUpdate UpdateRule { get { return lazyUpdateRule . Value ; } }
109
103
110
104
/// <summary>
111
105
/// Retrieves the state of this submodule in the working directory compared to the staging area and the latest commmit.
112
106
/// </summary>
113
107
/// <returns></returns>
114
108
public virtual SubmoduleStatus RetrieveStatus ( )
115
109
{
116
- return Proxy . git_submodule_status ( handle ) ;
110
+ // Should be a property? Should it be dynamic?
111
+ return lazyStatus . Value ;
117
112
}
118
113
119
114
/// <summary>
@@ -154,11 +149,6 @@ public override string ToString()
154
149
return Name ;
155
150
}
156
151
157
- internal static Submodule BuildFromPtr ( SubmoduleSafeHandle handle , string name )
158
- {
159
- return handle == null ? null : new Submodule ( handle , name ) ;
160
- }
161
-
162
152
private string DebuggerDisplay
163
153
{
164
154
get
0 commit comments