If email address is not in log, get it from pijul change

andybalholm
Mar 14, 2023, 10:35 PM
RGK2IUMOM7CWPSAHLJBLIRJ7Y6HZPHLTLJ7ADTWVBMI5ZJNBGY2AC

Dependencies

  • [2] 5ETDKF5F Start on data structures to represent fast-export stream
  • [3] EGKSUIOB Better handling of missing email address
  • [*] Y7VFVY6E Initial dummy version
  • [*] RTQQLOCO Use real metadata, but no content yet
  • [*] KZ4XMKSP Make a temporary clone of the repository
  • [*] RFMRCLJX Remove empty parentheses after author name

Change contents

  • edit in main.go at line 4
    [5.56]
    [6.0]
    "bufio"
    "bytes"
  • edit in main.go at line 12
    [7.17]
    [8.0]
    "strconv"
  • edit in main.go at line 50
    [7.358]
    [5.126]
    // unquote tries to unquote various types of quoted strings, and returns the
    // result. If none of the formats works, it returns s unchanged except for
    // trimming off whitespace.
    func unquote(s string) string {
    s = strings.TrimSpace(s)
    switch {
    case strings.HasPrefix(s, "'''") && strings.HasSuffix(s, "'''"):
    return strings.TrimPrefix(strings.TrimSuffix(s, "'''"), "'''")
    case strings.HasPrefix(s, "'") && strings.HasSuffix(s, "'"):
    return strings.TrimPrefix(strings.TrimSuffix(s, "'"), "'")
    case strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\""):
    unquoted, err := strconv.Unquote(s)
    if err == nil {
    return unquoted
    }
    }
    return s
    }
    var authorsHeader = []byte("\n[[authors]]\n")
  • edit in main.go at line 127
    [3.19]
    [7.1162]
    // Since the email address is missing from the log,
    // we'll try to find it in the output of pijul change.
    changeInfo, err := exec.Command("pijul", "change", c.Hash).Output()
    if err != nil {
    printErrorAndExit("Error from pijul change:", err)
    }
    if i := bytes.Index(changeInfo, authorsHeader); i != -1 {
    var name, email string
    s := bufio.NewScanner(bytes.NewReader(changeInfo[i+len(authorsHeader):]))
    for s.Scan() {
    line := s.Text()
    if line == "" {
    break
    }
    if strings.HasPrefix(line, "email =") {
    email = unquote(strings.TrimPrefix(line, "email ="))
    } else if strings.HasPrefix(line, "name =") {
    name = unquote(strings.TrimPrefix(line, "name ="))
    }
    }
    if name != "" && email != "" {
    author = name + " <" + email + ">"
    }
    }
  • edit in main.go at line 154
    [2.76]
    [2.76]