mailmap

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 3 Imported by: 0

README

mailmap

A Go library for parsing Git .mailmap files and resolving author identities. It uses only the standard library and supports the four mailmap entry forms for replacing names, email addresses, or both.

Installation

go get github.com/git-pkgs/mailmap

Usage

package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/git-pkgs/mailmap"
)

func main() {
	m, err := mailmap.Parse(strings.NewReader(`Jane Doe <jane@example.com> <jane@laptop.(none)>
`))
	if err != nil {
		log.Fatal(err)
	}
	name, email := m.Resolve("jane", "jane@laptop.(none)")
	fmt.Printf("%s <%s>\n", name, email)
	// Jane Doe <jane@example.com>
}

Parse accepts an io.Reader, including an open .mailmap file. New() creates an empty map; empty, zero-value, and nil maps return identities unchanged.

Matching ignores case for names and email addresses, and entries matching both take priority over entries matching only email. The last matching entry in each group wins; unmatched identities are returned unchanged.

Blank lines, comments starting with #, and malformed entries are skipped. Reader errors and lines exceeding the default bufio.Scanner token limit return an error along with the entries parsed so far.

License

MIT.

Documentation

Overview

Package mailmap parses Git .mailmap files and resolves author identities.

Parse accepts the four mailmap forms for replacing names, email addresses, or both. Names and email addresses match without regard to case. Entries matching both name and email take priority over entries matching only email; within either group, the last matching entry wins.

Blank lines, comments starting with #, and malformed entries are skipped. Parse returns a partially populated Mailmap together with any reader or scanner error. It uses bufio.Scanner's default token limit.

An empty, zero-value, or nil Mailmap returns identities unchanged.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mailmap

type Mailmap struct {
	// contains filtered or unexported fields
}

Mailmap holds parsed .mailmap entries and resolves author identities.

func New

func New() *Mailmap

New creates an empty Mailmap.

func Parse

func Parse(r io.Reader) (*Mailmap, error)

Parse reads a .mailmap file and returns a Mailmap for resolving identities.

Example
package main

import (
	"fmt"
	"strings"

	"github.com/git-pkgs/mailmap"
)

func main() {
	m, err := mailmap.Parse(strings.NewReader(`Jane Doe <jane@example.com> <jane@laptop.(none)>
`))
	if err != nil {
		panic(err)
	}
	name, email := m.Resolve("jane", "jane@laptop.(none)")
	fmt.Printf("%s <%s>\n", name, email)
}
Output:
Jane Doe <jane@example.com>

func (*Mailmap) Resolve

func (m *Mailmap) Resolve(name, email string) (string, string)

Resolve maps an author's name and email to their canonical identity. If no mapping exists, the original values are returned unchanged.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL