aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Conley2013-08-29 15:58:43 (EDT)
committerBogdan Gheorghe2013-08-29 15:59:34 (EDT)
commit1585f69568fdd40d31e55e6902cdcc850006b6b0 (patch)
tree92abcb6a260e7dedcd10df0c446571dff649a840
parentfd497edc9a213417b7a37de1aabe216536652012 (diff)
downloadorg.eclipse.orion.client-1585f69568fdd40d31e55e6902cdcc850006b6b0.zip
org.eclipse.orion.client-1585f69568fdd40d31e55e6902cdcc850006b6b0.tar.gz
org.eclipse.orion.client-1585f69568fdd40d31e55e6902cdcc850006b6b0.tar.bz2
Bug 414014 - Show git blame annotations in the editor
Signed-off-by: Chris Conley <chrisconley15@gmail.com>
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/plugins/gitBlamePlugin.js117
1 files changed, 39 insertions, 78 deletions
diff --git a/bundles/org.eclipse.orion.client.ui/web/plugins/gitBlamePlugin.js b/bundles/org.eclipse.orion.client.ui/web/plugins/gitBlamePlugin.js
index fd45544..a46150e 100644
--- a/bundles/org.eclipse.orion.client.ui/web/plugins/gitBlamePlugin.js
+++ b/bundles/org.eclipse.orion.client.ui/web/plugins/gitBlamePlugin.js
@@ -8,10 +8,9 @@
*
* Contributors: IBM Corporation - initial API and implementation
******************************************************************************/
-/*global define document*/
+/*global define document */
define(["orion/xhr", "orion/plugin", "orion/Deferred", 'orion/operation'], function(xhr, PluginProvider, Deferred, operation) {
-
var headers = {
name: "Git Blame Plugin",
version: "1.0", //$NON-NLS-0$
@@ -20,41 +19,28 @@ define(["orion/xhr", "orion/plugin", "orion/Deferred", 'orion/operation'], funct
var provider = new PluginProvider(headers);
var blameRequest = {
- getCommitInfo: function(location) {
- var service = this;
- var clientDeferred = new Deferred();
- xhr("GET", location, { //$NON-NLS-0$
- headers: {
- "Orion-Version": "1", //$NON-NLS-1$ //$NON-NLS-0$
- "Content-Type": "charset=UTF-8" //$NON-NLS-1$ //$NON-NLS-0$
- },
- timeout: 15000,
- handleAs: "json" //$NON-NLS-0$
- }).then(function(result) {
- service._getGitServiceResponse(clientDeferred, result);
- }, function(error) {
- service._handleGitServiceResponseError(clientDeferred, error);
- });
- return clientDeferred;
- },
getBlameInfo: function(location) {
- var service = this;
+ var service = this; //$NON-NLS-0$
var clientDeferred = new Deferred();
xhr("GET", "/gitapi/blame/master" + location, { //$NON-NLS-1$ //$NON-NLS-0$
headers: {
"Orion-Version": "1", //$NON-NLS-1$ //$NON-NLS-0$
- "Content-Type": "charset=UTF-8" //$NON-NLS-1$ //$NON-NLS-0$
+ "Content-Type": "charset=UTF-8" //$NON-NLS-1$ //$NON-NLS-0$
},
timeout: 15000,
handleAs: "json" //$NON-NLS-0$
- }).then(function(result) {
+ }).then(
+
+ function(result) {
service._getGitServiceResponse(clientDeferred, result);
- }, function(error) {
+ },
+
+ function(error) {
service._handleGitServiceResponseError(clientDeferred, error);
- });
+ });
return clientDeferred;
},
@@ -84,73 +70,46 @@ define(["orion/xhr", "orion/plugin", "orion/Deferred", 'orion/operation'], funct
};
/*
- * Makes a server requests for the blame data, as well as server requests for
- * all of the commits that make up the blame data
+ * Makes a server requests for the blame data, as well as server
+ * requests for all of the commits that make up the blame data
*/
function blameFile(url) {
var wrappedResult = new Deferred();
blameRequest.getBlameInfo(url).then(function(response) {
- var range = [];
- var commits = [];
- var j;
- var i;
- var found;
- for (i = 0; i < response.Children.length; i++) {
- range = response.Children[i];
- j = 0;
- found = false;
- var id = range.CommitLocation;
- while (j < commits.length && !found) {
- if (commits[j] === id) {
- found = true;
- }
- j++;
- }
- if (!found) {
- commits.push(id);
- }
- }
-
- for (i = 0; i < commits.length; i++) {
- commits[i] = blameRequest.getCommitInfo(commits[i] + "?pageSize=1"); //$NON-NLS-0$
- }
-
- Deferred.all(commits, function(error) {
+ var annotations = [];
+ Deferred.all(annotations, function(error) {
return {
_error: error
};
- }).then(function(blame) {
-
- blame.sort(function compare(a, b) {
- if (a.Children[0].Time < b.Children[0].Time) {
+ }).then(function() {
+ var commits = response.Children;
+ commits.sort(function compare(a, b) {
+ if (a.Time < b.Time) {
return 1;
}
- if (a.Children[0].Time > b.Children[0].Time) {
+ if (a.Time > b.Time) {
return -1;
}
return 0;
});
-
- for (var i = 0; i < response.Children.length; i++) {
- range = response.Children[i];
- for (var j = 0; j < blame.length; j++) {
- var c = blame[j].Children[0];
- if (c.Location === range.CommitLocation) {
- range.AuthorName = c.AuthorName;
- range.AuthorEmail = c.AuthorEmail;
- range.CommitterName = c.CommitterName;
- range.CommitterEmail = c.CommitterEmail;
- range.Message = c.Message;
- range.AuthorImage = c.AuthorImage;
- range.Name = c.Name;
- range.Time = new Date(c.Time).toLocaleString();
- range.Shade = (1 / (blame.length + 1)) * (blame.length - j + 1);
- range.CommitLink = "{OrionHome}/git/git-commit.html#" + range.CommitLocation + "?page=1&pageSize=1"; //$NON-NLS-1$ //$NON-NLS-0$
- break;
- }
+ for (var i = 0; i < commits.length; i++) {
+ for (var j = 0; j < commits[i].Children.length; j++) {
+ var range = commits[i].Children[j];
+ var c = commits[i];
+ range.AuthorName = c.AuthorName;
+ range.AuthorEmail = c.AuthorEmail;
+ range.CommitterName = c.CommitterName;
+ range.CommitterEmail = c.CommitterEmail;
+ range.Message = c.Message;
+ range.AuthorImage = c.AuthorImage;
+ range.Name = c.Name;
+ range.Time = new Date(c.Time).toLocaleString();
+ range.Shade = (1 / (commits.length + 1)) * (commits.length - i + 1);
+ range.CommitLink = "{OrionHome}/git/git-commit.html#" + c.CommitLocation + "?page=1&pageSize=1"; //$NON-NLS-1$ //$NON-NLS-0$
+ annotations.push(range);
}
}
- wrappedResult.resolve(response.Children);
+ wrappedResult.resolve(annotations);
});
});
return wrappedResult;
@@ -163,9 +122,11 @@ define(["orion/xhr", "orion/plugin", "orion/Deferred", 'orion/operation'], funct
};
var properties = {
name: "Git Blame",
- key: ["b", true, false, true] // Ctrl+Alt+b //$NON-NLS-0$
+ key: ["b", true, false, true] //$NON-NLS-0$
+ // Ctrl+Alt+b
};
- provider.registerService("orion.edit.blamer", serviceImpl, properties); //$NON-NLS-0$
+ provider.registerService("orion.edit.blamer", serviceImpl, //$NON-NLS-0$
+ properties);
provider.connect();
}); \ No newline at end of file