Always use Git instance from project

This removes the need to open a new repository
each time a directory-view or file-view is displayed
and also when a status-bar is displayed for a buffer.
This commit is contained in:
Kevin Sawicki
2013-01-02 17:21:24 -08:00
parent 7f0030ef4f
commit 2971716060
5 changed files with 15 additions and 18 deletions

View File

@@ -8,7 +8,6 @@ UndoManager = require 'undo-manager'
BufferChangeOperation = require 'buffer-change-operation'
Anchor = require 'anchor'
AnchorRange = require 'anchor-range'
Git = require 'git'
module.exports =
class Buffer
@@ -24,7 +23,6 @@ class Buffer
anchors: null
anchorRanges: null
refcount: 0
git: null
constructor: (path, @project) ->
@id = @constructor.idCounter++
@@ -90,8 +88,6 @@ class Buffer
setPath: (path) ->
return if path == @getPath()
@git = new Git(path)
@file?.off()
@file = new File(path)
if @file.exists()
@@ -387,12 +383,12 @@ class Buffer
line = @lineForRow(row)
console.log row, line, line.length
getGit: -> @git
getRepo: -> @project?.repo
checkoutHead: ->
path = @getPath()
return unless path
if @git?.checkoutHead(path)
if @getRepo()?.checkoutHead(path)
@trigger 'git-status-changed'
scheduleStoppedChangingEvent: ->

View File

@@ -119,6 +119,7 @@ describe "StatusBar", ->
expect(statusBar.branchLabel.text()).toBe 'master'
it "doesn't display the current branch for a file not in a repository", ->
rootView.project.setPath('/tmp')
path = '/tmp/temp.txt'
rootView.open(path)
expect(statusBar.branchArea).toBeHidden()

View File

@@ -65,7 +65,7 @@ class StatusBar extends View
@branchArea.hide()
return unless path
head = @buffer.getGit()?.getShortHead()
head = @buffer.getRepo()?.getShortHead()
@branchLabel.text(head)
@branchArea.show() if head
@@ -75,9 +75,10 @@ class StatusBar extends View
return unless path
@gitStatusIcon.removeClass().addClass('git-status octicons')
if @buffer.getGit()?.isPathModified(path)
git = @buffer.getRepo()
if git?.isPathModified(path)
@gitStatusIcon.addClass('modified-status-icon')
stats = @buffer.getGit().getDiffStats(path)
stats = git.getDiffStats(path)
if stats.added and stats.deleted
@gitStatusIcon.text("+#{stats.added},-#{stats.deleted}")
else if stats.added
@@ -86,7 +87,7 @@ class StatusBar extends View
@gitStatusIcon.text("-#{stats.deleted}")
else
@gitStatusIcon.text('')
else if @buffer.getGit()?.isPathNew(path)
else if git?.isPathNew(path)
@gitStatusIcon.addClass('new-status-icon')
@gitStatusIcon.text("+#{@buffer.getLineCount()}")

View File

@@ -22,7 +22,7 @@ class DirectoryView extends View
@expand() if isExpanded
@disclosureArrow.on 'click', => @toggleExpansion()
repositoryPath = parent?.getPath() or @directory.getPath()
@directoryName.addClass('ignored') if new Git(repositoryPath).isPathIgnored(@directory.getPath())
@directoryName.addClass('ignored') if @project.repo.isPathIgnored(@directory.getPath())
getPath: ->
@directory.path
@@ -39,7 +39,7 @@ class DirectoryView extends View
if entry instanceof Directory
@entries.append(new DirectoryView(directory: entry, isExpanded: false, project: @project, parent: @directory))
else
@entries.append(new FileView(entry))
@entries.append(new FileView(file: entry, project: @project))
@append(@entries)
toggleExpansion: ->

View File

@@ -6,14 +6,14 @@ fs = require 'fs'
module.exports =
class FileView extends View
@content: (file) ->
@content: ({file} = {}) ->
@li class: 'file entry', =>
@span file.getBaseName(), class: 'name', outlet: 'fileName'
@span "", class: 'highlight'
file: null
initialize: (@file) ->
initialize: ({@file, project} = {}) ->
path = @getPath()
extension = fs.extension(path)
if fs.isCompressedExtension(extension)
@@ -25,12 +25,11 @@ class FileView extends View
else
@fileName.addClass('text-name')
git = new Git(path)
if git.isPathIgnored(path)
if project.repo.isPathIgnored(path)
@addClass('ignored')
else if git.isPathModified(path)
else if project.repo.isPathModified(path)
@addClass('modified')
else if git.isPathNew(path)
else if project.repo.isPathNew(path)
@addClass('new')
getPath: ->