@@ -11,19 +11,18 @@ public class GitRepoMetadataProvider
11
11
private Dictionary < Branch , List < BranchCommit > > mergeBaseCommitsCache ;
12
12
private Dictionary < Tuple < Branch , Branch > , MergeBaseData > mergeBaseCache ;
13
13
private Dictionary < Branch , List < SemanticVersion > > semanticVersionTagsOnBranchCache ;
14
- private IRepository repository ;
14
+ private IRepository Repository { get ; set ; }
15
15
const string missingTipFormat = "{0} has no tip. Please see http://example.com/docs for information on how to fix this." ;
16
16
17
-
18
17
public GitRepoMetadataProvider ( IRepository repository )
19
18
{
20
19
mergeBaseCache = new Dictionary < Tuple < Branch , Branch > , MergeBaseData > ( ) ;
21
20
mergeBaseCommitsCache = new Dictionary < Branch , List < BranchCommit > > ( ) ;
22
21
semanticVersionTagsOnBranchCache = new Dictionary < Branch , List < SemanticVersion > > ( ) ;
23
- this . repository = repository ;
22
+ this . Repository = repository ;
24
23
}
25
24
26
- public IEnumerable < SemanticVersion > GetVersionTagsOnBranch ( Branch branch , IRepository repository , string tagPrefixRegex )
25
+ public IEnumerable < SemanticVersion > GetVersionTagsOnBranch ( Branch branch , string tagPrefixRegex )
27
26
{
28
27
if ( semanticVersionTagsOnBranchCache . ContainsKey ( branch ) )
29
28
{
@@ -33,9 +32,9 @@ public IEnumerable<SemanticVersion> GetVersionTagsOnBranch(Branch branch, IRepos
33
32
34
33
using ( Logger . IndentLog ( string . Format ( "Getting version tags from branch '{0}'." , branch . CanonicalName ) ) )
35
34
{
36
- var tags = repository . Tags . Select ( t => t ) . ToList ( ) ;
35
+ var tags = this . Repository . Tags . Select ( t => t ) . ToList ( ) ;
37
36
38
- var versionTags = repository . Commits . QueryBy ( new CommitFilter
37
+ var versionTags = this . Repository . Commits . QueryBy ( new CommitFilter
39
38
{
40
39
IncludeReachableFrom = branch . Tip
41
40
} )
@@ -53,13 +52,13 @@ public IEnumerable<SemanticVersion> GetVersionTagsOnBranch(Branch branch, IRepos
53
52
}
54
53
55
54
// TODO Should we cache this?
56
- public IEnumerable < Branch > GetBranchesContainingCommit ( [ NotNull ] Commit commit , IRepository repository , IList < Branch > branches , bool onlyTrackedBranches )
55
+ public IEnumerable < Branch > GetBranchesContainingCommit ( [ NotNull ] Commit commit , IList < Branch > branches , bool onlyTrackedBranches )
57
56
{
58
57
if ( commit == null )
59
58
{
60
59
throw new ArgumentNullException ( "commit" ) ;
61
60
}
62
- Logger . WriteDebug ( "Heh" ) ;
61
+
63
62
using ( Logger . IndentLog ( string . Format ( "Getting branches containing the commit '{0}'." , commit . Id ) ) )
64
63
{
65
64
var directBranchHasBeenFound = false ;
@@ -87,7 +86,7 @@ public IEnumerable<Branch> GetBranchesContainingCommit([NotNull] Commit commit,
87
86
{
88
87
Logger . WriteInfo ( string . Format ( "Searching for commits reachable from '{0}'." , branch . FriendlyName ) ) ;
89
88
90
- var commits = repository . Commits . QueryBy ( new CommitFilter
89
+ var commits = this . Repository . Commits . QueryBy ( new CommitFilter
91
90
{
92
91
IncludeReachableFrom = branch
93
92
} ) . Where ( c => c . Sha == commit . Sha ) ;
@@ -107,7 +106,7 @@ public IEnumerable<Branch> GetBranchesContainingCommit([NotNull] Commit commit,
107
106
/// <summary>
108
107
/// Find the merge base of the two branches, i.e. the best common ancestor of the two branches' tips.
109
108
/// </summary>
110
- public Commit FindMergeBase ( Branch branch , Branch otherBranch , IRepository repository )
109
+ public Commit FindMergeBase ( Branch branch , Branch otherBranch )
111
110
{
112
111
var key = Tuple . Create ( branch , otherBranch ) ;
113
112
@@ -129,7 +128,7 @@ public Commit FindMergeBase(Branch branch, Branch otherBranch, IRepository repos
129
128
commitToFindCommonBase = otherBranch . Tip . Parents . First ( ) ;
130
129
}
131
130
132
- var findMergeBase = repository . ObjectDatabase . FindMergeBase ( commit , commitToFindCommonBase ) ;
131
+ var findMergeBase = this . Repository . ObjectDatabase . FindMergeBase ( commit , commitToFindCommonBase ) ;
133
132
if ( findMergeBase != null )
134
133
{
135
134
Logger . WriteInfo ( string . Format ( "Found merge base of {0}" , findMergeBase . Sha ) ) ;
@@ -145,7 +144,7 @@ public Commit FindMergeBase(Branch branch, Branch otherBranch, IRepository repos
145
144
if ( mergeBaseWasForwardMerge )
146
145
{
147
146
var second = commitToFindCommonBase . Parents . First ( ) ;
148
- var mergeBase = repository . ObjectDatabase . FindMergeBase ( commit , second ) ;
147
+ var mergeBase = this . Repository . ObjectDatabase . FindMergeBase ( commit , second ) ;
149
148
if ( mergeBase == findMergeBase )
150
149
{
151
150
break ;
@@ -157,7 +156,7 @@ public Commit FindMergeBase(Branch branch, Branch otherBranch, IRepository repos
157
156
}
158
157
159
158
// Store in cache.
160
- mergeBaseCache . Add ( key , new MergeBaseData ( branch , otherBranch , repository , findMergeBase ) ) ;
159
+ mergeBaseCache . Add ( key , new MergeBaseData ( branch , otherBranch , this . Repository , findMergeBase ) ) ;
161
160
162
161
return findMergeBase ;
163
162
}
@@ -167,7 +166,7 @@ public Commit FindMergeBase(Branch branch, Branch otherBranch, IRepository repos
167
166
/// Find the commit where the given branch was branched from another branch.
168
167
/// If there are multiple such commits and branches, returns the newest commit.
169
168
/// </summary>
170
- public BranchCommit FindCommitBranchWasBranchedFrom ( [ NotNull ] Branch branch , IRepository repository , params Branch [ ] excludedBranches )
169
+ public BranchCommit FindCommitBranchWasBranchedFrom ( [ NotNull ] Branch branch , params Branch [ ] excludedBranches )
171
170
{
172
171
if ( branch == null )
173
172
{
@@ -186,7 +185,6 @@ public BranchCommit FindCommitBranchWasBranchedFrom([NotNull] Branch branch, IRe
186
185
}
187
186
}
188
187
189
-
190
188
List < BranchCommit > GetMergeCommitsForBranch ( Branch branch )
191
189
{
192
190
if ( mergeBaseCommitsCache . ContainsKey ( branch ) )
@@ -197,15 +195,15 @@ List<BranchCommit> GetMergeCommitsForBranch(Branch branch)
197
195
return mergeBaseCommitsCache [ branch ] ;
198
196
}
199
197
200
- var branchMergeBases = repository . Branches . Select ( otherBranch =>
198
+ var branchMergeBases = Repository . Branches . Select ( otherBranch =>
201
199
{
202
200
if ( otherBranch . Tip == null )
203
201
{
204
202
Logger . WriteWarning ( string . Format ( missingTipFormat , otherBranch . FriendlyName ) ) ;
205
203
return BranchCommit . Empty ;
206
204
}
207
205
208
- var findMergeBase = FindMergeBase ( branch , otherBranch , repository ) ;
206
+ var findMergeBase = FindMergeBase ( branch , otherBranch ) ;
209
207
return new BranchCommit ( findMergeBase , otherBranch ) ;
210
208
} ) . Where ( b => b . Commit != null ) . OrderByDescending ( b => b . Commit . Committer . When ) . ToList ( ) ;
211
209
mergeBaseCommitsCache . Add ( branch , branchMergeBases ) ;
0 commit comments