Rev 33: Handle the case where we have a user but no email. in http://bzr.arbash-meinel.com/plugins/stats

John Arbash Meinel john at arbash-meinel.com
Fri Jan 15 21:33:09 GMT 2010


At http://bzr.arbash-meinel.com/plugins/stats

------------------------------------------------------------
revno: 33
revision-id: john at arbash-meinel.com-20100115213257-jupa04qkt5fdkm82
parent: john at arbash-meinel.com-20100115211904-1modd0fhfslvqdz0
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: stats
timestamp: Fri 2010-01-15 15:32:57 -0600
message:
  Handle the case where we have a user but no email.
  
  This now seems to match properly for all the cases involved.
  A UserName but no email will match the same username, an email with
  no UserName will match the same email. But the empty entries never
  add a match to similar named entries.
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2010-01-15 21:19:04 +0000
+++ b/__init__.py	2010-01-15 21:32:57 +0000
@@ -87,17 +87,34 @@
                 email_to_id[old_email] = cur_id
     for email, usernames in email_users.iteritems():
         assert email not in email_to_id
+        if not email:
+            # We use a different algorithm for usernames that have no email
+            # address, we just try to match by username, and not at all by
+            # email
+            for user in usernames:
+                if not user:
+                    continue # The mysterious ('', '') user
+                user_id = username_to_id.get(user)
+                if user_id is None:
+                    id_counter += 1
+                    user_id = id_counter
+                    username_to_id[user] = user_id
+                    id_to_combos[user_id] = id_combos = set()
+                else:
+                    id_combos = id_combos[user_id]
+                id_combos.add((user, email))
+            continue
+
         id_counter += 1
         cur_id = id_counter
         id_to_combos[cur_id] = id_combos = set()
-        if email:
-            email_to_id[email] = cur_id
+        email_to_id[email] = cur_id
 
         for user in usernames:
             combo = (user, email)
             id_combos.add(combo)
-            if not user or not email:
-                # We don't match on empty usernames and empty emails
+            if not user:
+                # We don't match on empty usernames
                 continue
             user_id = username_to_id.get(user)
             if user_id is not None:
@@ -186,7 +203,7 @@
         sorted_fullnames = sorted(((count, fullname)
                                   for fullname,count in fullnames.iteritems()),
                                   reverse=True)
-        if sorted_fullnames[0][1] == '':
+        if sorted_fullnames[0][1] == '' and sorted_emails[0][1] == '':
             to_file.write('%4d %s\n'
                           % (count, 'Unknown'))
         else:



More information about the bazaar-commits mailing list