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
{
@@ -16,22 +14,39 @@ public class Submodule : IEquatable<Submodule>
16
14
private static readonly LambdaEqualityHelper < Submodule > equalityHelper =
17
15
new LambdaEqualityHelper < Submodule > ( x => x . Name , x => x . HeadCommitId ) ;
18
16
19
- private readonly SubmoduleSafeHandle handle ;
17
+ private readonly Repository repo ;
20
18
private readonly string name ;
21
- private readonly Lazy < string > lazyPath ;
19
+ private readonly string path ;
20
+ private readonly string url ;
21
+ private readonly ILazy < ObjectId > indexCommitId ;
22
+ private readonly ILazy < ObjectId > headCommitId ;
23
+ private readonly ILazy < ObjectId > workdirCommitId ;
24
+ private readonly ILazy < bool > fetchRecurseSubmodulesRule ;
25
+ private readonly ILazy < SubmoduleIgnore > ignoreRule ;
26
+ private readonly ILazy < SubmoduleUpdate > updateRule ;
22
27
23
28
/// <summary>
24
29
/// Needed for mocking purposes.
25
30
/// </summary>
26
31
protected Submodule ( )
27
32
{ }
28
33
29
- private Submodule ( SubmoduleSafeHandle handle , string name )
34
+ internal Submodule ( Repository repo , string name , string path , string url )
30
35
{
31
- this . handle = handle ;
36
+ this . repo = repo ;
32
37
this . name = name ;
33
-
34
- lazyPath = new Lazy < string > ( ( ) => Proxy . git_submodule_path ( handle ) ) ;
38
+ this . path = path ;
39
+ this . url = url ;
40
+
41
+ var commitIds = new SubmoduleLazyGroup ( repo , name ) ;
42
+ indexCommitId = commitIds . AddLazy ( Proxy . git_submodule_index_id ) ;
43
+ headCommitId = commitIds . AddLazy ( Proxy . git_submodule_head_id ) ;
44
+ workdirCommitId = commitIds . AddLazy ( Proxy . git_submodule_wd_id ) ;
45
+
46
+ var rules = new SubmoduleLazyGroup ( repo , name ) ;
47
+ fetchRecurseSubmodulesRule = rules . AddLazy ( Proxy . git_submodule_fetch_recurse_submodules ) ;
48
+ ignoreRule = rules . AddLazy ( Proxy . git_submodule_ignore ) ;
49
+ updateRule = rules . AddLazy ( Proxy . git_submodule_update ) ;
35
50
}
36
51
37
52
/// <summary>
@@ -42,65 +57,56 @@ private Submodule(SubmoduleSafeHandle handle, string name)
42
57
/// <summary>
43
58
/// The path of the submodule.
44
59
/// </summary>
45
- public virtual string Path { get { return lazyPath . Value ; } }
60
+ public virtual string Path { get { return path ; } }
46
61
47
62
/// <summary>
48
- /// The commit ID for this submodule in the index .
63
+ /// The URL of the submodule .
49
64
/// </summary>
50
- public virtual ObjectId IndexCommitId { get { return Proxy . git_submodule_index_id ( handle ) ; } }
65
+ public virtual string Url { get { return url ; } }
51
66
52
67
/// <summary>
53
- /// The commit ID for this submodule in the current HEAD tree .
68
+ /// The commit ID for this submodule in the index .
54
69
/// </summary>
55
- public virtual ObjectId HeadCommitId { get { return Proxy . git_submodule_head_id ( handle ) ; } }
70
+ public virtual ObjectId IndexCommitId { get { return indexCommitId . Value ; } }
56
71
57
72
/// <summary>
58
- /// The commit ID for this submodule in the current working directory .
73
+ /// The commit ID for this submodule in the current HEAD tree .
59
74
/// </summary>
60
- public virtual ObjectId WorkDirCommitId { get { return Proxy . git_submodule_wd_id ( handle ) ; } }
75
+ public virtual ObjectId HeadCommitId { get { return headCommitId . Value ; } }
61
76
62
77
/// <summary>
63
- /// The URL of the submodule.
78
+ /// The commit ID for this submodule in the current working directory .
64
79
/// </summary>
65
- public virtual string Url
66
- {
67
- get { return Proxy . git_submodule_url ( handle ) ; }
68
- }
80
+ public virtual ObjectId WorkDirCommitId { get { return workdirCommitId . Value ; } }
69
81
70
82
/// <summary>
71
83
/// The fetchRecurseSubmodules rule for the submodule.
72
84
///
73
85
/// Note that at this time, LibGit2Sharp does not honor this setting and the
74
86
/// fetch functionality current ignores submodules.
75
87
/// </summary>
76
- public virtual bool FetchRecurseSubmodulesRule
77
- {
78
- get { return Proxy . git_submodule_fetch_recurse_submodules ( handle ) ; }
79
- }
88
+ public virtual bool FetchRecurseSubmodulesRule { get { return fetchRecurseSubmodulesRule . Value ; } }
80
89
81
90
/// <summary>
82
91
/// The ignore rule of the submodule.
83
92
/// </summary>
84
- public virtual SubmoduleIgnore IgnoreRule
85
- {
86
- get { return Proxy . git_submodule_ignore ( handle ) ; }
87
- }
93
+ public virtual SubmoduleIgnore IgnoreRule { get { return ignoreRule . Value ; } }
88
94
89
95
/// <summary>
90
96
/// The update rule of the submodule.
91
97
/// </summary>
92
- public virtual SubmoduleUpdate UpdateRule
93
- {
94
- get { return Proxy . git_submodule_update ( handle ) ; }
95
- }
98
+ public virtual SubmoduleUpdate UpdateRule { get { return updateRule . Value ; } }
96
99
97
100
/// <summary>
98
101
/// Retrieves the state of this submodule in the working directory compared to the staging area and the latest commmit.
99
102
/// </summary>
100
103
/// <returns></returns>
101
104
public virtual SubmoduleStatus RetrieveStatus ( )
102
105
{
103
- return Proxy . git_submodule_status ( handle ) ;
106
+ using ( var handle = Proxy . git_submodule_lookup ( repo . Handle , Name ) )
107
+ {
108
+ return Proxy . git_submodule_status ( handle ) ;
109
+ }
104
110
}
105
111
106
112
/// <summary>
@@ -141,11 +147,6 @@ public override string ToString()
141
147
return Name ;
142
148
}
143
149
144
- internal static Submodule BuildFromPtr ( SubmoduleSafeHandle handle , string name )
145
- {
146
- return handle == null ? null : new Submodule ( handle , name ) ;
147
- }
148
-
149
150
private string DebuggerDisplay
150
151
{
151
152
get
0 commit comments