@@ -3,7 +3,14 @@ import zlib from 'zlib';
3
3
import fs from 'fs' ;
4
4
import path from 'path' ;
5
5
import lod from 'lodash' ;
6
- import { CommitContent , CommitHeader , PersonLine } from '../types' ;
6
+
7
+ import {
8
+ CommitContent ,
9
+ CommitData ,
10
+ CommitHeader ,
11
+ PackMeta ,
12
+ PersonLine ,
13
+ } from '../types' ;
7
14
import {
8
15
BRANCH_PREFIX ,
9
16
EMPTY_COMMIT_HASH ,
@@ -122,7 +129,7 @@ const parsePersonLine = (line: string): PersonLine => {
122
129
* @param {string[] } headerLines - The header lines of a commit.
123
130
* @return {CommitHeader } An object containing the parsed commit header.
124
131
*/
125
- const getParsedData = ( headerLines : string [ ] ) => {
132
+ const getParsedData = ( headerLines : string [ ] ) : CommitHeader => {
126
133
const parsedData : CommitHeader = {
127
134
parents : [ ] ,
128
135
tree : '' ,
@@ -174,7 +181,7 @@ const getParsedData = (headerLines: string[]) => {
174
181
* @return {void }
175
182
* @throws {Error } If the commit header is invalid.
176
183
*/
177
- const validateParsedData = ( parsedData : CommitHeader ) => {
184
+ const validateParsedData = ( parsedData : CommitHeader ) : void => {
178
185
const missing = [ ] ;
179
186
if ( parsedData . tree === '' ) {
180
187
missing . push ( 'tree' ) ;
@@ -202,9 +209,9 @@ const isBlankPersonLine = (personLine: PersonLine): boolean => {
202
209
/**
203
210
* Parses the commit data from the contents of a pack file.
204
211
* @param {CommitContent[] } contents - The contents of the pack file.
205
- * @return {Array } An array of commit data objects.
212
+ * @return {CommitData[] } An array of commit data objects.
206
213
*/
207
- const getCommitData = ( contents : CommitContent [ ] ) => {
214
+ const getCommitData = ( contents : CommitContent [ ] ) : CommitData [ ] => {
208
215
console . log ( { contents } ) ;
209
216
return lod
210
217
. chain ( contents )
@@ -253,9 +260,9 @@ const getCommitData = (contents: CommitContent[]) => {
253
260
/**
254
261
* Gets the metadata from a pack file.
255
262
* @param {Buffer } buffer - The buffer containing the pack file data.
256
- * @return {Array } An array containing the metadata and the remaining buffer.
263
+ * @return {[PackMeta, Buffer] } An array containing the metadata and the remaining buffer.
257
264
*/
258
- const getPackMeta = ( buffer : Buffer ) => {
265
+ const getPackMeta = ( buffer : Buffer ) : [ PackMeta , Buffer ] => {
259
266
const sig = buffer . slice ( 0 , PACKET_SIZE ) . toString ( 'utf-8' ) ;
260
267
const version = buffer . readUIntBE ( PACKET_SIZE , PACKET_SIZE ) ;
261
268
const entries = buffer . readUIntBE ( PACKET_SIZE * 2 , PACKET_SIZE ) ;
@@ -273,9 +280,9 @@ const getPackMeta = (buffer: Buffer) => {
273
280
* Gets the contents of a pack file.
274
281
* @param {Buffer } buffer - The buffer containing the pack file data.
275
282
* @param {number } entries - The number of entries in the pack file.
276
- * @return {CommitContent[] } An array of commit content objects.
283
+ * @return {Array } An array of commit content objects.
277
284
*/
278
- const getContents = ( buffer : Buffer | CommitContent [ ] , entries : number ) => {
285
+ const getContents = ( buffer : Buffer | CommitContent [ ] , entries : number ) : CommitContent [ ] => {
279
286
const contents = [ ] ;
280
287
281
288
for ( let i = 0 ; i < entries ; i ++ ) {
@@ -295,7 +302,7 @@ const getContents = (buffer: Buffer | CommitContent[], entries: number) => {
295
302
* @param {boolean[] } bits - The array of bits.
296
303
* @return {number } The integer value.
297
304
*/
298
- const getInt = ( bits : boolean [ ] ) => {
305
+ const getInt = ( bits : boolean [ ] ) : number => {
299
306
let strBits = '' ;
300
307
301
308
// eslint-disable-next-line guard-for-in
@@ -312,7 +319,7 @@ const getInt = (bits: boolean[]) => {
312
319
* @param {Buffer } buffer - The buffer containing the pack file data.
313
320
* @return {Array } An array containing the content object and the next buffer.
314
321
*/
315
- const getContent = ( item : number , buffer : Buffer ) => {
322
+ const getContent = ( item : number , buffer : Buffer ) : [ CommitContent , Buffer ] => {
316
323
// FIRST byte contains the type and some of the size of the file
317
324
// a MORE flag -8th byte tells us if there is a subsequent byte
318
325
// which holds the file size
@@ -383,7 +390,7 @@ const getContent = (item: number, buffer: Buffer) => {
383
390
* @param {Buffer } buf - The buffer containing the zipped content.
384
391
* @return {Array } An array containing the unzipped content and the size of the deflated content.
385
392
*/
386
- const unpack = ( buf : Buffer ) => {
393
+ const unpack = ( buf : Buffer ) : [ string , number ] => {
387
394
// Unzip the content
388
395
const inflated = zlib . inflateSync ( buf ) ;
389
396
0 commit comments