Process commits in reverse

andybalholm
Mar 11, 2023, 10:27 PM
K23EJ6EJBFYC73TX5MMV7ZMI2GXVQJT6OQCGV56MXPQN4BLOQZ5AC

Dependencies

  • [2] 5ETDKF5F Start on data structures to represent fast-export stream
  • [3] KZ4XMKSP Make a temporary clone of the repository
  • [4] RTQQLOCO Use real metadata, but no content yet
  • [*] Y7VFVY6E Initial dummy version

Change contents

  • replacement in main.go at line 75
    [3.1001][3.1001:1101]()
    for changeIndex := len(changes) - 1; changeIndex >= 0; changeIndex-- {
    c := changes[changeIndex]
    [3.1001]
    [3.1101]
    stream := new(FastExportStream)
    for changeIndex, c := range changes {
  • edit in main.go at line 84
    [2.20][2.20:47]()
    commit.Mark = nextMark()
  • replacement in main.go at line 99
    [2.138][2.138:241](),[2.241][3.1622:1626](),[3.1622][3.1622:1626]()
    if err := commit.WriteTo(os.Stdout); err != nil {
    printErrorAndExit("Error writing commit:", err)
    }
    [2.138]
    [3.1167]
    stream.AddCommit(commit)
    }
    stream.ReverseCommits()
    if err := stream.WriteTo(os.Stdout); err != nil {
    printErrorAndExit("Error writing output stream:", err)
  • edit in fast-export.go at line 36
    [2.986]
    [2.986]
    }
    return nil
    }
    // A FastExportStream is an in-memory representation of a fast-export stream.
    type FastExportStream struct {
    Commits []Commit
    marks int
    }
    func (f *FastExportStream) AddCommit(c Commit) {
    if c.Mark == 0 {
    f.marks++
    c.Mark = f.marks
    }
    f.Commits = append(f.Commits, c)
    }
    func (f *FastExportStream) ReverseCommits() {
    for i, j := 0, len(f.Commits)-1; j > i; i, j = i+1, j-1 {
    f.Commits[i], f.Commits[j] = f.Commits[j], f.Commits[i]
  • edit in fast-export.go at line 59
    [2.989]
    [2.989]
    }
    func (f *FastExportStream) WriteTo(w io.Writer) error {
    for _, c := range f.Commits {
    if err := c.WriteTo(w); err != nil {
    return err
    }
    }