this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/cuetxtar: simplify ordering

Instead of reconstructing the order, now simply
mark the order of new files to be that of files
they are related too. This simplifies the code
and actually results in a more precise ordering.

Note that since we add new files first, derivative files will be added before their
related files. This mimics the behavior we
had so far.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I97553dcc7ebfb984bdef22a1b1925fbd0e866b1d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199804
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>

+12 -28
+12 -28
internal/cuetxtar/txtar.go
··· 20 20 "fmt" 21 21 "io" 22 22 "io/fs" 23 + "maps" 23 24 "os" 24 25 "path" 25 26 "path/filepath" ··· 418 419 t.Fatalf("error parsing txtar file: %v", err) 419 420 } 420 421 421 - // Record ordering of files in the archive to preserve that ordering 422 - // later. 423 - ordering := map[string]int{} 424 - for i, f := range a.Files { 425 - ordering[f.Name] = i 426 - } 427 - 428 422 tc := &Test{ 429 423 T: t, 430 424 Archive: a, ··· 487 481 index[f.Name] = i 488 482 } 489 483 484 + // Record ordering of files in the archive to preserve that ordering 485 + // later. 486 + ordering := maps.Clone(index) 487 + 490 488 // Add diff files between fallback and main file. These are added 491 489 // as regular output files so that they can be updated as well. 492 490 for _, sub := range tc.outFiles { ··· 494 492 continue 495 493 } 496 494 if j, ok := index[sub.fallback]; ok { 495 + if _, ok := ordering[sub.name]; !ok { 496 + ordering[sub.name] = j 497 + } 497 498 fallback := a.Files[j].Data 498 499 499 500 result := sub.buf.Bytes() ··· 502 503 } 503 504 504 505 diffName := "diff/-" + sub.name + "<==>+" + sub.fallback 506 + if _, ok := ordering[diffName]; !ok { 507 + ordering[diffName] = j 508 + } 505 509 switch diff := diff.Diff("old", fallback, "new", result); { 506 510 case len(diff) > 0: 507 511 tc.outFiles = append(tc.outFiles, file{ ··· 540 544 } 541 545 } 542 546 543 - // Insert results of this test at first location of any existing 544 - // test or at end of list otherwise. 545 - k := len(a.Files) 546 - for _, sub := range tc.outFiles { 547 - if i, ok := index[sub.name]; ok { 548 - k = i 549 - break 550 - } 551 - if i, ok := index[sub.fallback]; ok { 552 - k = i 553 - break 554 - } 555 - } 556 - 557 - // Filter files up to k from the original list. 558 547 files := make([]txtar.File, 0, len(a.Files)) 559 - for _, f := range a.Files[:k] { 560 - if _, ok := index[f.Name]; ok { 561 - files = append(files, f) 562 - } 563 - } 564 548 565 549 for _, sub := range tc.outFiles { 566 550 result := sub.buf.Bytes() ··· 607 591 608 592 // Add remaining unrelated files, ignoring files that were already 609 593 // added. 610 - for _, f := range a.Files[k:] { 594 + for _, f := range a.Files { 611 595 if _, ok := index[f.Name]; ok { 612 596 files = append(files, f) 613 597 }