Changeset 21 in tailor


Ignore:
Timestamp:
06/22/04 02:20:58 (9 years ago)
Author:
lele@…
Hash name:
20040622002058-97f81-538aa65cf1c3a42e84ae2d566661ce6d413b0878
Message:

Preliminary 'darcs changes' parser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/darcs.py

    r19 r21  
    5959 
    6060 
     61class DarcsChanges(SystemCommand): 
     62    COMMAND = "darcs changes --from-tag=tagname --xml-output --summary" 
     63 
     64 
    6165class DarcsWorkingDir(UpdatableSourceWorkingDir,SyncronizableTargetWorkingDir): 
    6266    """ 
     
    7074        Do the actual work of fetching the upstream changeset. 
    7175         
    72         This is different from the other mechanism: here we want register 
    73         with the target the changes we submitted to this repository to be 
    74         sent back to upstream. 
    75  
    76         So, here we actually list the changes after the last tag. 
     76        This is different from the other VC mechanisms: here we want 
     77        register with the target the changes we submitted to this 
     78        repository to be sent back to upstream. Since we may want to 
     79        regroup the various patchsets into a single one, we first 
     80        manually pull here what we wanna send, then the sync will replay  
     81        the changes of all new changesets. 
     82         
     83        So, here we actually list the changes after the last tag, not 
     84        those pending on the other side. 
    7785        """ 
    7886 
    7987        tagname = self._getLastTag(root) 
    80         # darcs changes --from-tag=tagname --xml-output 
     88         
     89        c = DarcsChanges(working_dir=root) 
     90        changes = c(output=True) 
     91 
     92        changesets = self.__parseDarcsChanges(changes) 
     93 
     94        if changesets: 
     95            self._createTag(root, 
     96                            'Sent %d patchsets upstream' % len(changesets)) 
     97 
     98        return changesets 
     99     
     100    def __parseDarcsChanges(self, changes): 
     101        from xml.sax import parseString 
     102        from xml.sax.handler import ContentHandler 
     103        from changes import ChangesetEntry, Changeset 
     104         
     105        class DarcsXMLChangesHandler(ContentHandler): 
     106            def __init__(self): 
     107                self.changesets = [] 
     108                self.current = None 
     109                self.current_field = [] 
     110 
     111            def startElement(self, name, attributes): 
     112                if name == 'patch': 
     113                    self.current = {} 
     114                    self.current['author'] = attributes['author'] 
     115                    self.current['date'] = attributes['local_date'] 
     116                    self.current['revision'] = attributes['revision'] 
     117                    self.current['entries'] = [] 
     118                elif name in ['name', 'comment', 
     119                              'add_file', 'add_directory', 
     120                              'modify_file', 'remove_file', 
     121                              'rename_file']: 
     122                    self.current_field = [] 
     123                elif name == 'path': 
     124                    self.current_field = [] 
     125                    if attributes.has_key('copyfrom-path'): 
     126                        self.current_path_action = ( 
     127                            attributes['action'], 
     128                            attributes['copyfrom-path'][1:], # make it relative 
     129                            attributes['copyfrom-rev']) 
     130                    else: 
     131                        self.current_path_action = attributes['action'] 
     132 
     133            def endElement(self, name): 
     134                if name == 'patch': 
     135                    # Sort the paths to make tests easier 
     136                    self.current['entries'].sort() 
     137                    self.changesets.append(Changeset(self.current['name'], 
     138                                                     self.current['date'], 
     139                                                     self.current['author'], 
     140                                                     self.current['comment'], 
     141                                                     self.current['entries'])) 
     142                    self.current = None 
     143                elif name in ['name', 'comment']: 
     144                    self.current[name] = ''.join(self.current_field) 
     145                elif name in ['add_file', 'add_directory', 
     146                              'modify_file', 'remove_file', 
     147                              'rename_file']: 
     148                    entry = ChangesetEntry(''.join(self.current_field)) 
     149                    entry.action_kind = { 'add_file': entry.ADDED, 
     150                                          'add_directory': entry.ADDED, 
     151                                          'modify_file': entry.MODIFIED, 
     152                                          'remove_file': entry.REMOVED, 
     153                                          'rename_file': entry.RENAMED 
     154                                        }[name] 
     155 
     156                    self.current['entries'].append(entry) 
     157 
     158            def characters(self, data): 
     159                self.current_field.append(data) 
     160         
     161        handler = DarcsXMLChangesHandler() 
     162        parseString(changes.getvalue(), handler) 
     163        return handler.changesets 
    81164         
    82165    def _applyChangeset(self, root, changeset): 
Note: See TracChangeset for help on using the changeset viewer.