Skip to content

Commit 7b339dc

Browse files
committed
Use a single RemoteRevision per editor window
Parameterize `url()` by the revision instead having it be fixed at creation time to allow all `BlameLineView` components to share the same instance. Test Plan: Toggled blame view and it still works. Also, specs still pass.
1 parent dc09b51 commit 7b339dc

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

lib/controllers/blameViewController.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const $ = require('atom').$;
22
const React = require('atom').React;
33
const BlameListView = require('../views/blame-list-view');
4+
const RemoteRevision = require('../util/RemoteRevision');
45

56

67
/**
@@ -16,12 +17,18 @@ function toggleBlame(projectBlamer) {
1617
var editor = editorView.getEditor();
1718

1819
if (!editorView.blameView) {
20+
var filePath = atom.workspace.activePaneItem.getPath();
21+
var remoteUrl = projectBlamer.repo.getOriginUrl(filePath);
22+
var remoteRevision = RemoteRevision.create(remoteUrl);
23+
// TODO: validate the RemoteRevision here
24+
1925
// insert the BlameListView after the gutter div
2026
var mountPoint = $('<div>', {'class': 'git-blame-mount'});
2127
editorView.find('.gutter').after(mountPoint);
2228

2329
editorView.blameView = React.renderComponent(new BlameListView({
2430
projectBlamer: projectBlamer,
31+
remoteRevision: remoteRevision,
2532
filePath: editor.getPath(),
2633
lineCount: editor.getLineCount(),
2734
scrollbar: editorView.find('.vertical-scrollbar')

lib/util/RemoteRevision.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ 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);
15+
RemoteRevision.create = function(remoteUrl) {
16+
return new RemoteRevision(remoteUrl);
1817
}
1918

2019
// ================
@@ -34,7 +33,7 @@ _.extend(RemoteRevision.prototype, {
3433
}
3534
},
3635

37-
url: function() {
36+
url: function(revision) {
3837
var template = this.getTemplate();
3938

4039
if (!template) {
@@ -44,7 +43,7 @@ _.extend(RemoteRevision.prototype, {
4443

4544
// create data object used to render template string
4645
var data = this.parseProjectAndRepo();
47-
data.revision = this.hash;
46+
data.revision = revision;
4847

4948
// ensure we have all the correct vars in the template data
5049
if (!this.verifyTemplateData(data)) {

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)