@@ -4,9 +4,8 @@ import npath from "path";
44import shell from "shelljs" ;
55// tslint:disable-next-line:no-submodule-imports
66import gitP from "simple-git/promise.js" ;
7- import pkg from "smart-buffer" ;
8- const { SmartBuffer } = pkg ;
9- import zlib from "zlib" ;
7+
8+ import { fetchGitObject } from "./arweave.js" ;
109
1110const git = gitP ( ) ;
1211
@@ -20,36 +19,8 @@ export default class GitHelper {
2019 /***** core methods *****/
2120
2221 // OK
23- async collect ( oid , mapping ) {
22+ async collect ( oid ) {
2423 this . debug ( "collecting" , oid ) ;
25-
26- if ( mapping [ oid ] ) return mapping ;
27-
28- const node = await this . load ( oid ) ;
29-
30- if ( node . gitType === "commit" ) {
31- // node is a commit
32- const _mapping = await this . collect (
33- this . helper . ipld . cidToSha ( node . tree [ "/" ] ) ,
34- mapping
35- ) ;
36- return { ...mapping , ..._mapping , ...{ [ cid ] : node } } ;
37- } else if ( Buffer . isBuffer ( node ) ) {
38- // node is a blob
39- return { ...mapping , ...{ [ cid ] : node } } ;
40- } else {
41- // node is a tree
42- // tslint:disable-next-line:forin
43- for ( const entry in node ) {
44- const _mapping = await this . collect (
45- this . helper . ipld . cidToSha ( node [ entry ] . hash [ "/" ] ) ,
46- mapping
47- ) ;
48- mapping = { ...mapping , ..._mapping } ;
49- }
50-
51- return { ...mapping , ...{ [ cid ] : node } } ;
52- }
5324 }
5425
5526 // OK
@@ -58,32 +29,16 @@ export default class GitHelper {
5829
5930 if ( await this . exists ( oid ) ) return ;
6031
61- // const cid = this.helper.ipld.shaToCid(oid);
62- // const node = await this.helper.ipld.get(cid);
63-
64- // if (node.gitType === "commit") {
65- // // node is a commit
66- // await this.download(this.helper.ipld.cidToSha(node.tree["/"]));
67-
68- // for (const parent of node.parents) {
69- // await this.download(this.helper.ipld.cidToSha(parent["/"]));
70- // }
71-
72- // await this.dump(oid, node);
73- // } else if (Buffer.isBuffer(node)) {
74- // // node is a blob
75- // await this.dump(oid, node);
76- // } else {
77- // // node is a tree
78- // // tslint:disable-next-line:forin
79- // for (const entry in node) {
80- // await this.download(
81- // await this.helper.ipld.cidToSha(node[entry].hash["/"])
82- // );
83- // }
84-
85- // await this.dump(oid, node);
86- // }
32+ const object = await fetchGitObject (
33+ this . helper . _arweave ,
34+ this . helper . url ,
35+ oid
36+ ) ;
37+
38+ await this . dump ( oid , object ) ;
39+
40+ // if commit expand the tree
41+ console . error ( git . catFile ( [ oid ] ) ) ;
8742 }
8843
8944 /***** fs-related methods *****/
@@ -97,29 +52,16 @@ export default class GitHelper {
9752
9853 // OK
9954 async load ( oid ) {
100- const type = shell
101- . exec ( `git cat-file -t ${ oid } ` , { silent : true } )
102- . stdout . trim ( ) ;
103- const size = shell
104- . exec ( `git cat-file -s ${ oid } ` , { silent : true } )
105- . stdout . trim ( ) ;
106- const data = await git . binaryCatFile ( [ type , oid ] ) ;
107-
108- const raw = new SmartBuffer ( ) ;
109- raw . writeString ( `${ type } ` ) ;
110- raw . writeString ( size ) ;
111- raw . writeUInt8 ( 0 ) ;
112- raw . writeBuffer ( data ) ;
113-
114- return this . helper . ipld . deserialize ( raw . toBuffer ( ) ) ;
55+ const path = await this . path ( oid ) ;
56+ await fs . ensureFile ( path ) ;
57+ return fs . readFileSync ( path ) ;
11558 }
11659
11760 // OK
118- async dump ( oid , node ) {
61+ async dump ( oid , object ) {
11962 const path = await this . path ( oid ) ;
120- const buffer = await this . helper . ipld . serialize ( node ) ;
12163 await fs . ensureFile ( path ) ;
122- fs . writeFileSync ( path , zlib . deflateSync ( buffer ) ) ;
64+ fs . writeFileSync ( path , object ) ;
12365 }
12466
12567 /***** utility methods *****/
0 commit comments