nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, comment:# First sort commits by author email; 8, expression_statement; 9, comment:# Group commits by author email, so they can be merged; 10, for_statement; 11, comment:# Finally sort by the (aggregated) commits' line counts; 12, expression_statement; 13, return_statement; 14, comment:"""Sort by commit size, per author."""; 15, assignment; 16, pattern_list; 17, call; 18, block; 19, assignment; 20, attribute; 21, identifier:users; 22, list; 23, identifier:_; 24, identifier:group; 25, attribute; 26, argument_list; 27, if_statement; 28, attribute; 29, call; 30, identifier:self; 31, identifier:sorted_commits; 32, identifier:itertools; 33, identifier:groupby; 34, call; 35, call; 36, identifier:group; 37, block; 38, identifier:self; 39, identifier:sorted_commits; 40, identifier:sorted; 41, argument_list; 42, identifier:sorted; 43, argument_list; 44, attribute; 45, argument_list; 46, expression_statement; 47, identifier:users; 48, keyword_argument; 49, keyword_argument; 50, attribute; 51, identifier:operator; 52, identifier:attrgetter; 53, string; 54, call; 55, identifier:key; 56, call; 57, identifier:reverse; 58, True; 59, identifier:self; 60, identifier:commits; 61, string_content:author_mail; 62, attribute; 63, argument_list; 64, attribute; 65, argument_list; 66, identifier:users; 67, identifier:append; 68, call; 69, identifier:operator; 70, identifier:attrgetter; 71, string; 72, attribute; 73, argument_list; 74, string_content:line_count; 75, identifier:self; 76, identifier:merge_user_commits; 77, identifier:group
code: def sort(self):
          """Sort by commit size, per author."""
          # First sort commits by author email
          users = []
          # Group commits by author email, so they can be merged
          for _, group in itertools.groupby(sorted(self.commits),
                                            operator.attrgetter('author_mail')):
              if group:
                  users.append(self.merge_user_commits(group))
          # Finally sort by the (aggregated) commits' line counts
          self.sorted_commits = sorted(users,
                                       key=operator.attrgetter('line_count'),
                                       reverse=True)
          return self.sorted_commits