From e067390fb22a9619efdbb8c29952ed9b7ec09ee3 Mon Sep 17 00:00:00 2001 From: Nathan Kinsinger Date: Sat, 3 Jul 2010 09:04:30 -0600 Subject: [PATCH] Bugfix: Stop committer names from getting mangled If the commit's detail is not UTF8 then PBWebHistoryController's commitDetailsLoaded: method will drop down to Latin1. That can cause character's in the committer's name to not be converted correctly. Move parsing the name to PBGitRevList where the correct encoding can be determined. --- PBGitCommit.h | 2 ++ PBGitCommit.m | 1 + PBGitRevList.mm | 6 +++++- html/views/history/history.js | 21 +++++++++------------ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/PBGitCommit.h b/PBGitCommit.h index 02ceb03..9e4da8d 100644 --- a/PBGitCommit.h +++ b/PBGitCommit.h @@ -23,6 +23,7 @@ extern NSString * const kGitXCommitType; NSString* subject; NSString* author; + NSString *committer; NSString* details; NSString *_patch; NSArray* parents; @@ -53,6 +54,7 @@ extern NSString * const kGitXCommitType; @property (readonly) git_oid *sha; @property (copy) NSString* subject; @property (copy) NSString* author; +@property (copy) NSString *committer; @property (readonly) NSArray* parents; // TODO: remove this and its uses @property (assign) git_oid *parentShas; diff --git a/PBGitCommit.m b/PBGitCommit.m index a9b3b15..6bb9d56 100644 --- a/PBGitCommit.m +++ b/PBGitCommit.m @@ -16,6 +16,7 @@ NSString * const kGitXCommitType = @"commit"; @implementation PBGitCommit @synthesize repository, subject, timestamp, author, parentShas, nParents, sign, lineInfo; +@synthesize committer; - (NSArray *) parents { diff --git a/PBGitRevList.mm b/PBGitRevList.mm index f282484..4a033fb 100644 --- a/PBGitRevList.mm +++ b/PBGitRevList.mm @@ -96,7 +96,7 @@ using namespace std; std::map encodingMap; NSThread *currentThread = [NSThread currentThread]; - NSString *formatString = @"--pretty=format:%H\01%e\01%an\01%s\01%P\01%at"; + NSString *formatString = @"--pretty=format:%H\01%e\01%an\01%cn\01%s\01%P\01%at"; BOOL showSign = [rev hasLeftRight]; if (showSign) @@ -145,6 +145,9 @@ using namespace std; string author; getline(stream, author, '\1'); + string committer; + getline(stream, committer, '\1'); + string subject; getline(stream, subject, '\1'); @@ -171,6 +174,7 @@ using namespace std; [newCommit setSubject:[NSString stringWithCString:subject.c_str() encoding:encoding]]; [newCommit setAuthor:[NSString stringWithCString:author.c_str() encoding:encoding]]; + [newCommit setCommitter:[NSString stringWithCString:committer.c_str() encoding:encoding]]; [newCommit setTimestamp:time]; if (showSign) diff --git a/html/views/history/history.js b/html/views/history/history.js index eabcf41..4c9db52 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -7,6 +7,7 @@ var Commit = function(obj) { this.refs = obj.refs(); this.author_name = obj.author; + this.committer_name = obj.committer; this.sha = obj.realSha(); this.parents = obj.parents; this.subject = obj.subject; @@ -37,21 +38,17 @@ var Commit = function(obj) { if (typeof match !== 'undefined' && typeof match[2] !== 'undefined') { if (!(match[2].match(/@[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/))) this.author_email = match[2]; - - this.author_date = new Date(parseInt(match[3]) * 1000); - + + if (typeof match[3] !== 'undefined') + this.author_date = new Date(parseInt(match[3]) * 1000); + match = this.header.match(/\ncommitter (.*) <(.*@.*|.*)> ([0-9].*)/); - if (typeof match !== 'undefined') { - this.committer_name = match[1]; - this.committer_email = match[2]; - } else { - this.committer_name = "undefined"; - this.committer_email = "undefined"; - } + if (typeof match[2] !== 'undefined') + this.committer_email = match[2]; + if (typeof match[3] !== 'undefined') + this.committer_date = new Date(parseInt(match[3]) * 1000); } } - - this.committer_date = new Date(parseInt(match[3]) * 1000); } this.reloadRefs = function() {