mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Use a Commit model in Javascript to parse commit data
This includes the prototype library in the bundle for convenience. Whenever a new commit is selected, a new Commit object is created that is going to parse the raw message. From the object we can select author information, diffs, etc. Currently there is still a bug with commits without content changes.
This commit is contained in:
+1748
-1804
File diff suppressed because it is too large
Load Diff
BIN
Binary file not shown.
@@ -18,6 +18,10 @@
|
||||
F56526240E03D85900F03B52 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F56526230E03D85900F03B52 /* WebKit.framework */; };
|
||||
F565262B0E03D89B00F03B52 /* PBWebGitController.m in Sources */ = {isa = PBXBuildFile; fileRef = F565262A0E03D89B00F03B52 /* PBWebGitController.m */; };
|
||||
F565265A0E03E71B00F03B52 /* commit.html in Resources */ = {isa = PBXBuildFile; fileRef = F56526590E03E71B00F03B52 /* commit.html */; };
|
||||
F57ABDDF0E0441DE00A088B8 /* commit.js in Sources */ = {isa = PBXBuildFile; fileRef = F57ABDDE0E0441DE00A088B8 /* commit.js */; };
|
||||
F57ABE0B0E0442DD00A088B8 /* commit.js in Resources */ = {isa = PBXBuildFile; fileRef = F57ABDDE0E0441DE00A088B8 /* commit.js */; };
|
||||
F57ABE190E04431D00A088B8 /* prototype.js in Sources */ = {isa = PBXBuildFile; fileRef = F57ABE180E04431D00A088B8 /* prototype.js */; };
|
||||
F57ABE2B0E04435100A088B8 /* prototype.js in Resources */ = {isa = PBXBuildFile; fileRef = F57ABE180E04431D00A088B8 /* prototype.js */; };
|
||||
F58A8F280E043698007E3FC0 /* commits.css in Resources */ = {isa = PBXBuildFile; fileRef = F58A8F270E043698007E3FC0 /* commits.css */; };
|
||||
F5945E170E02B0C200706420 /* PBGitRepository.m in Sources */ = {isa = PBXBuildFile; fileRef = F5945E160E02B0C200706420 /* PBGitRepository.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
@@ -44,6 +48,8 @@
|
||||
F56526290E03D89B00F03B52 /* PBWebGitController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBWebGitController.h; sourceTree = "<group>"; };
|
||||
F565262A0E03D89B00F03B52 /* PBWebGitController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBWebGitController.m; sourceTree = "<group>"; };
|
||||
F56526590E03E71B00F03B52 /* commit.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = commit.html; path = html/commit.html; sourceTree = "<group>"; };
|
||||
F57ABDDE0E0441DE00A088B8 /* commit.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = commit.js; path = html/commit.js; sourceTree = "<group>"; };
|
||||
F57ABE180E04431D00A088B8 /* prototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = prototype.js; path = html/prototype.js; sourceTree = "<group>"; };
|
||||
F58A8F270E043698007E3FC0 /* commits.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; name = commits.css; path = html/commits.css; sourceTree = "<group>"; };
|
||||
F5945E150E02B0C200706420 /* PBGitRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRepository.h; sourceTree = "<group>"; };
|
||||
F5945E160E02B0C200706420 /* PBGitRepository.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRepository.m; sourceTree = "<group>"; };
|
||||
@@ -161,6 +167,8 @@
|
||||
children = (
|
||||
F56526590E03E71B00F03B52 /* commit.html */,
|
||||
F58A8F270E043698007E3FC0 /* commits.css */,
|
||||
F57ABDDE0E0441DE00A088B8 /* commit.js */,
|
||||
F57ABE180E04431D00A088B8 /* prototype.js */,
|
||||
);
|
||||
name = HTML;
|
||||
sourceTree = "<group>";
|
||||
@@ -211,6 +219,8 @@
|
||||
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */,
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
|
||||
F565265A0E03E71B00F03B52 /* commit.html in Resources */,
|
||||
F57ABE0B0E0442DD00A088B8 /* commit.js in Resources */,
|
||||
F57ABE2B0E04435100A088B8 /* prototype.js in Resources */,
|
||||
F58A8F280E043698007E3FC0 /* commits.css in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -229,6 +239,8 @@
|
||||
F56524BB0E02D22D00F03B52 /* NSFileHandleExt.m in Sources */,
|
||||
F56524F00E02D45200F03B52 /* PBGitCommit.m in Sources */,
|
||||
F565262B0E03D89B00F03B52 /* PBWebGitController.m in Sources */,
|
||||
F57ABDDF0E0441DE00A088B8 /* commit.js in Sources */,
|
||||
F57ABE190E04431D00A088B8 /* prototype.js in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
+3
-25
@@ -2,30 +2,8 @@
|
||||
<header>
|
||||
<title>Details for commit</title>
|
||||
<link rel="stylesheet" href="commits.css" type="text/css" media="screen" title="no title" charset="utf-8">
|
||||
<script type="text/JavaScript">
|
||||
var doeHet = function() {
|
||||
document.getElementById("commitID").innerHTML = CommitObject.sha;
|
||||
document.getElementById("authorID").innerHTML = CommitObject.author;
|
||||
document.getElementById("subjectID").innerHTML = CommitObject.subject;
|
||||
|
||||
details = CommitObject.details();
|
||||
messageStart = details.indexOf("\n\n") + 2;
|
||||
diffStart = details.indexOf("diff");
|
||||
|
||||
header = details.substring(0, messageStart);
|
||||
message = details.substring(messageStart, diffStart);
|
||||
details = details.substring(diffStart);
|
||||
|
||||
date = header.match(/author .* ([0-9]+) .*/)[1];
|
||||
date = new Date(parseInt(date) * 1000);
|
||||
//date = "ha";
|
||||
document.getElementById("date").innerHTML = date;
|
||||
|
||||
document.getElementById("message").innerHTML = message.replace(/\n/g,"<br>");
|
||||
document.getElementById("details").innerHTML = details;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="prototype.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="commit.js" type="text/javascript" charset="utf-8"></script>
|
||||
</header>
|
||||
|
||||
<body style="padding: 0px; border: 0px">
|
||||
@@ -44,7 +22,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="property_name">Subject:</td>
|
||||
<td id="subjectID">Pieter de Bie</td>
|
||||
<td id="subjectID" style="font-weight:bold">Pieter de Bie</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
var Commit = Class.create({
|
||||
initialize: function(obj) {
|
||||
this.raw = obj.details();
|
||||
this.sha = this.raw.match(/^commit ([0-9a-f]{40,40})/)[1];
|
||||
|
||||
var match = this.raw.match(/\nauthor (.*) <(.*@.*)> ([0-9].*)/);
|
||||
this.author_name = match[1];
|
||||
this.author_email = match[2];
|
||||
this.author_date = new Date(parseInt(match[3]) * 1000);
|
||||
|
||||
match = this.raw.match(/\ncommitter (.*) <(.*@.*)> ([0-9].*)/);
|
||||
this.committer_name = match[1];
|
||||
this.committer_email = match[2];
|
||||
this.committer_date = new Date(parseInt(match[3]) * 1000);
|
||||
|
||||
this.parents = $A(this.raw.match(/\nparent ([0-9a-f]{40,40})/g)).map(function(x) {
|
||||
return x.replace("\nparent ","");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
var doeHet = function() {
|
||||
var commit = new Commit(CommitObject);
|
||||
$("commitID").innerHTML = commit.sha;
|
||||
$("authorID").innerHTML = commit.author_name + " <<a href='mailto:" + commit.author_email + "'>" + commit.author_email + "</a>>";
|
||||
$("date").innerHTML = commit.author_date;
|
||||
$("subjectID").innerHTML =CommitObject.subject;
|
||||
|
||||
$A($("commit_header").rows).each(function(row) {
|
||||
if (row.innerHTML.match(/Parent:/))
|
||||
row.remove();
|
||||
});
|
||||
commit.parents.each(function(parent) {
|
||||
var new_row = $("commit_header").insertRow(-1);
|
||||
new_row.innerHTML = "<td class='property_name'>Parent:</td><td><a href=''>" + parent + "</a></td>";
|
||||
});
|
||||
|
||||
details = CommitObject.details();
|
||||
messageStart = details.indexOf("\n\n") + 2;
|
||||
diffStart = details.indexOf("diff");
|
||||
|
||||
header = details.substring(0, messageStart);
|
||||
message = details.substring(messageStart, diffStart);
|
||||
details = details.substring(diffStart);
|
||||
|
||||
|
||||
$("message").innerHTML = message.replace(/\n/g,"<br>");
|
||||
$("details").innerHTML = details;
|
||||
}
|
||||
Vendored
+4221
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user