Пример #1
0
func readMailmap() (mailmap, error) {
	var (
		rg  runGuard
		cwd string
		mm  = make(mailmap)
	)

	rg.maybeRun(func() {
		var err error

		cwd, err = os.Getwd()
		if err != nil {
			rg.err = err
			rg.msg = "Error determining current working directory"
		}
	})

	// Check for profile mailmap
	rg.maybeRun(func() {
		cp, err := gg.ConfigFindGlobal()
		if err != nil {
			fmt.Printf("Error finding global config: %v\n", err)
			return
		}

		conf, err := gg.OpenOndisk(&gg.Config{}, cp)
		if err != nil {
			return
		}
		defer conf.Free()

		path, err := conf.LookupString("mailmap.file")
		if err != nil {
			fmt.Printf("Error lookup up mailmap file %v\n", err)
			return
		}

		f, err := os.Open(path)
		defer f.Close()
		if err != nil {
			return
		}

		if err := readMailmapFromSource(mm, f); err != nil {
			return
		}
	})

	// Parse project mailmap last so it overrides
	rg.maybeRun(func() {
		f, err := os.Open(cwd + ".mailmap")
		defer f.Close()
		if err != nil {
			return
		}

		if err := readMailmapFromSource(mm, f); err != nil {
			return
		}
	})

	// Check for any errors that might have happened
	if rg.err != nil {
		return nil, rg.err
	}

	return mm, nil
}
Пример #2
0
func init() {
	var (
		rg  runGuard
		cwd string
	)

	rg.maybeRun(func() {
		var err error

		cwd, err = os.Getwd()
		if err != nil {
			rg.err = err
			rg.msg = "Error determining current working directory"
		}
	})

	mailmap = make(map[string]string)

	// Check for profile mailmap
	rg.maybeRun(func() {
		cp, err := gg.ConfigFindGlobal()
		if err != nil {
			fmt.Printf("Error finding global config: %v\n", err)
			return
		}

		conf, err := gg.OpenOndisk(&gg.Config{}, cp)
		if err != nil {
			return
		}
		defer conf.Free()

		path, err := conf.LookupString("mailmap.file")
		if err != nil {
			fmt.Printf("Error lookup up mailmap file %v\n", err)
			return
		}

		f, err := os.Open(path)
		defer f.Close()
		if err != nil {
			return
		}

		readMailmap(mailmap, f)
		useMailmap = true
	})

	// Parse project mailmap last so it overrides
	rg.maybeRun(func() {
		f, err := os.Open(cwd + ".mailmap")
		defer f.Close()
		if err != nil {
			return
		}

		readMailmap(mailmap, f)
		useMailmap = true
	})

	// Check for any errors that might have happened
	if rg.err != nil {
		useMailmap = false
		fmt.Println("Error starting up! We can't read the mailmap file!")
		fmt.Println(rg.err.Error())

		// If we're left with an error by now, we should stop
		panic(rg.err)
	}
}