6
6
namespace LibGit2Sharp
7
7
{
8
8
/// <summary>
9
- /// Representation of a git packbuilder .
9
+ /// Representation of a git PackBuilder .
10
10
/// </summary>
11
11
public sealed class PackBuilder : IDisposable
12
12
{
13
13
private readonly PackBuilderSafeHandle packBuilderHandle ;
14
14
private readonly Repository repo ;
15
15
16
16
/// <summary>
17
- /// Constructs a packbuilder from a repository .
17
+ /// Constructs a PackBuilder for a <see cref="Repository"/> .
18
18
/// </summary>
19
19
internal PackBuilder ( Repository repository )
20
20
{
@@ -25,81 +25,102 @@ internal PackBuilder(Repository repository)
25
25
}
26
26
27
27
/// <summary>
28
- /// Inserts a single object to the packbuilder .
28
+ /// Inserts a single <see cref="GitObject"/> to the PackBuilder .
29
29
/// For an optimal pack it's mandatory to insert objects in recency order, commits followed by trees and blobs. (quoted from libgit2 API ref)
30
30
/// </summary>
31
- /// <param name="gitObjectID">The object ID to be inserted.</param>
32
- public void Add ( ObjectId gitObjectID )
31
+ /// <param name="gitObject">The object to be inserted.</param>
32
+ /// <exception cref="ArgumentNullException">if the gitObject is null</exception>
33
+ public void Add < T > ( T gitObject ) where T : GitObject
33
34
{
34
- Ensure . ArgumentNotNull ( gitObjectID , "gitObject" ) ;
35
+ Ensure . ArgumentNotNull ( gitObject , "gitObject" ) ;
35
36
36
- Proxy . git_packbuilder_insert ( packBuilderHandle , gitObjectID , null ) ;
37
+ Add ( gitObject . Id ) ;
37
38
}
38
39
39
40
/// <summary>
40
- /// Recursively insert an object and its referenced objects. Inserts the object as well as any object it references.
41
+ /// Recursively inserts a <see cref="GitObject"/> and its referenced objects.
42
+ /// Inserts the object as well as any object it references.
41
43
/// </summary>
42
- /// <param name="gitObjectID">The object ID to be recursively inserted.</param>
43
- public void AddRecursively ( ObjectId gitObjectID )
44
+ /// <param name="gitObject">The object to be inserted recursively.</param>
45
+ /// <exception cref="ArgumentNullException">if the gitObject is null</exception>
46
+ public void AddRecursively < T > ( T gitObject ) where T : GitObject
44
47
{
45
- Ensure . ArgumentNotNull ( gitObjectID , "gitObject" ) ;
48
+ Ensure . ArgumentNotNull ( gitObject , "gitObject" ) ;
46
49
47
- Proxy . git_packbuilder_insert_recur ( packBuilderHandle , gitObjectID , null ) ;
50
+ AddRecursively ( gitObject . Id ) ;
48
51
}
49
52
50
53
/// <summary>
51
- /// Writes the new pack file and corresponding index file to path.
54
+ /// Inserts a single object to the PackBuilder by its <see cref="ObjectId"/>.
55
+ /// For an optimal pack it's mandatory to insert objects in recency order, commits followed by trees and blobs. (quoted from libgit2 API ref)
52
56
/// </summary>
53
- /// <param name="path">The path that pack and index files will be written to it.</param>
54
- internal void Write ( string path )
57
+ /// <param name="id">The object ID to be inserted.</param>
58
+ /// <exception cref="ArgumentNullException">if the id is null</exception>
59
+ public void Add ( ObjectId id )
55
60
{
56
- Proxy . git_packbuilder_write ( packBuilderHandle , path ) ;
61
+ Ensure . ArgumentNotNull ( id , "id" ) ;
62
+
63
+ Proxy . git_packbuilder_insert ( packBuilderHandle , id , null ) ;
57
64
}
58
65
59
66
/// <summary>
60
- /// Disposes the packbuilder object.
67
+ /// Recursively inserts an object and its referenced objects by its <see cref="ObjectId"/>.
68
+ /// Inserts the object as well as any object it references.
69
+ /// </summary>
70
+ /// <param name="id">The object ID to be recursively inserted.</param>
71
+ /// <exception cref="ArgumentNullException">if the id is null</exception>
72
+ public void AddRecursively ( ObjectId id )
73
+ {
74
+ Ensure . ArgumentNotNull ( id , "id" ) ;
75
+
76
+ Proxy . git_packbuilder_insert_recur ( packBuilderHandle , id , null ) ;
77
+ }
78
+
79
+ /// <summary>
80
+ /// Disposes the PackBuilder object.
61
81
/// </summary>
62
82
public void Dispose ( )
63
83
{
64
84
packBuilderHandle . SafeDispose ( ) ;
65
85
}
66
86
87
+ /// <summary>
88
+ /// Writes the pack file and corresponding index file to path.
89
+ /// </summary>
90
+ /// <param name="path">The path that pack and index files will be written to it.</param>
91
+ internal void Write ( string path )
92
+ {
93
+ Proxy . git_packbuilder_write ( packBuilderHandle , path ) ;
94
+ }
95
+
67
96
/// <summary>
68
97
/// Sets number of threads to spawn.
69
98
/// </summary>
70
99
/// <returns> Returns the number of actual threads to be used.</returns>
71
- /// <param name="nThread">The Number of threads to spawn. An argument of 0 enusures using all available CPUs</param>
100
+ /// <param name="nThread">The Number of threads to spawn. An argument of 0 ensures using all available CPUs</param>
72
101
internal int SetMaximumNumberOfThreads ( int nThread )
73
102
{
74
103
// Libgit2 set the number of threads to 1 by default, 0 ensures git_online_cpus
75
104
return ( int ) Proxy . git_packbuilder_set_threads ( packBuilderHandle , ( uint ) nThread ) ;
76
105
}
77
106
78
107
/// <summary>
79
- /// Get the total number of objects the packbuilder will write out.
108
+ /// Number of objects the PackBuilder will write out.
80
109
/// </summary>
81
110
internal long ObjectsCount
82
111
{
83
112
get { return Proxy . git_packbuilder_object_count ( packBuilderHandle ) ; }
84
113
}
85
114
86
115
/// <summary>
87
- /// Number of objects the packbuilder has already written out.
88
- /// This is only correct after the packfile has been written.
116
+ /// Number of objects the PackBuilder has already written out.
117
+ /// This is only correct after the pack file has been written.
89
118
/// </summary>
90
119
internal long WrittenObjectsCount
91
120
{
92
121
get { return Proxy . git_packbuilder_written ( packBuilderHandle ) ; }
93
122
}
94
123
95
- /// <summary>
96
- /// A refernce to the repository that the packbuilder is working on.
97
- /// </summary>
98
- public Repository Repository
99
- {
100
- get { return repo ; }
101
- }
102
-
103
124
internal PackBuilderSafeHandle Handle
104
125
{
105
126
get { return packBuilderHandle ; }
@@ -112,7 +133,7 @@ internal PackBuilderSafeHandle Handle
112
133
public struct PackBuilderResults
113
134
{
114
135
/// <summary>
115
- /// Number of objects the packbuilder has already written out.
136
+ /// Number of objects the PackBuilder has already written out.
116
137
/// </summary>
117
138
public long WrittenObjectsCount { get ; internal set ; }
118
139
}
@@ -129,7 +150,7 @@ public sealed class PackBuilderOptions
129
150
/// The default value for maximum number of threads to spawn is 0 which ensures using all available CPUs.
130
151
/// <exception cref="ArgumentNullException">if packDirectory is null or empty</exception>
131
152
/// <exception cref="DirectoryNotFoundException">if packDirectory doesn't exist</exception>
132
- public PackBuilderOptions ( string packDirectory )
153
+ public PackBuilderOptions ( string packDirectory )
133
154
{
134
155
PackDirectoryPath = packDirectory ;
135
156
MaximumNumberOfThreads = 0 ;
@@ -176,7 +197,7 @@ public int MaximumNumberOfThreads
176
197
{
177
198
return nThreads ;
178
199
}
179
-
200
+
180
201
}
181
202
182
203
private string path ;
0 commit comments