Skip to content

Commit cd8aca7

Browse files
committed
Make previous flow recreation faster
1 parent b2e086d commit cd8aca7

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrBackflower.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,35 @@ private NativePath GetPatchName(SourceMapping mapping, LastFlows lastFlows, Code
505505
LastFlows previousFlows,
506506
string branchToCreate,
507507
string targetBranch,
508+
(Codeflow PreviousFlow, LastFlows LastFlows)? lastRewind,
508509
CancellationToken cancellationToken)
509510
{
510-
await targetRepo.ResetWorkingTree();
511-
await targetRepo.ForceCheckoutAsync(targetBranch);
511+
Backflow previousFlow;
512+
513+
int i = 1;
514+
if (lastRewind.HasValue)
515+
{
516+
i = depth - 1;
517+
previousFlow = (Backflow)lastRewind.Value.PreviousFlow;
518+
previousFlows = lastRewind.Value.LastFlows;
512519

513-
Backflow previousFlow = previousFlows.LastBackFlow
514-
?? throw new DarcException("No more backflows found to recreate");
520+
await targetRepo.ForceCheckoutAsync(previousFlow.RepoSha);
521+
await _vmrCloneManager.PrepareVmrAsync(
522+
[_vmrInfo.VmrUri],
523+
[previousFlow.VmrSha],
524+
previousFlow.VmrSha,
525+
resetToRemote: false,
526+
cancellationToken);
527+
}
528+
else
529+
{
530+
previousFlow = previousFlows.LastBackFlow
531+
?? throw new DarcException("No more backflows found to recreate");
532+
await targetRepo.ResetWorkingTree();
533+
await targetRepo.ForceCheckoutAsync(targetBranch);
534+
}
515535

516-
for (int i = 1; i < depth; i++)
536+
while (i++ < depth)
517537
{
518538
var previousFlowSha = await _localGitClient.BlameLineAsync(
519539
targetRepo.Path / VersionFiles.VersionDetailsXml,

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrCodeflower.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,20 +401,26 @@ private async Task<CodeFlowResult> RecreatePreviousFlowsAndApplyChanges(
401401
AzureDevOpsRepository = codeflowOptions.Build.AzureDevOpsRepository
402402
};
403403

404+
Codeflow? previousFlow = null;
405+
LastFlows? previousFlows = null;
406+
404407
// We recursively try to re-create previous flows until we find the one that introduced the conflict with the current flown
405408
int flowsToRecreate = 1;
406409
while (flowsToRecreate < 50)
407410
{
408411
_logger.LogInformation("Trying to recreate {count} previous flow(s)..", flowsToRecreate);
409412

410413
// We rewing to the previous flow and create a branch there
411-
(Codeflow previousFlow, LastFlows previousFlows) = await RewindToPreviousFlowAsync(
414+
(previousFlow, previousFlows) = await RewindToPreviousFlowAsync(
412415
codeflowOptions.Mapping,
413416
repo,
414417
flowsToRecreate,
415418
lastFlows,
416419
codeflowOptions.HeadBranch,
417420
codeflowOptions.TargetBranch,
421+
previousFlow != null && previousFlows != null
422+
? (previousFlow, previousFlows)
423+
: null,
418424
cancellationToken);
419425

420426
// We store the SHA where the head branch originates from so that later we can diff it
@@ -430,8 +436,8 @@ codeflowOptions with
430436
{
431437
Build = previouslyAppliedBuild,
432438
CurrentFlow = currentIsBackflow
433-
? new Backflow(previouslyAppliedBuild.Commit, previousFlow.RepoSha)
434-
: new ForwardFlow(previouslyAppliedBuild.Commit, previousFlow.VmrSha),
439+
? new Backflow(previouslyAppliedBuild.Commit, previousFlow!.RepoSha)
440+
: new ForwardFlow(previouslyAppliedBuild.Commit, previousFlow!.VmrSha),
435441
EnableRebase = false,
436442
ForceUpdate = true,
437443
},
@@ -498,6 +504,7 @@ await HandleRevertedFiles(
498504
LastFlows previousFlows,
499505
string branchToCreate,
500506
string targetBranch,
507+
(Codeflow PreviousFlow, LastFlows LastFlows)? lastRewind,
501508
CancellationToken cancellationToken);
502509

503510
/// <summary>

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrForwardFlower.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,35 @@ private async Task CommentIncludedPRs(
441441
LastFlows previousFlows,
442442
string branchToCreate,
443443
string targetBranch,
444+
(Codeflow PreviousFlow, LastFlows LastFlows)? lastRewind,
444445
CancellationToken cancellationToken)
445446
{
446-
var previousFlow = previousFlows.LastForwardFlow;
447447
var vmr = _localGitRepoFactory.Create(_vmrInfo.VmrPath);
448-
await vmr.ResetWorkingTree();
449-
await vmr.ForceCheckoutAsync(targetBranch);
450448

451-
for (int i = 1; i < depth; i++)
449+
ForwardFlow previousFlow;
450+
int i = 1;
451+
if (lastRewind.HasValue)
452+
{
453+
i = depth - 1;
454+
previousFlow = (ForwardFlow)lastRewind.Value.PreviousFlow;
455+
previousFlows = lastRewind.Value.LastFlows;
456+
await _vmrCloneManager.PrepareVmrAsync(
457+
[_vmrInfo.VmrUri],
458+
[previousFlow.VmrSha],
459+
previousFlow.VmrSha,
460+
resetToRemote: false,
461+
cancellationToken);
462+
463+
await sourceRepo.ForceCheckoutAsync(previousFlow.RepoSha);
464+
}
465+
else
466+
{
467+
previousFlow = previousFlows.LastForwardFlow;
468+
await vmr.ResetWorkingTree();
469+
await vmr.ForceCheckoutAsync(targetBranch);
470+
}
471+
472+
while (i++ < depth)
452473
{
453474
var previousFlowSha = await _localGitClient.BlameLineAsync(
454475
_vmrInfo.SourceManifestPath,

0 commit comments

Comments
 (0)