@@ -7,22 +7,15 @@ import { logger, setupLogging } from "../logger.ts"
77import { PromiseQueue } from "./queue.ts"
88import { checkKey , storeKey } from "./transferKey.ts"
99import ProgressBar from "@deno-library/progress"
10- import { annexAdd , hashDirLower , readAnnexPath } from "./annex.ts"
10+ import type { AnnexKeyPaths } from "./annex.ts"
11+ import { annexAdd , getAnnexKeys , hashDirLower , readAnnexPath } from "./annex.ts"
1112import { GitWorkerContext } from "./types/git-context.ts"
1213import { resetWorktree } from "./resetWorktree.ts"
1314import { getDefault } from "./getDefault.ts"
1415
1516let context : GitWorkerContext
1617let attributesCache : GitAnnexAttributes
1718
18- /**
19- * Paths to upload to the remote annex
20- *
21- * Keys are the annex key
22- * Values are repo relative path
23- */
24- const annexKeys : Record < string , string > = { }
25-
2619async function done ( ) {
2720 logger . info ( "Git worker shutdown." )
2821 // @ts -ignore
@@ -163,7 +156,6 @@ async function add(event: GitWorkerEventAdd) {
163156 } else {
164157 if (
165158 await annexAdd (
166- annexKeys ,
167159 annexed ,
168160 event . data . path ,
169161 event . data . relativePath ,
@@ -214,14 +206,13 @@ async function createAnnexBranch() {
214206 * Generate a commit for remote.log updates if needed
215207 */
216208async function remoteSetup ( ) {
217- const noAnnexKeys : Record < string , string > = { }
218- await commitAnnexBranch ( noAnnexKeys )
209+ await commitAnnexBranch ( )
219210}
220211
221212/**
222213 * Generate one commit for all pending git-annex branch changes
223214 */
224- async function commitAnnexBranch ( annexKeys : Record < string , string > ) {
215+ async function commitAnnexBranch ( ) {
225216 // Find the UUID of this repository if it exists already
226217 const expectedRemote = "OpenNeuro" // TODO - This could be more flexible?
227218 let uuid
@@ -280,6 +271,7 @@ async function commitAnnexBranch(annexKeys: Record<string, string>) {
280271 }
281272 }
282273 // Add logs for each annexed file
274+ const annexKeys = await getAnnexKeys ( "HEAD" , logger , context )
283275 for ( const [ key , _path ] of Object . entries ( annexKeys ) ) {
284276 const hashDir = join ( ...await hashDirLower ( key ) )
285277 const annexBranchPath = join ( hashDir , `${ key } .log` )
@@ -379,7 +371,7 @@ async function commit() {
379371 author : context . author ,
380372 message : "[OpenNeuro] Added local files" ,
381373 } )
382- await commitAnnexBranch ( annexKeys )
374+ await commitAnnexBranch ( )
383375 logger . info ( `Committed as "${ commitHash } "` )
384376 }
385377}
@@ -389,6 +381,7 @@ async function commit() {
389381 */
390382async function push ( ) {
391383 let completed = 0
384+ const annexKeys : AnnexKeyPaths = await getAnnexKeys ( "HEAD" , logger , context )
392385 const annexedObjects = Object . keys ( annexKeys ) . length
393386 const progress = new ProgressBar ( {
394387 title : `Transferring annexed files` ,
@@ -398,13 +391,15 @@ async function push() {
398391 await progress . render ( completed )
399392 }
400393 // Git-annex copy --to=openneuro
401- for ( const [ key , path ] of Object . entries ( annexKeys ) ) {
394+ for ( const [ key , relativePath ] of Object . entries ( annexKeys ) ) {
402395 const checkKeyResult = await checkKey ( {
403396 url : context . repoEndpoint ,
404397 token : context . authorization ,
405398 } , key )
406399 if ( checkKeyResult ) {
407400 logger . info ( `Skipping key "${ key } " present on remote` )
401+ completed += 1
402+ await progress . render ( completed )
408403 } else {
409404 let storeKeyResult = - 1
410405 let retries = 3
@@ -416,7 +411,7 @@ async function push() {
416411 token : context . authorization ,
417412 } ,
418413 key ,
419- path ,
414+ join ( context . sourcePath , relativePath ) ,
420415 )
421416 if ( storeKeyResult === - 1 && retries > 0 ) {
422417 logger . warn ( `Failed to transfer annex object "${ key } " - retrying` )
@@ -430,7 +425,7 @@ async function push() {
430425 completed += 1
431426 await progress . render ( completed )
432427 logger . info (
433- `Stored ${ storeKeyResult } bytes for key "${ key } " from path "${ path } "` ,
428+ `Stored ${ storeKeyResult } bytes for key "${ key } " from path "${ relativePath } "` ,
434429 )
435430 }
436431 }
0 commit comments