@@ -28,7 +28,7 @@ import type { CheckpointStoreError } from "./Errors.ts";
2828import type { VcsCheckpointOps } from "../vcs/VcsDriver.ts" ;
2929import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts" ;
3030import * as WorkspaceRepositories from "../workspace/WorkspaceRepositories.ts" ;
31- import { prefixNumstatPaths , prefixPatchPaths } from "./Diffs.ts" ;
31+ import { parseTurnDiffFilesFromNumstat , prefixNumstatPaths , prefixPatchPaths } from "./Diffs.ts" ;
3232
3333export interface CaptureCheckpointInput {
3434 readonly cwd : string ;
@@ -261,22 +261,36 @@ export const make = Effect.gen(function* () {
261261 "CheckpointStore.diffCheckpoints" ,
262262 target . cwd ,
263263 ) ;
264- if ( target . pathPrefix !== null ) {
265- // A repository added to the workspace after either checkpoint has nothing to compare.
266- const comparable =
264+ if ( target . pathPrefix === null ) {
265+ return yield * checkpoints . diffCheckpoints ( { ...input , cwd : target . cwd } ) ;
266+ }
267+ // A repository added to the workspace after either checkpoint has nothing to compare.
268+ const comparable =
269+ ( yield * checkpoints . hasCheckpointRef ( {
270+ cwd : target . cwd ,
271+ checkpointRef : input . toCheckpointRef ,
272+ } ) ) &&
273+ ( input . fallbackFromToHead === true ||
267274 ( yield * checkpoints . hasCheckpointRef ( {
268275 cwd : target . cwd ,
269- checkpointRef : input . toCheckpointRef ,
270- } ) ) &&
271- ( input . fallbackFromToHead === true ||
272- ( yield * checkpoints . hasCheckpointRef ( {
273- cwd : target . cwd ,
274- checkpointRef : input . fromCheckpointRef ,
275- } ) ) ) ;
276- if ( ! comparable ) return "" ;
277- }
278- const diff = yield * checkpoints . diffCheckpoints ( { ...input , cwd : target . cwd } ) ;
279- if ( target . pathPrefix === null ) return diff ;
276+ checkpointRef : input . fromCheckpointRef ,
277+ } ) ) ) ;
278+ if ( ! comparable ) return "" ;
279+ // Requested paths are relative to the workspace folder.
280+ const repositoryPrefix = `${ target . pathPrefix } /` ;
281+ const diff = yield * checkpoints . diffCheckpoints ( {
282+ ...input ,
283+ cwd : target . cwd ,
284+ ...( input . filePaths
285+ ? {
286+ filePaths : input . filePaths . flatMap ( ( filePath ) =>
287+ filePath . startsWith ( repositoryPrefix )
288+ ? [ filePath . slice ( repositoryPrefix . length ) ]
289+ : [ ] ,
290+ ) ,
291+ }
292+ : { } ) ,
293+ } ) ;
280294 return input . format === "numstat"
281295 ? prefixNumstatPaths ( diff , target . pathPrefix )
282296 : prefixPatchPaths ( diff , target . pathPrefix ) ;
@@ -288,8 +302,63 @@ export const make = Effect.gen(function* () {
288302 const listAuthoredPaths : CheckpointStore [ "Service" ] [ "listAuthoredPaths" ] = Effect . fn (
289303 "listAuthoredPaths" ,
290304 ) ( function * ( input ) {
291- const checkpoints = yield * resolveCheckpoints ( "CheckpointStore.listAuthoredPaths" , input . cwd ) ;
292- return yield * checkpoints . listAuthoredPaths ( input ) ;
305+ const targets = yield * resolveTargets ( input . cwd ) ;
306+ if ( targets . length === 1 && targets [ 0 ] ! . pathPrefix === null ) {
307+ const checkpoints = yield * resolveCheckpoints ( "CheckpointStore.listAuthoredPaths" , input . cwd ) ;
308+ return yield * checkpoints . listAuthoredPaths ( input ) ;
309+ }
310+ const perRepository = yield * forEachTarget ( targets , ( target ) =>
311+ Effect . gen ( function * ( ) {
312+ const checkpoints = yield * resolveCheckpoints (
313+ "CheckpointStore.listAuthoredPaths" ,
314+ target . cwd ,
315+ ) ;
316+ // A repository without both checkpoints has no diff, so nothing of it is listed.
317+ const comparable =
318+ ( yield * checkpoints . hasCheckpointRef ( {
319+ cwd : target . cwd ,
320+ checkpointRef : input . fromCheckpointRef ,
321+ } ) ) &&
322+ ( yield * checkpoints . hasCheckpointRef ( {
323+ cwd : target . cwd ,
324+ checkpointRef : input . toCheckpointRef ,
325+ } ) ) ;
326+ if ( ! comparable ) return { target, paths : new Set < string > ( ) } ;
327+ return {
328+ target,
329+ paths : yield * checkpoints . listAuthoredPaths ( { ...input , cwd : target . cwd } ) ,
330+ } ;
331+ } ) ,
332+ ) ;
333+ if ( perRepository . every ( ( { paths } ) => paths === null ) ) return null ;
334+ // The result is one set for the workspace, so a repository whose HEAD did not move lists
335+ // every path it changed.
336+ const authored = new Set < string > ( ) ;
337+ for ( const { target, paths } of perRepository ) {
338+ let repositoryPaths : Iterable < string > | null = paths ;
339+ if ( repositoryPaths === null ) {
340+ const numstat = yield * resolveCheckpoints (
341+ "CheckpointStore.listAuthoredPaths" ,
342+ target . cwd ,
343+ ) . pipe (
344+ Effect . flatMap ( ( checkpoints ) =>
345+ checkpoints . diffCheckpoints ( {
346+ ...input ,
347+ cwd : target . cwd ,
348+ ignoreWhitespace : false ,
349+ format : "numstat" ,
350+ } ) ,
351+ ) ,
352+ ) ;
353+ repositoryPaths = parseTurnDiffFilesFromNumstat ( numstat ) . flatMap ( ( file ) =>
354+ file . previousPath === undefined ? [ file . path ] : [ file . path , file . previousPath ] ,
355+ ) ;
356+ }
357+ for ( const repositoryPath of repositoryPaths ) {
358+ authored . add ( `${ target . pathPrefix } /${ repositoryPath } ` ) ;
359+ }
360+ }
361+ return authored ;
293362 } ) ;
294363
295364 const deleteCheckpointRefs : CheckpointStore [ "Service" ] [ "deleteCheckpointRefs" ] = Effect . fn (
0 commit comments