Skip to content

Commit b7c46c1

Browse files
committed
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.
1 parent 1626606 commit b7c46c1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

PBGitRevList.mm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ - (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
7676
BOOL showSign = [rev hasLeftRight];
7777

7878
if (showSign)
79-
arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%an\01%s\01%P\01%at\01%m", nil];
79+
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];
8080
else
81-
arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%an\01%s\01%P\01%at", nil];
81+
arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%e\01%an\01%s\01%P\01%at", nil];
8282

8383
if (!rev)
8484
[arguments addObject:@"HEAD"];
@@ -120,6 +120,12 @@ - (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
120120
}
121121

122122
// From now on, 1.2 seconds
123+
string encoding_str;
124+
getline(stream, encoding_str, '\1');
125+
NSStringEncoding encoding = NSUTF8StringEncoding;
126+
if (encoding_str.length())
127+
encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)[NSString stringWithUTF8String:encoding_str.c_str()]));
128+
123129
git_oid oid;
124130
git_oid_mkstr(&oid, sha.c_str());
125131
PBGitCommit* newCommit = [[PBGitCommit alloc] initWithRepository:repository andSha:oid];
@@ -152,8 +158,8 @@ - (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
152158
stream >> time;
153159

154160

155-
[newCommit setSubject:[NSString stringWithUTF8String:subject.c_str()]];
156-
[newCommit setAuthor:[NSString stringWithUTF8String:author.c_str()]];
161+
[newCommit setSubject:[NSString stringWithCString:subject.c_str() encoding:encoding]];
162+
[newCommit setAuthor:[NSString stringWithCString:author.c_str() encoding:encoding]];
157163
[newCommit setTimestamp:time];
158164

159165
if (showSign)

0 commit comments

Comments
 (0)