<commit_before>fs = require 'fs'
path = require 'path'
util = require 'util'
urlParser = require 'url'
{spawnSync, exec} = require 'child_process'
diffLib = require 'jsdifflib'

###
Section: Constants used for file/buffer checking against changes
###
statusIndexNew = 1 << 0
statusIndexDeleted = 1 << 2

statusWorkingDirNew = 1 << 7
statusWorkingDirModified = 1 << 8
statusWorkingDirDelete = 1 << 9
statusWorkingDirTypeChange = 1 << 10
statusIgnored = 1 << 14

modifiedStatusFlags = statusWorkingDirModified | statusWorkingDirDelete |
                      statusWorkingDirTypeChange | statusIndexDeleted

newStatusFlags = statusWorkingDirNew | statusIndexNew

deletedStatusFlags = statusWorkingDirDelete | statusIndexDeleted

suppressHgWarnings = [
  'W200005' # hg: warning: W200005: 'file' is not under version control
  'E200009' # Could not cat all targets because some targets are not versioned
]

class Repository

  username: null
  password: <PASSWORD>

  rootPath: null

  isHgRepository: false
  binaryAvailable: false

  version: null

  url: null
  urlPath: null

  revision: null


  ###
  Section: Initialization and startup checks
  ###

  constructor: (repoRootPath) ->
    @rootPath = path.normalize(repoRootPath)
    unless fs.existsSync(@rootPath)
      return

    lstat = fs.lstatSync(@rootPath)
    unless lstat.isSymbolicLink()
      return

    @rootPath = fs.realpathSync(@rootPath)

  # Checks if there is a hg binary in the os searchpath and returns the
  # binary version string.
  #
  # Returns a {boolean}
  checkBinaryAvailable: () ->
    @version = @getHgVersion()
    if @version?
      @binaryAvailable = true
    else
      @binaryAvailable = false
    return @binaryAvailable

  exists: () ->
    return fs.existsSync(@rootPath + '/.hg')

  # Parses info from `hg info` and `hgversion` command and checks if repo infos have changed
  # since last check
  #
  # Returns a {Promise} of a {boolean} if repo infos have changed
  checkRepositoryHasChangedAsync: () =>
    return @getHgWorkingCopyRevisionAsync().then (revision) =>
      if revision? and revision != @revision
        @revision = revision
        return true
      return false

  getShortHeadAsync: () =>
    return new Promise (resolve) =>
      branchFile = @rootPath + '/.hg/branch'
      bookmarkFile = @rootPath + '/.hg/bookmarks.current'
      prompt = 'default'

      fs.readFile branchFile, 'utf8', (err, data) =>
        prompt = data.trim() unless err
        fs.readFile bookmarkFile, 'utf8', (err, data) =>
          prompt += ':' + data.trim() unless err
          @getHgTagsAsync().then (tags) =>
            prompt += ':' + tags.join(',') if tags?.length
          .then () => # Finally
            resolve prompt



  ###
  Section: TreeView Path Mercurial status
  ###

  # Parses `hg status`. Gets initially called by hg-repository.refreshStatus()
  #
  # Returns a {Promise} of an {Array} array keys are paths, values are change
  # constants. Or null
  getStatus: () ->
    return @getHgStatusAsync()

  # Parses `hg status`. Gets called by hg-repository.refreshStatus()
  #
  # Returns an {Array} Array keys are paths, values are change constants
  getPathStatus: (hgPath) -><commit_msg>Fix lint warnings in lib/hg-utils.coffee<commit_after>fs = require 'fs'
path = require 'path'
util = require 'util'
urlParser = require 'url'
{spawnSync, exec} = require 'child_process'
diffLib = require 'jsdifflib'

###
Section: Constants used for file/buffer checking against changes
###
statusIndexNew = 1 << 0
statusIndexDeleted = 1 << 2

statusWorkingDirNew = 1 << 7
statusWorkingDirModified = 1 << 8
statusWorkingDirDelete = 1 << 9
statusWorkingDirTypeChange = 1 << 10
statusIgnored = 1 << 14

modifiedStatusFlags = statusWorkingDirModified | statusWorkingDirDelete |
                      statusWorkingDirTypeChange | statusIndexDeleted

newStatusFlags = statusWorkingDirNew | statusIndexNew

deletedStatusFlags = statusWorkingDirDelete | statusIndexDeleted

suppressHgWarnings = [
  'W200005' # hg: warning: W200005: 'file' is not under version control
  'E200009' # Could not cat all targets because some targets are not versioned
]

class Repository

  username: null
  password: <PASSWORD>

  rootPath: null

  isHgRepository: false
  binaryAvailable: false

  version: null

  url: null
  urlPath: null

  revision: null


  ###
  Section: Initialization and startup checks
  ###

  constructor: (repoRootPath) ->
    @rootPath = path.normalize(repoRootPath)
    unless fs.existsSync(@rootPath)
      return

    lstat = fs.lstatSync(@rootPath)
    unless lstat.isSymbolicLink()
      return

    @rootPath = fs.realpathSync(@rootPath)

  # Checks if there is a hg binary in the os searchpath and returns the
  # binary version string.
  #
  # Returns a {boolean}
  checkBinaryAvailable: () ->
    @version = @getHgVersion()
    if @version?
      @binaryAvailable = true
    else
      @binaryAvailable = false
    return @binaryAvailable

  exists: () ->
    return fs.existsSync(@rootPath + '/.hg')

  # Parses info from `hg info` and `hgversion` command and checks if repo infos have changed
  # since last check
  #
  # Returns a {Promise} of a {boolean} if repo infos have changed
  checkRepositoryHasChangedAsync: () =>
    return @getHgWorkingCopyRevisionAsync().then (revision) =>
      if revision? and revision != @revision
        @revision = revision
        return true
      return false

  getShortHeadAsync: () =>
    return new Promise (resolve) =>
      branchFile = @rootPath + '/.hg/branch'
      bookmarkFile = @rootPath + '/.hg/bookmarks.current'
      prompt = 'default'

      fs.readFile branchFile, 'utf8', (err, data) =>
        prompt = data.trim() unless err
        fs.readFile bookmarkFile, 'utf8', (err, data) =>
          prompt += ':' + data.trim() unless err
          @getHgTagsAsync().then (tags) ->
            prompt += ':' + tags.join(',') if tags?.length
          .then () -> # Finally
            resolve prompt



  ###
  Section: TreeView Path Mercurial status
  ###

  # Parses `hg status`. Gets initially called by hg-repository.refreshStatus()
  #
  # Returns a {Promise} of an {Array} array keys are paths, values are change
  # constants. Or null
  getStatus: () ->
    return @getHgStatusAsync()

  # Parses `hg status`. Gets called by hg-repository.refreshStatus()
  #
  # Returns an {Array} Array keys are paths, values are change constants
  getPathStatus: (hgPath) ->
{'fraction_non_alphanumeric': 0.10290237467018469, 'fraction_numerical': 0.011174918516219153, 'mean_word_length': 3.2562747688243063, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, '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': '190727', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1870, 'n_words': 592}