<commit_before>Os = require 'os'
Path = require 'path'
fs = require 'fs-plus'

{CompositeDisposable} = require 'atom'
{$, TextEditorView, View} = require 'atom-space-pen-views'

git = require '../git'

showCommitFilePath = (objectHash) ->
  Path.join Os.tmpDir(), "#{objectHash}.diff"

showObject = (repo, objectHash, file) ->
  args = ['show']
  args.push '--format=full'
  args.push '--word-diff' if atom.config.get 'git-plus.wordDiff'
  args.push objectHash
  if file?
    args.push '--'
    args.push file

  git.cmd
    args: args
    cwd: repo.getWorkingDirectory()
    stdout: (data) -> prepFile(data, objectHash) if data.length > 0

prepFile = (text, objectHash) ->
  fs.writeFileSync showCommitFilePath(objectHash), text, flag: 'w+'
  showFile(objectHash)

showFile = (objectHash) ->
  disposables = new CompositeDisposable
  split = if atom.config.get('git-plus.openInPane') then atom.config.get('git-plus.splitPane')
  atom.workspace
    .open(showCommitFilePath(objectHash), split: split, activatePane: true)
    .done (textBuffer) =>
      if textBuffer?
        disposables.add textBuffer.onDidDestroy =>
          disposables.dispose()
          try fs.unlinkSync showCommitFilePath(objectHash)

class InputView extends View
  @content: -><commit_msg>Refactor git-show.coffee<commit_after>Os = require 'os'
Path = require 'path'
fs = require 'fs-plus'

{CompositeDisposable} = require 'atom'
{TextEditorView, View} = require 'atom-space-pen-views'

git = require '../git'

showCommitFilePath = (objectHash) ->
  Path.join Os.tmpDir(), "#{objectHash}.diff"

showObject = (repo, objectHash, file) ->
  args = ['show']
  args.push '--format=full'
  args.push '--word-diff' if atom.config.get 'git-plus.wordDiff'
  args.push objectHash
  if file?
    args.push '--'
    args.push file

  git.cmd(args, cwd: repo.getWorkingDirectory())
  .then (data) -> prepFile(data, objectHash) if data.length > 0

prepFile = (text, objectHash) ->
  fs.writeFile showCommitFilePath(objectHash), text, flag: 'w+', (err) ->
    if err then notifier.addError err else showFile objectHash

showFile = (objectHash) ->
  disposables = new CompositeDisposable
  split = if atom.config.get('git-plus.openInPane') then atom.config.get('git-plus.splitPane')
  atom.workspace
    .open(showCommitFilePath(objectHash), split: split, activatePane: true)
    .done (textBuffer) ->
      if textBuffer?
        disposables.add textBuffer.onDidDestroy ->
          disposables.dispose()
          try fs.unlinkSync showCommitFilePath(objectHash)

class InputView extends View
  @content: ->
{'fraction_non_alphanumeric': 0.13852140077821012, 'fraction_numerical': 0.0007782101167315176, 'mean_word_length': 3.769944341372913, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '2102798', 'n_tokens_mistral': 849, 'n_tokens_neox': 849, 'n_words': 199}