#!/usr/bin/env python # -*- Mode: python coding: utf-8 -*- # # author diverKon # version 0.2 # Copyright(C) KK.Kon # licenes http://opensource.org/licenses/bsd-license.php New BSD License # since 2012-01-13 import os import sys from svn import fs, repos, core, client, delta from svn.core import SubversionException if ( 2 > len(sys.argv) ): print 'Usage: repo_path' quit() do_fix = False if ( 3 <= len(sys.argv) ): if '--do-fix' == sys.argv[2]: do_fix = True print 'do_fix=', do_fix #print 'stdout.encoding=', sys.stdout.encoding if 'win32' == sys.platform: if 'cp65001' == sys.stdout.encoding: print 'Not support codepage 65001!' quit() else: import codecs sys.stdout = codecs.getwriter('utf_8')(sys.stdout) myrepos = repos.open( sys.argv[1] ) myfs = repos.fs( myrepos ) myrev = fs.youngest_rev( myfs ) def conv_encoding( data, to_enc="utf_8"): lookups = ('utf_8', 'euc_jp', 'cp932', 'ascii' ) for encoding in lookups: try: data = data.decode( encoding ) break except: pass if isinstance( data, unicode ): return data.encode( to_enc ) else: return data for rev in range(1, myrev): rev_log = fs.revision_prop( myfs, rev, 'svn:log' ) print 'revision=', rev if None == rev_log: continue #print 'rev_log=', rev_log svnlog_utf8 = conv_encoding( rev_log ) need_fix = False if svnlog_utf8 != rev_log: need_fix = True else: need_fix = False if True == need_fix: print 'need fix' print 'rev_log=', unicode( svnlog_utf8, 'utf_8' ) if True == do_fix: print 'fix...' fs.change_rev_prop( myfs, rev, 'svn:log', svnlog_utf8 )