<commit_before>{View} = require 'atom'

module.exports =
class GitView extends View
  @content: ->
    @div class: 'git-view', =>
      @div class: 'git-branch inline-block', outlet: 'branchArea', =>
        @span class: 'icon icon-git-branch'
        @span class: 'branch-label', outlet: 'branchLabel'
      @div class: 'git-commits inline-block', outlet: 'commitsArea', =>
        @span class: 'icon icon-arrow-up commits-ahead-label', outlet: 'commitsAhead'
        @span class: 'icon icon-arrow-down commits-behind-label', outlet: 'commitsBehind'
      @div class: 'git-status inline-block', outlet: 'gitStatus', =>
        @span outlet: 'gitStatusIcon'

  initialize: (@statusBar) ->
    @statusBar.subscribeToBuffer 'saved', @update
    @subscribe atom.workspaceView, 'pane-container:active-pane-item-changed', @update
    @subscribe atom.project, 'path-changed', @subscribeToRepo
    @subscribeToRepo()

  destroy: ->
    @unsubscribe(@repo) if @repo?
    @repo = null
    @remove()

  afterAttach: ->
    @update()

  getActiveItemPath: ->
    @getActiveItem()?.getPath?()

  getActiveItem: ->
    atom.workspaceView.getActivePaneItem()

  getActiveView: ->
    atom.workspaceView.getActiveView()

  subscribeToRepo: =>
    @unsubscribe(@repo) if @repo?
    if repo = atom.project.getRepo()
      @repo = repo
      @subscribe repo, 'status-changed', (path, status) =>
        @update() if path is @getActiveItemPath()
      @subscribe repo, 'statuses-changed', @update

  update: =>
    @updateBranchText()
    @updateStatusText()

  updateBranchText: ->
    @branchArea.hide()
    return unless atom.project.contains(@getActiveItemPath())

    head = atom.project.getRepo()?.getShortHead(@getActiveItemPath()) or ''
    @branchLabel.text(head)
    @branchArea.show() if head

  updateStatusText: ->
    itemPath = @getActiveItemPath()
    @gitStatus.hide()
    @commitsArea.hide()
    return unless atom.project.contains(itemPath)

    repo = atom.project.getRepo()
    return unless repo?

    upstream = repo.getCachedUpstreamAheadBehindCount(itemPath) ? {}

    if upstream.ahead > 0
      @commitsAhead.text(upstream.ahead).show()
    else
      @commitsAhead.hide()

    if upstream.behind > 0
      @commitsBehind.text(upstream.behind).show()
    else
      @commitsBehind.hide()

    @commitsArea.show() if upstream.ahead > 0 or upstream.behind > 0

    status = repo.statuses[itemPath]
    @gitStatusIcon.removeClass()
    if repo.isStatusModified(status)
      @gitStatusIcon.addClass('icon icon-diff-modified status-modified')
      stats = repo.getDiffStats(itemPath)
      if stats.added and stats.deleted
        @gitStatusIcon.text("+#{stats.added}, -#{stats.deleted}")
      else if stats.added
        @gitStatusIcon.text("+#{stats.added}")
      else if stats.deleted
        @gitStatusIcon.text("-#{stats.deleted}")
      else
        @gitStatusIcon.text('')
    else if repo.isStatusNew(status)
      @gitStatusIcon.addClass('icon icon-diff-added status-added')
      if @statusBar.getActiveBuffer()?
        @gitStatusIcon.text("+#{@statusBar.getActiveBuffer().getLineCount()}")
      else
        @gitStatusIcon.text('')
    else if repo.isPathIgnored(itemPath)
      @gitStatusIcon.addClass('icon icon-diff-ignored status-ignored')
      @gitStatusIcon.text('')

    if @gitStatusIcon.attr('class') then @gitStatus.show() else @gitStatus.hide()<commit_msg>Use new Git::getCachedPathStatus API<commit_after>{View} = require 'atom'

module.exports =
class GitView extends View
  @content: ->
    @div class: 'git-view', =>
      @div class: 'git-branch inline-block', outlet: 'branchArea', =>
        @span class: 'icon icon-git-branch'
        @span class: 'branch-label', outlet: 'branchLabel'
      @div class: 'git-commits inline-block', outlet: 'commitsArea', =>
        @span class: 'icon icon-arrow-up commits-ahead-label', outlet: 'commitsAhead'
        @span class: 'icon icon-arrow-down commits-behind-label', outlet: 'commitsBehind'
      @div class: 'git-status inline-block', outlet: 'gitStatus', =>
        @span outlet: 'gitStatusIcon'

  initialize: (@statusBar) ->
    @statusBar.subscribeToBuffer 'saved', @update
    @subscribe atom.workspaceView, 'pane-container:active-pane-item-changed', @update
    @subscribe atom.project, 'path-changed', @subscribeToRepo
    @subscribeToRepo()

  destroy: ->
    @unsubscribe(@repo) if @repo?
    @repo = null
    @remove()

  afterAttach: ->
    @update()

  getActiveItemPath: ->
    @getActiveItem()?.getPath?()

  getActiveItem: ->
    atom.workspaceView.getActivePaneItem()

  getActiveView: ->
    atom.workspaceView.getActiveView()

  subscribeToRepo: =>
    @unsubscribe(@repo) if @repo?
    if repo = atom.project.getRepo()
      @repo = repo
      @subscribe repo, 'status-changed', (path, status) =>
        @update() if path is @getActiveItemPath()
      @subscribe repo, 'statuses-changed', @update

  update: =>
    @updateBranchText()
    @updateStatusText()

  updateBranchText: ->
    @branchArea.hide()
    return unless atom.project.contains(@getActiveItemPath())

    head = atom.project.getRepo()?.getShortHead(@getActiveItemPath()) or ''
    @branchLabel.text(head)
    @branchArea.show() if head

  updateStatusText: ->
    itemPath = @getActiveItemPath()
    @gitStatus.hide()
    @commitsArea.hide()
    return unless atom.project.contains(itemPath)

    repo = atom.project.getRepo()
    return unless repo?

    upstream = repo.getCachedUpstreamAheadBehindCount(itemPath) ? {}

    if upstream.ahead > 0
      @commitsAhead.text(upstream.ahead).show()
    else
      @commitsAhead.hide()

    if upstream.behind > 0
      @commitsBehind.text(upstream.behind).show()
    else
      @commitsBehind.hide()

    @commitsArea.show() if upstream.ahead > 0 or upstream.behind > 0

    status = repo.getCachedPathStatus(itemPath)
    @gitStatusIcon.removeClass()
    if repo.isStatusModified(status)
      @gitStatusIcon.addClass('icon icon-diff-modified status-modified')
      stats = repo.getDiffStats(itemPath)
      if stats.added and stats.deleted
        @gitStatusIcon.text("+#{stats.added}, -#{stats.deleted}")
      else if stats.added
        @gitStatusIcon.text("+#{stats.added}")
      else if stats.deleted
        @gitStatusIcon.text("-#{stats.deleted}")
      else
        @gitStatusIcon.text('')
    else if repo.isStatusNew(status)
      @gitStatusIcon.addClass('icon icon-diff-added status-added')
      if @statusBar.getActiveBuffer()?
        @gitStatusIcon.text("+#{@statusBar.getActiveBuffer().getLineCount()}")
      else
        @gitStatusIcon.text('')
    else if repo.isPathIgnored(itemPath)
      @gitStatusIcon.addClass('icon icon-diff-ignored status-ignored')
      @gitStatusIcon.text('')

    if @gitStatusIcon.attr('class') then @gitStatus.show() else @gitStatus.hide()
{'fraction_non_alphanumeric': 0.14185022026431718, 'fraction_numerical': 0.0011747430249632893, 'mean_word_length': 3.3941935483870966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4968413', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2138, 'n_words': 416}