Changeset 932 in tailor
- Timestamp:
- 10/20/05 23:29:35 (8 years ago)
- Hash name:
- 20051020212935-7a6fb-ac338d99f0cbd94c04e3e003c1ec7ce26670fa7d
- Location:
- vcpx
- Files:
-
- 2 edited
-
darcs.py (modified) (11 diffs)
-
tests/darcs.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vcpx/darcs.py
r894 r932 23 23 """ 24 24 25 def changesets_from_darcschanges(changes, unidiff=False, repodir=None): 25 def changesets_from_darcschanges(changes, unidiff=False, repodir=None, 26 chunksize=2**15): 26 27 """ 27 28 Parse XML output of ``darcs changes``. … … 34 35 35 36 csets = changesets_from_darcschanges_unsafe(changes, unidiff, 36 repodir )37 repodir, chunksize) 37 38 for cs in csets: 38 39 cs.tags = None 39 return csets40 41 42 def changesets_from_darcschanges_unsafe(changes, unidiff=False, repodir=None):40 yield cs 41 42 def changesets_from_darcschanges_unsafe(changes, unidiff=False, repodir=None, 43 chunksize=2**15): 43 44 """ 44 45 Do the real work of parsing the change log, including tags. … … 53 54 changesets_from_darcschanges. 54 55 """ 55 from xml.sax import parse56 from xml.sax.handler import ContentHandler 56 from xml.sax import make_parser 57 from xml.sax.handler import ContentHandler, ErrorHandler 57 58 from changes import ChangesetEntry, Changeset 58 59 from datetime import datetime … … 142 143 self.current_field.append(data) 143 144 144 145 parser = make_parser() 145 146 handler = DarcsXMLChangesHandler() 146 parse(changes, handler) 147 changesets = handler.changesets 148 149 # sort changeset by date 150 changesets.sort(lambda x, y: cmp(x.date, y.date)) 151 152 return changesets 153 147 parser.setContentHandler(handler) 148 parser.setErrorHandler(ErrorHandler()) 149 150 chunk = changes.read(chunksize) 151 while chunk: 152 parser.feed(chunk) 153 for cs in handler.changesets: 154 yield cs 155 handler.changesets = [] 156 chunk = changes.read(chunksize) 157 parser.close() 158 for cs in handler.changesets: 159 yield cs 154 160 155 161 class DarcsWorkingDir(UpdatableSourceWorkingDir,SyncronizableTargetWorkingDir): … … 184 190 l == 'No remote changes to pull in!\n'): 185 191 l = output.readline() 186 187 changesets = []188 192 189 193 if l <> 'No remote changes to pull in!\n': … … 239 243 "propagate tags from darcs." % name 240 244 else: 241 changesets.append(cset)245 yield cset 242 246 243 247 while not l.strip(): 244 248 l = output.readline() 245 246 return changesets247 249 248 250 def _applyChangeset(self, changeset): … … 303 305 last = changesets_from_darcschanges(changes.execute(stdout=PIPE)[0]) 304 306 if last: 305 changeset.entries.extend(last [0].entries)307 changeset.entries.extend(last.next().entries) 306 308 307 309 return conflicts … … 335 337 initial = True 336 338 cmd = self.repository.command("changes", "--xml-output", 337 "--repo", self.repository.repository) 339 "--repo", self.repository.repository, 340 "--reverse") 338 341 changes = ExternalCommand(command=cmd) 339 342 output = changes.execute(stdout=PIPE, stderr=STDOUT)[0] … … 346 349 347 350 csets = changesets_from_darcschanges(output) 348 changeset = csets [0]351 changeset = csets.next() 349 352 350 353 revision = 'hash %s' % changeset.darcs_hash … … 407 410 last = changesets_from_darcschanges(output) 408 411 409 return last [0]412 return last.next() 410 413 411 414 … … 636 639 """ 637 640 cmd = self.repository.command("changes", "--from-match=not name ^TAG", 638 "--xml-output" )641 "--xml-output", "--reverse") 639 642 changes = ExternalCommand(cwd=self.basedir, command=cmd) 640 643 output = changes.execute(stdout=PIPE, stderr=STDOUT)[0] -
vcpx/tests/darcs.py
r882 r932 50 50 csets = changesets_from_darcschanges(log) 51 51 52 self.assertEqual(len(csets), 2) 52 cset = csets.next() 53 self.assertEqual(cset.revision, 54 "Fix the CVS parser to omit already seen changesets") 55 self.assertEqual(cset.author, "lele@nautilus.homeip.net") 56 self.assertEqual(cset.date, datetime(2004, 7, 16, 12, 37, 37)) 57 self.assertEqual(cset.log, 58 "Fix the CVS parser to omit already seen changesets\n" 59 "For some unknown reasons....") 60 entry = cset.entries[0] 61 self.assertEqual(entry.name, 'vcpx/cvs.py') 62 self.assertEqual(entry.action_kind, entry.UPDATED) 53 63 54 cset = csets [0]64 cset = csets.next() 55 65 self.assertEqual(cset.revision, 56 66 "Svn log parser with test") … … 73 83 self.assertEqual(entry.action_kind, entry.ADDED) 74 84 75 cset = csets[1]76 self.assertEqual(cset.revision,77 "Fix the CVS parser to omit already seen changesets")78 self.assertEqual(cset.author, "lele@nautilus.homeip.net")79 self.assertEqual(cset.date, datetime(2004, 7, 16, 12, 37, 37))80 self.assertEqual(cset.log,81 "Fix the CVS parser to omit already seen changesets\n"82 "For some unknown reasons....")83 entry = cset.entries[0]84 self.assertEqual(entry.name, 'vcpx/cvs.py')85 self.assertEqual(entry.action_kind, entry.UPDATED)86 87 85 def testOnTailorOwnRepo(self): 88 86 """Verify fetching unidiff of a darcs patch""" … … 96 94 unidiff=True, 97 95 repodir=getcwd()) 98 unidiff = csets [0].unidiff96 unidiff = csets.next().unidiff 99 97 head = unidiff.split('\n')[0] 100 98 self.assertEqual(head, 'Thu Jun 9 22:17:11 CEST 2005 zooko@zooko.com') … … 146 144 log = StringIO(self.ALL_ACTIONS_TEST) 147 145 148 csets = changesets_from_darcschanges(log)146 csets = list(changesets_from_darcschanges(log)) 149 147 150 148 self.assertEqual(len(csets), 4) … … 188 186 self.assertEqual(entry.name, 'a.txt') 189 187 self.assertEqual(entry.action_kind, entry.UPDATED) 188 189 def testIncrementalParser(self): 190 """Verify that the parser is effectively incremental""" 191 192 log = StringIO(self.ALL_ACTIONS_TEST) 193 194 csets = list(changesets_from_darcschanges(log, chunksize=100)) 195 self.assertEqual(len(csets), 4)
Note: See TracChangeset
for help on using the changeset viewer.
