Changeset 1384 in tailor for vcpx/repository/darcs/source.py


Ignore:
Timestamp:
06/13/07 01:06:24 (6 years ago)
Author:
Miklos Vajna <vmiklos@…>
Hash name:
20070612230624-8c5d4-1b78b236e353451e151e39ec5f87f65fd57781f3
Message:

darcs source: handle unescaped problematic characters
quoting the mail from Lele:
"Eh! This is really a damned problem. The fact is, darcs doesn't check
or even understand the encoding used by the committer. Maybe
DARCS_DONT_ESCAPE_XXX could help (but probably won't).

But even svn suffers of this sometimes, and in fact I implemented a
workaround for that system
(see
http://progetti.arstecnica.it/tailor/browser/vcpx/repository/svn.py#L340)
I'm afraid you'll need something similar, if you can isolate the
offending characters in the xml output."
this patch works around this problem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/repository/darcs/source.py

    r1371 r1384  
    125125 
    126126def changesets_from_darcschanges(changes, unidiff=False, repodir=None, 
    127                                  chunksize=2**15): 
     127                                 chunksize=2**15, replace_badchars=None): 
    128128    """ 
    129129    Parse XML output of ``darcs changes``. 
     
    136136 
    137137    csets = changesets_from_darcschanges_unsafe(changes, unidiff, 
    138                                                 repodir, chunksize) 
     138                                                repodir, chunksize, 
     139                                                replace_badchars) 
    139140    for cs in csets: 
    140141        yield cs 
    141142 
    142143def changesets_from_darcschanges_unsafe(changes, unidiff=False, repodir=None, 
    143                                         chunksize=2**15): 
     144                                        chunksize=2**15, replace_badchars=None): 
    144145    """ 
    145146    Do the real work of parsing the change log, including tags. 
     
    241242    parser.setErrorHandler(ErrorHandler()) 
    242243 
    243     chunk = changes.read(chunksize) 
     244    def fixup_badchars(s, map): 
     245        if not map: 
     246            return s 
     247 
     248        ret = [map.get(c, c) for c in s] 
     249        return "".join(ret) 
     250 
     251    chunk = fixup_badchars(changes.read(chunksize), replace_badchars) 
    244252    while chunk: 
    245253        parser.feed(chunk) 
     
    247255            yield cs 
    248256        handler.changesets = [] 
    249         chunk = changes.read(chunksize) 
     257        chunk = fixup_badchars(changes.read(chunksize), replace_badchars) 
    250258    parser.close() 
    251259    for cs in handler.changesets: 
     
    309317                #    my ($date, $author) = ($1, $2); 
    310318                # but that assumes the two spaces as separator, so I find the 
    311                 # following solution easier and by any chance faster too.                 
     319                # following solution easier and by any chance faster too. 
    312320                pieces = l.rstrip().split('  ') 
    313321                assert len(pieces)>1, "Cannot parse %r as a patch timestamp" % l 
     
    418426                                      "--xml-output", "--summ") 
    419427        changes = ExternalCommand(cwd=self.repository.basedir, command=cmd) 
    420         last = changesets_from_darcschanges(changes.execute(stdout=PIPE)[0]) 
     428        last = changesets_from_darcschanges(changes.execute(stdout=PIPE)[0], 
     429                                            replace_badchars=self.repository.replace_badchars) 
    421430        try: 
    422431            changeset.entries.extend(last.next().entries) 
     
    470479                         output and output.read() or '')) 
    471480 
    472                 csets = changesets_from_darcschanges(output) 
     481                csets = changesets_from_darcschanges(output, replace_badchars=self.repository.replace_badchars) 
    473482                changeset = csets.next() 
    474483 
     
    532541                (str(changes), changes.exit_status, output.read())) 
    533542 
    534         last = changesets_from_darcschanges(output) 
     543        last = changesets_from_darcschanges(output, replace_badchars=self.repository.replace_badchars) 
    535544 
    536545        return last.next() 
Note: See TracChangeset for help on using the changeset viewer.