From: Lars Schneider Date: Tue, 15 Sep 2015 15:59:16 GMT Subject: Re: [PATCH v7] git-p4: improve path encoding verbose output Message-ID: <46B8F08C-F4A4-43D0-9798-D663F1C5F4BA@gmail.com> In-Reply-To: <55F7C93D.1080309@diamand.org> On 15 Sep 2015, at 09:31, Luke Diamand wrote: > On 14/09/15 18:10, larsxschneider@gmail.com wrote: >> From: Lars Schneider >> >> If a path with non-ASCII characters is detected then print always the > > s/print always/print/ I will fix it. > > >> encoding and the encoded string in verbose mode. >> >> Signed-off-by: Lars Schneider >> --- >> git-p4.py | 19 +++++++++---------- >> 1 file changed, 9 insertions(+), 10 deletions(-) >> >> diff --git a/git-p4.py b/git-p4.py >> index d45cf2b..da25d3f 100755 >> --- a/git-p4.py >> +++ b/git-p4.py >> @@ -2220,16 +2220,15 @@ class P4Sync(Command, P4UserMap): >> text = regexp.sub(r'$\1$', text) >> contents = [ text ] >> >> - if gitConfig("git-p4.pathEncoding"): >> - relPath = relPath.decode(gitConfig("git-p4.pathEncoding")).encode('utf8', 'replace') >> - elif self.verbose: >> - try: >> - relPath.decode('ascii') >> - except: >> - print ( >> - "Path with Non-ASCII characters detected and no path encoding defined. " >> - "Please check the encoding: %s" % relPath >> - ) >> + try: >> + relPath.decode('ascii') >> + except: >> + encoding = 'utf8' >> + if gitConfig('git-p4.pathEncoding'): >> + encoding = gitConfig('git-p4.pathEncoding') > > It would be better to query this once at startup. Otherwise we're potentially forking "git config" twice per file which on a large repo could become significant. Make it an instance variable perhaps? solved in other email > >> + relPath = relPath.decode(encoding).encode('utf8', 'replace') >> + if self.verbose: >> + print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, relPath) >> >> self.gitStream.write("M %s inline %s\n" % (git_mode, relPath)) Thanks!