Changeset 3206

Show
Ignore:
Timestamp:
02/11/08 05:23:02 (10 months ago)
Author:
hvr
Message:

GitPlugin: parse timezone information of committer and author and print respective timestamps of properties in iso format

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gitplugin/0.11/tracext/git/git_fs.py

    r3205 r3206  
    1414 
    1515from trac.core import * 
    16 from trac.util import TracError, shorten_line, escape 
    17 from trac.util.datefmt import utc 
     16from trac.util import TracError, shorten_line 
     17from trac.util.datefmt import utc, FixedOffset 
    1818from trac.versioncontrol.api import \ 
    1919    Changeset, Node, Repository, IRepositoryConnector, NoSuchChangeset, NoSuchNode 
     
    2424 
    2525from genshi.builder import tag 
     26from genshi.core import Markup, escape 
    2627 
    2728from datetime import datetime 
     
    6768        # relied upon by GitChangeset 
    6869 
     70        _rendered_props = ('Parents','Children','git-committer','git-author') 
     71 
    6972        def match_property(self, name, mode): 
    70                 if (name in ('Parents','Children') and mode == 'revprop'): 
     73                if name in ('Parents','Children','git-committer','git-author') \ 
     74                            and mode == 'revprop': 
    7175                        return 8 # default renderer has priority 1 
    7276                return 0 
    7377 
    7478        def render_property(self, name, mode, context, props): 
    75                 assert name in ('Parents','Children') 
    76  
    77                 revs = props[name] 
    78  
    7979                def sha_link(sha): 
    8080                        return self._format_sha_link(context, 'sha', sha, sha) 
    8181 
    82                 return tag([tag(sha_link(rev), ', ') for rev in revs[:-1]], 
    83                            sha_link(revs[-1])) 
    84  
     82                if name in ('Parents','Children'): 
     83                        revs = props[name] 
     84 
     85                        return tag([tag(sha_link(rev), ', ') for rev in revs[:-1]], 
     86                                   sha_link(revs[-1])) 
     87 
     88                if name in ('git-committer', 'git-author'): 
     89                        user_,time_ = props[name] 
     90                        _str = user_ + " / " + time_.strftime('%Y-%m-%dT%H:%M:%SZ%z') 
     91                        return unicode(_str) 
     92 
     93                raise TracError("internal error") 
    8594 
    8695        ####################### 
     
    330339                } 
    331340 
     341        # helper 
     342        def __parse_user_time(self, s): 
     343                """parse author/committer attribute lines and return 
     344                (user,timestamp)""" 
     345                (user,time,tz_str) = s.rsplit(None, 2) 
     346                tz = FixedOffset((int(tz_str)*6)/10, tz_str) 
     347                time = datetime.fromtimestamp(float(time), tz) 
     348                return (user,time) 
     349 
    332350        def __init__(self, git, sha): 
    333351                self.git = git 
     
    338356                self.props = props 
    339357 
    340                 committer = props['committer'][0] 
    341  
    342358                assert 'children' not in props 
    343359                _children = list(git.children(sha)) 
     
    345361                        props['children'] = _children 
    346362 
    347                 (user,time,tz) = committer.rsplit(None, 2) 
    348  
    349                 time = datetime.fromtimestamp(float(time), utc) 
    350                 Changeset.__init__(self, sha, msg, user, time
     363                # use 1st committer as changeset owner/timestamp 
     364                (user_, time_) = self.__parse_user_time(props['committer'][0]) 
     365 
     366                Changeset.__init__(self, sha, msg, user_, time_
    351367 
    352368        def get_properties(self): 
     
    357373                        properties['Children'] = self.props['children'] 
    358374                if 'committer' in self.props: 
    359                         properties['git-committer'] = "\n".join(self.props['committer']) 
     375                        properties['git-committer'] = \ 
     376                            self.__parse_user_time(self.props['committer'][0]) 
    360377                if 'author' in self.props: 
    361                         git_author = "\n".join(self.props['author']) 
     378                        git_author = self.__parse_user_time(self.props['author'][0]) 
    362379                        if not (properties.has_key('git-committer') and 
    363380                                properties['git-committer'] == git_author):