Skip to content

Commit 1e14f49

Browse files
committed
Merge pull request #28 from dmnd/error-deluge
Fix error deluge
2 parents b51008e + c5c3974 commit 1e14f49

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

lib/controllers/blameViewController.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const $ = require('atom').$;
22
const React = require('atom').React;
33
const BlameListView = require('../views/blame-list-view');
4+
const RemoteRevision = require('../util/RemoteRevision');
5+
const errorController = require('./errorController');
46

57

68
/**
@@ -14,15 +16,27 @@ const BlameListView = require('../views/blame-list-view');
1416
function toggleBlame(projectBlamer) {
1517
var editorView = atom.workspaceView.getActiveView();
1618
var editor = editorView.getEditor();
19+
var filePath = editor.getPath();
1720

1821
if (!editorView.blameView) {
22+
var remoteUrl = projectBlamer.repo.getOriginUrl(filePath);
23+
var remoteRevision;
24+
try {
25+
remoteRevision = RemoteRevision.create(remoteUrl);
26+
} catch (e) {
27+
// the only exception possible occurs when the template string is invalid
28+
errorController.showError('error-no-custom-url-specified');
29+
return;
30+
}
31+
1932
// insert the BlameListView after the gutter div
2033
var mountPoint = $('<div>', {'class': 'git-blame-mount'});
2134
editorView.find('.gutter').after(mountPoint);
2235

2336
editorView.blameView = React.renderComponent(new BlameListView({
2437
projectBlamer: projectBlamer,
25-
filePath: editor.getPath(),
38+
remoteRevision: remoteRevision,
39+
filePath: filePath,
2640
lineCount: editor.getLineCount(),
2741
scrollbar: editorView.find('.vertical-scrollbar')
2842
}), mountPoint[0]);

lib/util/RemoteRevision.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ const loophole = require('loophole');
44

55
const errorController = require('../controllers/errorController');
66

7-
function RemoteRevision(hash, remote) {
8-
this.hash = hash;
7+
function RemoteRevision(remote) {
98
this.remote = remote;
109
}
1110

1211
// ================
1312
// Class Methods
1413
// ================
1514

16-
RemoteRevision.create = function(hash, remoteUrl) {
17-
return new RemoteRevision(hash, remoteUrl);
18-
}
15+
RemoteRevision.create = function(remoteUrl) {
16+
var rr = new RemoteRevision(remoteUrl);
17+
if (!rr.getTemplate()) {
18+
throw "Cannot create RemoteRevision with invalid template";
19+
}
20+
return rr;
21+
};
1922

2023
// ================
2124
// Instance Methods
@@ -34,20 +37,20 @@ _.extend(RemoteRevision.prototype, {
3437
}
3538
},
3639

37-
url: function() {
40+
url: function(revision) {
3841
var template = this.getTemplate();
39-
4042
if (!template) {
41-
errorController.showError('error-no-custom-url-specified');
42-
return;
43+
// this should be impossible, so throw
44+
throw "No template present in RemoteRevision";
4345
}
4446

4547
// create data object used to render template string
4648
var data = this.parseProjectAndRepo();
47-
data.revision = this.hash;
49+
data.revision = revision;
4850

4951
// ensure we have all the correct vars in the template data
5052
if (!this.verifyTemplateData(data)) {
53+
// TODO: validate this upon creation
5154
errorController.showError('error-problem-parsing-data-from-remote');
5255
return;
5356
}
@@ -95,10 +98,8 @@ _.extend(RemoteRevision.prototype, {
9598
if (atom.config.get('git-blame.useCustomUrlTemplateIfStandardRemotesFail')) {
9699
var customUrlTemplate = atom.config.get('git-blame.customCommitUrlTemplateString');
97100

98-
// if the user hasnt entered a template string...inform them
101+
// if the user hasnt entered a template string, return nothing
99102
if (/^Example/.test(customUrlTemplate)) {
100-
// TODO inform user
101-
errorController.showError('error-no-custom-url-specified');
102103
return;
103104
}
104105

lib/views/blame-line-view.coffee

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{$, React, Reactionary} = require 'atom'
22
RP = React.PropTypes
33
{div, span, a} = Reactionary
4-
RemoteRevision = require '../util/RemoteRevision'
54

65
HASH_LENGTH = 7 # github uses this length
76
BLANK_HASH = '-'.repeat(HASH_LENGTH)
@@ -18,7 +17,7 @@ BlameLineComponent = React.createClass
1817
propTypes:
1918
date: RP.string.isRequired
2019
hash: RP.string.isRequired
21-
url: RP.string.isRequired
20+
remoteRevision: RP.object.isRequired
2221
committer: RP.string.isRequired
2322
backgroundClass: RP.string
2423
noCommit: RP.bool
@@ -30,7 +29,7 @@ BlameLineComponent = React.createClass
3029
span className: 'date', @props.date
3130
span className: 'committer', 'Nobody'
3231
else
33-
url = RemoteRevision.create(@props.hash, @props.url).url()
32+
url = @props.remoteRevision.url @props.hash
3433
div className: 'blame-line ' + @props.backgroundClass,
3534
a className: 'hash', href: url,
3635
@props.hash.substring(0, HASH_LENGTH)

lib/views/blame-list-view.coffee

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ BlameListLinesComponent = React.createClass
1111
loading: RP.bool.isRequired
1212
filePath: RP.string.isRequired
1313
lineCount: RP.number.isRequired
14+
remoteRevision: RP.object.isRequired
1415

1516
renderLoading: ->
1617
lines = [0...@props.lineCount].map renderLoading
@@ -38,9 +39,7 @@ BlameListLinesComponent = React.createClass
3839
lines = _.clone @props.annotations
3940

4041
# add url to open diff
41-
filePath = atom.workspace.activePaneItem.getPath()
42-
remoteUrl = atom.project.getRepo()?.getOriginUrl(filePath)
43-
l['url'] = remoteUrl for l in lines
42+
l.remoteRevision = @props.remoteRevision for l in lines
4443
@_addAlternatingBackgroundColor lines
4544
div null, lines.map BlameLineComponent
4645

@@ -57,6 +56,7 @@ BlameListLinesComponent = React.createClass
5756
BlameListView = React.createClass
5857
propTypes:
5958
projectBlamer: RP.object.isRequired
59+
remoteRevision: RP.object.isRequired
6060
filePath: RP.string.isRequired
6161
lineCount: RP.number.isRequired
6262
scrollbar: RP.object.isRequired
@@ -87,6 +87,7 @@ BlameListView = React.createClass
8787
loading: @state.loading
8888
filePath: @props.filePath
8989
lineCount: @props.lineCount
90+
remoteRevision: @props.remoteRevision
9091

9192
div
9293
className: 'git-blame'

0 commit comments

Comments
 (0)