Import and export marks
Dependencies
- [2]
OLMQ7EVUAdd --branch flag - [3]
YBAXM44PRefactor marks - [4]
RGK2IUMOIf email address is not in log, get it from pijul change - [5]
K23EJ6EJProcess commits in reverse - [6]
P2B4ZSO5Include file content - [7]
534I6MRXAdd --channel flag - [8]
2J4YY37DUse "raw" date format - [9]
RTQQLOCOUse real metadata, but no content yet - [10]
Y7VFVY6EInitial dummy version - [11]
KZ4XMKSPMake a temporary clone of the repository
Change contents
- edit in marks.go at line 2
import ("bufio""fmt""io""os")type markedChange struct {mark inthash string} - replacement in marks.go at line 16
marks intmarks intchanges []markedChange - edit in marks.go at line 26
// 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.markif mc.mark > m.marks {m.marks = mc.mark}} - replacement in marks.go at line 37
changes[i].mark = m.Next()if mark, ok := hashToMark[changes[i].Hash]; ok {changes[i].mark = markchanges[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 markedChangen, 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
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
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)")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
mark intmark intexported bool - edit in main.go at line 40
fmt.Fprintf(os.Stderr, "%T\n", err) - edit in main.go at line 108
if *markFile != "" {if err := stream.marks.Import(*markFile); err != nil {printErrorAndExit("Error loading marks file:", err)}} - edit in main.go at line 116
if c.exported {break} - replacement in main.go at line 121
if _, err := exec.Command("pijul", "unrecord", changes[changeIndex-1].Hash).Output(); err != nil {if _, err := exec.Command("pijul", "unrecord", "--reset", changes[changeIndex-1].Hash).Output(); err != nil { - edit in main.go at line 123
}if _, err := exec.Command("pijul", "reset").Output(); err != nil {printErrorAndExit("Error from pijul reset:", err) - edit in main.go at line 211
}if *markFile != "" {if err := stream.marks.Export(*markFile); err != nil {printErrorAndExit("Error writing marks file:", err)}