mailmap 0.1.0 → 0.2.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 +4 -4
- data/lib/mailmap/map.rb +19 -15
- data/lib/mailmap/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4eddd3d4d856573b2f0886a08f721b9743db7135db526e2931106827cd3fd3cd
         | 
| 4 | 
            +
              data.tar.gz: d030d00fcaede82db18bd7978efa7c262344d2ed561dab7dc248c299935c45dd
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b8c963050607ed6da6240013aba42103c553b33cb490a58ba0f4ed147a3f54168f0796bdce4e96cc9b2f5e6aae2375c06ec48685aa2e57cae1d2c86dd08499c7
         | 
| 7 | 
            +
              data.tar.gz: bf65c0613576ef87a0efe85bbdde22e4cf84036a5fc74a4bb11c4575914fab1e952d4c55a6c4b7a4abbb663894ea8450452bb1cba9e57847eaf87af215051665
         | 
    
        data/lib/mailmap/map.rb
    CHANGED
    
    | @@ -1,6 +1,5 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'forwardable'
         | 
| 4 3 | 
             
            require 'strscan'
         | 
| 5 4 |  | 
| 6 5 | 
             
            module Mailmap
         | 
| @@ -10,9 +9,7 @@ module Mailmap | |
| 10 9 |  | 
| 11 10 | 
             
              # A Map represents a .mailmap file.
         | 
| 12 11 | 
             
              class Map
         | 
| 13 | 
            -
                 | 
| 14 | 
            -
             | 
| 15 | 
            -
                def_delegators :each, *Enumerable.instance_methods(false)
         | 
| 12 | 
            +
                include Enumerable
         | 
| 16 13 |  | 
| 17 14 | 
             
                class << self
         | 
| 18 15 | 
             
                  # Load a mailmap file and return Map object.
         | 
| @@ -28,18 +25,20 @@ module Mailmap | |
| 28 25 |  | 
| 29 26 | 
             
                # @param string [String] the string in .mailmap format
         | 
| 30 27 | 
             
                def initialize(string)
         | 
| 28 | 
            +
                  # @type ivar @map: Hash[String, Hash[String?, String?]]
         | 
| 31 29 | 
             
                  @map = Hash.new { |h, k| h[k] = {} }
         | 
| 32 30 | 
             
                  parse(string)
         | 
| 33 31 | 
             
                end
         | 
| 34 32 |  | 
| 35 33 | 
             
                def each
         | 
| 36 | 
            -
                  return enum_for | 
| 34 | 
            +
                  return enum_for unless block_given?
         | 
| 37 35 |  | 
| 38 36 | 
             
                  @map.each do |commit_email, entries_by_commit_name|
         | 
| 39 37 | 
             
                    entries_by_commit_name.each do |commit_name, (proper_name, proper_email)|
         | 
| 40 | 
            -
                      yield  | 
| 38 | 
            +
                      yield proper_name, proper_email, commit_name, commit_email
         | 
| 41 39 | 
             
                    end
         | 
| 42 40 | 
             
                  end
         | 
| 41 | 
            +
                  self
         | 
| 43 42 | 
             
                end
         | 
| 44 43 |  | 
| 45 44 | 
             
                # Look up the person's canonical name and email address.
         | 
| @@ -47,7 +46,9 @@ module Mailmap | |
| 47 46 | 
             
                #
         | 
| 48 47 | 
             
                # @param commit_name_or_nil [String, nil] the name in commit or nil
         | 
| 49 48 | 
             
                # @param commit_email [String] the name in commit
         | 
| 50 | 
            -
                # @return [ | 
| 49 | 
            +
                # @return [(String, String)] if found, a pair of proper name and email
         | 
| 50 | 
            +
                # @return [(String, nil)] if only proper name is found
         | 
| 51 | 
            +
                # @return [(nil, String)] if only proper email is found
         | 
| 51 52 | 
             
                # @return [nil] if not found
         | 
| 52 53 | 
             
                def lookup(commit_name_or_nil, commit_email)
         | 
| 53 54 | 
             
                  commit_name = commit_name_or_nil&.downcase
         | 
| @@ -56,12 +57,13 @@ module Mailmap | |
| 56 57 | 
             
                  hash[commit_name] || hash[nil]
         | 
| 57 58 | 
             
                end
         | 
| 58 59 |  | 
| 59 | 
            -
                # Like  | 
| 60 | 
            +
                # Like +git-check-mailmap+ command, look up the person's canonical name and email address.
         | 
| 60 61 | 
             
                # If found, return them; otherwise return the input as-is.
         | 
| 61 62 | 
             
                #
         | 
| 62 63 | 
             
                # @param commit_name_or_nil [String, nil] the name in commit or nil
         | 
| 63 64 | 
             
                # @param commit_email [String] the email in commit
         | 
| 64 | 
            -
                # @return [ | 
| 65 | 
            +
                # @return [(String, String)] a pair of proper name and email
         | 
| 66 | 
            +
                # @return [(nil, String)] if proper name is not found and +commit_name+ is not provided
         | 
| 65 67 | 
             
                def resolve(commit_name_or_nil, commit_email)
         | 
| 66 68 | 
             
                  proper_name, proper_email = lookup(commit_name_or_nil, commit_email)
         | 
| 67 69 | 
             
                  proper_name ||= commit_name_or_nil
         | 
| @@ -76,8 +78,8 @@ module Mailmap | |
| 76 78 | 
             
                # @return [Boolean]
         | 
| 77 79 | 
             
                def include_name?(name)
         | 
| 78 80 | 
             
                  name = name.downcase
         | 
| 79 | 
            -
                  any? do | | 
| 80 | 
            -
                    proper_name | 
| 81 | 
            +
                  any? do |proper_name, _proper_email, commit_name, _commit_email|
         | 
| 82 | 
            +
                    proper_name&.downcase == name || commit_name == name
         | 
| 81 83 | 
             
                  end
         | 
| 82 84 | 
             
                end
         | 
| 83 85 |  | 
| @@ -88,8 +90,8 @@ module Mailmap | |
| 88 90 | 
             
                # @return [Boolean]
         | 
| 89 91 | 
             
                def include_email?(email)
         | 
| 90 92 | 
             
                  email = email.downcase
         | 
| 91 | 
            -
                  any? do | | 
| 92 | 
            -
                    proper_email | 
| 93 | 
            +
                  any? do |_proper_name, proper_email, _commit_name, commit_email|
         | 
| 94 | 
            +
                    proper_email&.downcase == email || commit_email == email
         | 
| 93 95 | 
             
                  end
         | 
| 94 96 | 
             
                end
         | 
| 95 97 |  | 
| @@ -104,7 +106,9 @@ module Mailmap | |
| 104 106 | 
             
                end
         | 
| 105 107 |  | 
| 106 108 | 
             
                def parse_name_and_email(line, line_number) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
         | 
| 109 | 
            +
                  # @type var names: Array[String]
         | 
| 107 110 | 
             
                  names = []
         | 
| 111 | 
            +
                  # @type var emails: Array[String]
         | 
| 108 112 | 
             
                  emails = []
         | 
| 109 113 | 
             
                  scanner = StringScanner.new(line)
         | 
| 110 114 | 
             
                  2.times do
         | 
| @@ -114,9 +118,9 @@ module Mailmap | |
| 114 118 | 
             
                    scanner.scan(/[^>]+/).then { |s| emails << s if s }
         | 
| 115 119 | 
             
                    scanner.skip(/>/)
         | 
| 116 120 | 
             
                  end
         | 
| 117 | 
            -
                  raise ParserError, "Missing commit email at line #{line_number}" if emails.empty?
         | 
| 118 | 
            -
             | 
| 119 121 | 
             
                  commit_email = emails.pop&.downcase
         | 
| 122 | 
            +
                  raise ParserError, "Missing commit email at line #{line_number}" unless commit_email
         | 
| 123 | 
            +
             | 
| 120 124 | 
             
                  proper_email = emails.pop
         | 
| 121 125 | 
             
                  proper_name = names.shift
         | 
| 122 126 | 
             
                  commit_name = names.shift&.downcase
         | 
    
        data/lib/mailmap/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mailmap
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ryosuke Ito
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2023-01-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: Parser for Git Mailmap (.mailmap)
         | 
| 14 14 | 
             
            email:
         |