mailmap 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/mailmap/map.rb +126 -0
- data/lib/mailmap/version.rb +5 -0
- data/lib/mailmap.rb +4 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cdc12709b9e48412d76d01f4f75c018bb0822e6d3e25ced6527cdca9c507a97f
|
4
|
+
data.tar.gz: e3a713e40d6f7ae4134ac8c1021558e01aa23f9f3dae5fb039bfc724c6a648dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df1d46c1608c78dae83f1359b13af597a24d11cf531d44bd4aa9d6f8fd71e1d89779ff3018f357d7bd17c46e628e985905a7906a593bf9e23f55af4dbcdee7e8
|
7
|
+
data.tar.gz: 1519019ddacc4d53af233a9638bbc7717df61a15457cbc88d356dc964c23c8608f0f4eb565e646f6b834ee2143643be3948e80def17195d669f4e090fbbc2c83
|
data/lib/mailmap/map.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
require 'strscan'
|
5
|
+
|
6
|
+
module Mailmap
|
7
|
+
# This exception is raised if a parser error occurs.
|
8
|
+
class ParserError < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
# A Map represents a .mailmap file.
|
12
|
+
class Map
|
13
|
+
extend Forwardable
|
14
|
+
|
15
|
+
def_delegators :each, *Enumerable.instance_methods(false)
|
16
|
+
|
17
|
+
class << self
|
18
|
+
# Load a mailmap file and return Map object.
|
19
|
+
#
|
20
|
+
# @param path [String] the path to .mailmap file
|
21
|
+
# @return [Map]
|
22
|
+
def load(path)
|
23
|
+
new(File.read(path))
|
24
|
+
end
|
25
|
+
|
26
|
+
alias parse new
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param string [String] the string in .mailmap format
|
30
|
+
def initialize(string)
|
31
|
+
@map = Hash.new { |h, k| h[k] = {} }
|
32
|
+
parse(string)
|
33
|
+
end
|
34
|
+
|
35
|
+
def each
|
36
|
+
return enum_for(:each) unless block_given?
|
37
|
+
|
38
|
+
@map.each do |commit_email, entries_by_commit_name|
|
39
|
+
entries_by_commit_name.each do |commit_name, (proper_name, proper_email)|
|
40
|
+
yield [proper_name, proper_email, commit_name, commit_email]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Look up the person's canonical name and email address.
|
46
|
+
# If found, return them; otherwise return nil.
|
47
|
+
#
|
48
|
+
# @param commit_name_or_nil [String, nil] the name in commit or nil
|
49
|
+
# @param commit_email [String] the name in commit
|
50
|
+
# @return [Array<String>] if found, a pair of proper name and email or nil
|
51
|
+
# @return [nil] if not found
|
52
|
+
def lookup(commit_name_or_nil, commit_email)
|
53
|
+
commit_name = commit_name_or_nil&.downcase
|
54
|
+
commit_email = commit_email.downcase
|
55
|
+
hash = @map[commit_email]
|
56
|
+
hash[commit_name] || hash[nil]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Like `git-check-mailmap` command, look up the person's canonical name and email address.
|
60
|
+
# If found, return them; otherwise return the input as-is.
|
61
|
+
#
|
62
|
+
# @param commit_name_or_nil [String, nil] the name in commit or nil
|
63
|
+
# @param commit_email [String] the email in commit
|
64
|
+
# @return [Array<String>] a pair of proper name and email
|
65
|
+
def resolve(commit_name_or_nil, commit_email)
|
66
|
+
proper_name, proper_email = lookup(commit_name_or_nil, commit_email)
|
67
|
+
proper_name ||= commit_name_or_nil
|
68
|
+
proper_email ||= commit_email
|
69
|
+
[proper_name, proper_email]
|
70
|
+
end
|
71
|
+
|
72
|
+
# Return true if the name is defined as either of proper or commit name, otherwise false.
|
73
|
+
# The comparison is case-insensitive.
|
74
|
+
#
|
75
|
+
# @param name [String] the name
|
76
|
+
# @return [Boolean]
|
77
|
+
def include_name?(name)
|
78
|
+
name = name.downcase
|
79
|
+
any? do |(proper_name, _proper_email, commit_name, _commit_email)|
|
80
|
+
proper_name.downcase == name || commit_name == name
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Return true if the email is defined as either of proper or commit email, otherwise false.
|
85
|
+
# The comparison is case-insensitive.
|
86
|
+
#
|
87
|
+
# @param email [String] the email
|
88
|
+
# @return [Boolean]
|
89
|
+
def include_email?(email)
|
90
|
+
email = email.downcase
|
91
|
+
any? do |(_proper_name, proper_email, _commit_name, commit_email)|
|
92
|
+
proper_email.downcase == email || commit_email == email
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def parse(string)
|
99
|
+
string.each_line.with_index(1) do |line, line_number|
|
100
|
+
next if line.start_with?('#')
|
101
|
+
|
102
|
+
parse_name_and_email(line, line_number)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def parse_name_and_email(line, line_number) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
107
|
+
names = []
|
108
|
+
emails = []
|
109
|
+
scanner = StringScanner.new(line)
|
110
|
+
2.times do
|
111
|
+
scanner.skip(/\s+/)
|
112
|
+
scanner.scan(/[^<]+/).then { |s| names << s.rstrip if s }
|
113
|
+
scanner.skip(/</)
|
114
|
+
scanner.scan(/[^>]+/).then { |s| emails << s if s }
|
115
|
+
scanner.skip(/>/)
|
116
|
+
end
|
117
|
+
raise ParserError, "Missing commit email at line #{line_number}" if emails.empty?
|
118
|
+
|
119
|
+
commit_email = emails.pop&.downcase
|
120
|
+
proper_email = emails.pop
|
121
|
+
proper_name = names.shift
|
122
|
+
commit_name = names.shift&.downcase
|
123
|
+
@map[commit_email][commit_name] = [proper_name, proper_email]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/lib/mailmap.rb
ADDED
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailmap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryosuke Ito
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Parser for Git Mailmap (.mailmap)
|
14
|
+
email:
|
15
|
+
- rito.0305@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/mailmap.rb
|
21
|
+
- lib/mailmap/map.rb
|
22
|
+
- lib/mailmap/version.rb
|
23
|
+
homepage: https://github.com/manicmaniac/mailmap
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata:
|
27
|
+
rubygems_mfa_required: 'true'
|
28
|
+
homepage_uri: https://github.com/manicmaniac/mailmap
|
29
|
+
source_code_uri: https://github.com/manicmaniac/mailmap
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 2.6.0
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubygems_version: 3.0.3.1
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Parser for Git Mailmap (.mailmap)
|
49
|
+
test_files: []
|