def parse_commit(chunks):
 parents = []
 extra = []
 tree = None
 author_info = (None, None, (None, None))
 commit_info = (None, None, (None, None))
 encoding = None
 mergetag = []
 message = None
 gpgsig = None
 for (field, value) in _parse_message(chunks):
  if (field == _TREE_HEADER):
   tree = value
  elif (field == _PARENT_HEADER):
   parents.append(value)
  elif (field == _AUTHOR_HEADER):
   (author, timetext, timezonetext) = value.rsplit(' ', 2)
   author_time = int(timetext)
   author_info = (author, author_time, parse_timezone(timezonetext))
  elif (field == _COMMITTER_HEADER):
   (committer, timetext, timezonetext) = value.rsplit(' ', 2)
   commit_time = int(timetext)
   commit_info = (committer, commit_time, parse_timezone(timezonetext))
  elif (field == _ENCODING_HEADER):
   encoding = value
  elif (field == _MERGETAG_HEADER):
   mergetag.append(Tag.from_string((value + '\n')))
  elif (field == _GPGSIG_HEADER):
   gpgsig = value
  elif (field is None):
   message = value
  else:
   extra.append((field, value))
 return (tree, parents, author_info, commit_info, encoding, mergetag, gpgsig, message, extra)

def parse_commit ( chunks ) : parents = [ ] extra = [ ] tree = None author_info = ( None , None , ( None , None ) ) commit_info = ( None , None , ( None , None ) ) encoding = None mergetag = [ ] message = None gpgsig = None for ( field , value ) in _parse_message ( chunks ) : if ( field == _TREE_HEADER ) : tree = value elif ( field == _PARENT_HEADER ) : parents . append ( value ) elif ( field == _AUTHOR_HEADER ) : ( author , timetext , timezonetext ) = value . rsplit ( ' ' , 2 ) author_time = int ( timetext ) author_info = ( author , author_time , parse_timezone ( timezonetext ) ) elif ( field == _COMMITTER_HEADER ) : ( committer , timetext , timezonetext ) = value . rsplit ( ' ' , 2 ) commit_time = int ( timetext ) commit_info = ( committer , commit_time , parse_timezone ( timezonetext ) ) elif ( field == _ENCODING_HEADER ) : encoding = value elif ( field == _MERGETAG_HEADER ) : mergetag . append ( Tag . from_string ( ( value + '\n' ) ) ) elif ( field == _GPGSIG_HEADER ) : gpgsig = value elif ( field is None ) : message = value else : extra . append ( ( field , value ) ) return ( tree , parents , author_info , commit_info , encoding , mergetag , gpgsig , message , extra )
parse a string referring to a single commit .