@@ -9,6 +9,8 @@ import shell from "shelljs";
99import GitHelper from "./lib/git.js" ;
1010import DGitHelper from "./lib/dgit.js" ;
1111import LineHelper from "./lib/line.js" ;
12+ import Arweave from "arweave" ;
13+ import { getRefsOnArweave } from "./lib/arweave.js" ;
1214
1315const _timeout = async ( duration ) => {
1416 return new Promise ( ( resolve , reject ) => {
@@ -58,17 +60,20 @@ export default class Helper {
5860 // OK
5961 async initialize ( ) {
6062 // create dirs
61- fs . ensureDirSync ( path . join ( this . path , "refs" , "remotes" , this . name ) ) ;
62- fs . ensureDirSync ( path . join ( this . path , "dgit" , "refs" ) ) ;
63- // load db
64- this . _db = Level ( path . join ( this . path , "dgit" , "refs" , this . address ) ) ;
63+ // fs.ensureDirSync(path.join(this.path, "refs", "remotes", this.name));
64+ // fs.ensureDirSync(path.join(this.path, "dgit", "refs"));
65+ this . _arweave = Arweave . init ( {
66+ host : "arweave.net" ,
67+ port : 443 ,
68+ protocol : "https" ,
69+ } ) ;
6570 }
6671
6772 // OK
6873 async run ( ) {
6974 while ( true ) {
7075 const cmd = await this . line . next ( ) ;
71- console . log ( cmd ) ;
76+
7277 switch ( this . _cmd ( cmd ) ) {
7378 case "capabilities" :
7479 await this . _handleCapabilities ( ) ;
@@ -77,7 +82,7 @@ export default class Helper {
7782 await this . _handleList ( { forPush : true } ) ;
7883 break ;
7984 case "list" :
80- await this . _handleList ( ) ;
85+ await this . _handleList ( { } ) ;
8186 break ;
8287 case "fetch" :
8388 await this . _handleFetch ( cmd ) ;
@@ -112,7 +117,7 @@ export default class Helper {
112117
113118 // tslint:disable-next-line:forin
114119 for ( const ref in refs ) {
115- this . _send ( this . dgit . cidToSha ( refs [ ref ] ) + " " + ref ) ;
120+ this . _send ( refs [ ref ] + " " + ref ) ;
116121 }
117122
118123 // force HEAD to master and update once dgit handle symbolic refs
@@ -160,61 +165,29 @@ export default class Helper {
160165
161166 // OK
162167 async _fetchRefs ( ) {
163- this . debug ( "fetching remote refs from chain " ) ;
168+ this . debug ( "fetching remote refs from arweave " ) ;
164169
165170 let start ;
166171 let block ;
167172 let events ;
168173 const ops = [ ] ;
169- const updates = { } ;
170- const spinner = ora (
171- "Fetching remote refs from chain [this may take a while]"
172- ) . start ( ) ;
174+ const spinner = ora ( "Fetching remote refs from arweave" ) . start ( ) ;
173175
174176 try {
175- start = await this . _db . get ( "@block" ) ;
176- } catch ( err ) {
177- if ( err . message === "Key not found in database [@block]" ) {
178- start = 0 ;
179- } else {
180- throw err ;
181- }
182- }
183-
184- try {
185- // get refs from dgit node
186- // events = await this._repo.contract.getPastEvents("UpdateRef", {
187- // fromBlock: start,
188- // toBlock: "latest",
189- // });
190- events = [ { ref : "" , hash : "" } ] ;
191-
192- for ( const event of events ) {
193- updates [ event . ref ] = event . hash ;
194- }
195-
196- // tslint:disable-next-line:forin
197- for ( const ref in updates ) {
198- ops . push ( { type : "put" , key : ref , value : updates [ ref ] } ) ;
199- }
200-
201- ops . push ( { type : "put" , key : "@block" , value : block } ) ;
177+ const refs = await getRefsOnArweave ( this . _arweave , this . url ) ;
202178
203- await this . _db . batch ( ops ) ;
179+ spinner . succeed ( "Remote refs fetched from arweave" ) ;
204180
205- spinner . succeed ( "Remote refs fetched from chain" ) ;
206-
207- return this . _getRefs ( ) ;
181+ return Object . fromEntries ( refs ) ;
208182 } catch ( err ) {
209- spinner . fail ( "Failed to fetch remote refs from chain " ) ;
183+ spinner . fail ( "Failed to fetch remote refs from arweave " ) ;
210184 throw err ;
211185 }
212186 }
213187
214188 // OK
215189 async _getRefs ( ) {
216190 this . debug ( "reading refs from local db" ) ;
217-
218191 const refs = { } ;
219192
220193 return new ( ( resolve , reject ) => {
@@ -256,21 +229,23 @@ export default class Helper {
256229 const pins = [ ] ;
257230
258231 try {
259- const refs = await this . _getRefs ( ) ;
232+ const refs = await this . _fetchRefs ( ) ;
260233 const remote = refs [ dst ] ;
261234
262235 const srcBranch = src . split ( "/" ) . pop ( ) ;
263236 const dstBranch = dst . split ( "/" ) . pop ( ) ;
264237
265238 const revListCmd = remote
266- ? `git rev-list --left-only ${ srcBranch } ...${ this . name } /${ dstBranch } `
267- : "git rev-list --all" ;
239+ ? `git rev-list --objects -- left-only ${ srcBranch } ...${ this . name } /${ dstBranch } `
240+ : "git rev-list --objects -- all" ;
268241
269242 const commits = shell
270243 . exec ( revListCmd , { silent : true } )
271- . stdout . split ( "\n" )
272- . slice ( 0 , - 1 ) ;
244+ . stdout . split ( "\n" ) ;
273245
246+ // .slice(0, -1);
247+ this . debug ( commits ) ;
248+ this . _die ( ) ;
274249 // checking permissions
275250 try {
276251 spinner = ora ( `Checking permissions over ${ this . address } ` ) . start ( ) ;
@@ -313,7 +288,7 @@ export default class Helper {
313288 mapping = { ...mapping , ..._mapping } ;
314289 }
315290
316- head = this . dgit . shaToCid ( commits [ 0 ] ) ;
291+ head = commits [ 0 ] ;
317292
318293 // tslint:disable-next-line:forin
319294 for ( const entry in mapping ) {
@@ -336,20 +311,6 @@ export default class Helper {
336311 this . _die ( ) ;
337312 }
338313
339- // pin git objects
340- try {
341- // tslint:disable-next-line:forin
342- for ( const entry in mapping ) {
343- pins . push ( this . dgit . pin ( entry ) ) ;
344- }
345- spinner = ora ( "Pinning git objects to IPFS" ) . start ( ) ;
346- await Promise . all ( pins ) ;
347- spinner . succeed ( "Git objects pinned to IPFS" ) ;
348- } catch ( err ) {
349- spinner . fail ( "Failed to pin git objects to IPFS: " + err . message ) ;
350- this . _die ( ) ;
351- }
352-
353314 // register on chain
354315 try {
355316 spinner = ora ( `Registering ref ${ dst } ${ head } on-chain` ) . start ( ) ;
@@ -390,7 +351,6 @@ export default class Helper {
390351
391352 // OK
392353 _cmd ( line ) {
393- console . log ( line ) ;
394354 if ( line === "capabilities" ) {
395355 return "capabilities" ;
396356 } else if ( line === "list for-push" ) {
0 commit comments