From b7c46c16b86a2c1c1aeaf64d644720fd9a2031bf Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Thu, 28 May 2009 15:10:46 +0100 Subject: [PATCH] GitRevList -- Try to read the encoding of the commit message This tries to read the encoding of the commit message, if it's specified by git (using i18n.commitEncoding at the time of committing). It uses an ugly hack to try to convert the encoding string to an NSStringEncoding, and then uses that for the subject and committer name. I'm not sure how expensive this is. If it's too expensive, we might need to cache this value. --- PBGitRevList.mm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/PBGitRevList.mm b/PBGitRevList.mm index 8ce2082..61a1b27 100644 --- a/PBGitRevList.mm +++ b/PBGitRevList.mm @@ -76,9 +76,9 @@ using namespace std; BOOL showSign = [rev hasLeftRight]; if (showSign) - arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%an\01%s\01%P\01%at\01%m", nil]; + arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%e\01%an\01%s\01%P\01%at\01%m", nil]; else - arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%an\01%s\01%P\01%at", nil]; + arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%e\01%an\01%s\01%P\01%at", nil]; if (!rev) [arguments addObject:@"HEAD"]; @@ -120,6 +120,12 @@ using namespace std; } // From now on, 1.2 seconds + string encoding_str; + getline(stream, encoding_str, '\1'); + NSStringEncoding encoding = NSUTF8StringEncoding; + if (encoding_str.length()) + encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)[NSString stringWithUTF8String:encoding_str.c_str()])); + git_oid oid; git_oid_mkstr(&oid, sha.c_str()); PBGitCommit* newCommit = [[PBGitCommit alloc] initWithRepository:repository andSha:oid]; @@ -152,8 +158,8 @@ using namespace std; stream >> time; - [newCommit setSubject:[NSString stringWithUTF8String:subject.c_str()]]; - [newCommit setAuthor:[NSString stringWithUTF8String:author.c_str()]]; + [newCommit setSubject:[NSString stringWithCString:subject.c_str() encoding:encoding]]; + [newCommit setAuthor:[NSString stringWithCString:author.c_str() encoding:encoding]]; [newCommit setTimestamp:time]; if (showSign) -- 2.11.4.GIT