Import and export marks

andybalholm
Mar 15, 2023, 5:46 PM
R7WB2ZZZMN4DUC7PGWRKW3QNWJQF4P6XDZIYLTBV4INJDHSBPZQQC

Dependencies

  • [2] OLMQ7EVU Add --branch flag
  • [3] YBAXM44P Refactor marks
  • [4] RGK2IUMO If email address is not in log, get it from pijul change
  • [5] K23EJ6EJ Process commits in reverse
  • [6] P2B4ZSO5 Include file content
  • [7] 534I6MRX Add --channel flag
  • [8] 2J4YY37D Use "raw" date format
  • [9] RTQQLOCO Use real metadata, but no content yet
  • [10] Y7VFVY6E Initial dummy version
  • [11] KZ4XMKSP Make a temporary clone of the repository

Change contents

  • edit in marks.go at line 2
    [3.47]
    [3.47]
    import (
    "bufio"
    "fmt"
    "io"
    "os"
    )
    type markedChange struct {
    mark int
    hash string
    }
  • replacement in marks.go at line 16
    [3.68][3.68:79]()
    marks int
    [3.68]
    [3.79]
    marks int
    changes []markedChange
  • edit in marks.go at line 26
    [3.189]
    [3.189]
    // Make a lookup table for existing marks, and make sure we don't
    // reuse them.
    hashToMark := make(map[string]int)
    for _, mc := range m.changes {
    hashToMark[mc.hash] = mc.mark
    if mc.mark > m.marks {
    m.marks = mc.mark
    }
    }
  • replacement in marks.go at line 37
    [3.215][3.215:244]()
    changes[i].mark = m.Next()
    [3.215]
    [3.244]
    if mark, ok := hashToMark[changes[i].Hash]; ok {
    changes[i].mark = mark
    changes[i].exported = true
    } else {
    changes[i].mark = m.Next()
    m.changes = append(m.changes, markedChange{
    mark: changes[i].mark,
    hash: changes[i].Hash,
    })
    }
    }
    }
    // Import loads a marks file analogous to those used by git fast-export's
    // --import-marks and --export-marks switches.
    func (m *Marks) Import(filename string) error {
    f, err := os.Open(filename)
    if err != nil {
    return err
    }
    defer f.Close()
    br := bufio.NewReader(f)
    for {
    var mc markedChange
    n, err := fmt.Fscanf(br, ":%d %s\n", &mc.mark, &mc.hash)
    if err == io.ErrUnexpectedEOF && n == 0 {
    return nil
    }
    if err != nil {
    return err
    }
    m.changes = append(m.changes, mc)
    }
    }
    func (m *Marks) Export(filename string) error {
    f, err := os.Create(filename)
    if err != nil {
    return err
  • edit in marks.go at line 78
    [3.247]
    [3.247]
    for _, c := range m.changes {
    fmt.Fprintf(f, ":%d %s\n", c.mark, c.hash)
    }
    return f.Close()
  • replacement in main.go at line 17
    [4.45][4.18:90](),[4.90][4.0:72](),[4.72][2.0:101]()
    var repo = flag.String("repo", ".", "path of the repository to export")
    var channel = flag.String("channel", "main", "which channel to export")
    var branch = flag.String("branch", "", "destination branch in Git (default is the same as channel)")
    [4.45]
    [4.73]
    var (
    repo = flag.String("repo", ".", "path of the repository to export")
    channel = flag.String("channel", "main", "which channel to export")
    branch = flag.String("branch", "", "destination branch in Git (default is the same as channel)")
    markFile = flag.String("marks", "", "path to file to store persistent marks")
    )
  • replacement in main.go at line 35
    [4.362][3.250:260]()
    mark int
    [4.362]
    [4.96]
    mark int
    exported bool
  • edit in main.go at line 40
    [4.147][4.147:184]()
    fmt.Fprintf(os.Stderr, "%T\n", err)
  • edit in main.go at line 108
    [4.33]
    [3.394]
    if *markFile != "" {
    if err := stream.marks.Import(*markFile); err != nil {
    printErrorAndExit("Error loading marks file:", err)
    }
    }
  • edit in main.go at line 116
    [4.73]
    [4.5]
    if c.exported {
    break
    }
  • replacement in main.go at line 121
    [4.28][4.28:130]()
    if _, err := exec.Command("pijul", "unrecord", changes[changeIndex-1].Hash).Output(); err != nil {
    [4.28]
    [4.130]
    if _, err := exec.Command("pijul", "unrecord", "--reset", changes[changeIndex-1].Hash).Output(); err != nil {
  • edit in main.go at line 123
    [4.218][4.218:347]()
    }
    if _, err := exec.Command("pijul", "reset").Output(); err != nil {
    printErrorAndExit("Error from pijul reset:", err)
  • edit in main.go at line 211
    [4.1282]
    [4.1677]
    }
    if *markFile != "" {
    if err := stream.marks.Export(*markFile); err != nil {
    printErrorAndExit("Error writing marks file:", err)
    }