− fmt.Println("commit refs/heads/master")
− fmt.Println("mark :1")
− fmt.Println("committer Andy Balholm <andy@balholm.com>", formatTime(time.Now()))
− fmt.Println("data <<END")
− fmt.Println("Test commit")
− fmt.Println("END")
− fmt.Println()
+ flag.Parse()
+
+ if *repo != "" {
+ err := os.Chdir(*repo)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error changing to directory of source repository: %v\n", err)
+ os.Exit(2)
+ }
+ }
+
+ logCmd := exec.Command("pijul", "log", "--description", "--output-format=json")
+ logBytes, err := logCmd.Output()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error running pijul log: %v\n", err)
+ os.Exit(2)
+ }
+
+ var changes []change
+ err = json.Unmarshal(logBytes, &changes)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error parsing pijul log output: %v\n", err)
+ os.Exit(2)
+ }
+
+ previousCommitMark := 0
+
+ for changeIndex := len(changes) - 1; changeIndex >= 0; changeIndex-- {
+ c := changes[changeIndex]
+ if len(c.Authors) == 0 && changeIndex == len(changes)-1 {
+ // Skip the original, empty change.
+ continue
+ }
+
+ commitMark := nextMark()
+
+ fmt.Println("commit refs/heads/master")
+ fmt.Printf("mark :%d\n", commitMark)
+ fmt.Println("committer", c.Authors[0], formatTime(c.Timestamp))
+
+ message := c.Message
+ if c.Description != "" {
+ message += "\n\n" + c.Description
+ }
+ fmt.Println("data", len(message))
+ fmt.Println(message)
+ if previousCommitMark != 0 {
+ fmt.Printf("from :%d\n", previousCommitMark)
+ }
+ fmt.Println()
+
+ previousCommitMark = commitMark
+ }